:root {
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: #e2e8f0;
    --radius: 8px;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    padding: 20px;
}

.container {
    max-width: 850px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border);
}

h1 { font-size: 1.5rem; color: var(--primary); }

.profile-section {
    background: var(--card-bg);
    padding: 15px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 15px;
}

.input-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.input-row .input-group {
    flex: 1;
    margin-bottom: 0;
}

label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

input[type="number"], select {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    width: 100%;
}

input[type="number"]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover { background-color: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.tab-btn {
    background: var(--border);
    color: var(--text-muted);
    padding: 10px 20px;
    border-radius: var(--radius) var(--radius) 0 0;
    border: none;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}

.tab-btn.active {
    background: var(--card-bg);
    color: var(--primary);
    border-top: 3px solid var(--primary);
    box-shadow: 0 -2px 5px rgba(0,0,0,0.02);
}

.tab-content {
    display: none;
    background: var(--card-bg);
    padding: 25px;
    border-radius: 0 var(--radius) var(--radius) var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.tab-content.active { display: block; }

.instructions {
    background: #f8fafc;
    border-left: 4px solid var(--text-muted);
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.9rem;
}

.instructions ol { margin-left: 20px; margin-top: 10px; }
.instructions li { margin-bottom: 6px; }

.slider-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    background: #f1f5f9;
    padding: 10px 15px;
    border-radius: var(--radius);
}

.slider-container input[type="range"] {
    -webkit-appearance: none;
    width: 60px;
    height: 24px;
    background: var(--primary);
    border-radius: 12px;
    outline: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    margin: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.calc-result {
    margin-top: 20px;
    padding: 15px;
    background: #f0f9ff;
    border-left: 4px solid var(--primary);
    font-size: 1.1rem;
    font-weight: bold;
}

.white-reference {
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
    height: 200px;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #cbd5e1;
    font-weight: 500;
}

.analysis-section,
.treatment-sheet {
    margin-top: 25px;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
}

.analysis-section h3,
.treatment-sheet h3 {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.alert-item,
.treatment-item {
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    font-size: 0.95rem;
    display: flex;
    flex-direction: column;
    border-left: 4px solid;
}

.alert-item strong,
.treatment-item strong {
    margin-bottom: 4px;
    font-size: 1.05rem;
}

.alert-danger,
.treatment-danger { background: #fef2f2; border-color: var(--danger); color: #991b1b; }
.alert-warning,
.treatment-warning { background: #fffbeb; border-color: var(--warning); color: #92400e; }
.alert-success,
.treatment-success { background: #f0fdf4; border-color: var(--success); color: #166534; }

.dose-recommendation {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(0,0,0,0.1);
    font-weight: 600;
}

.treatment-sheet-header {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    align-items: flex-start;
    margin-bottom: 15px;
}

.treatment-sheet-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.treatment-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.meta-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    background: #f8fafc;
}

.meta-card .meta-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.meta-card .meta-value {
    font-size: 0.95rem;
    font-weight: 600;
}

.readings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.reading-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    background: #fff;
}

.reading-card .reading-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.reading-card .reading-value {
    font-size: 1rem;
    font-weight: 700;
}

.treatment-item p,
.treatment-note-list li {
    margin: 0;
}

.treatment-item.action-needed {
    border-left-width: 5px;
}

.treatment-item.status-only {
    opacity: 0.95;
}

.treatment-action {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(0,0,0,0.12);
    font-weight: 700;
}

.treatment-dose {
    margin-top: 4px;
    font-weight: 600;
}

.treatment-notes {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.treatment-notes h4 {
    margin-bottom: 8px;
}

.treatment-note-list {
    margin-left: 20px;
    display: grid;
    gap: 6px;
}

.actions-row {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-secondary { background: var(--success); }
.btn-secondary:hover { background: #059669; }
.btn-print { background: #334155; }
.btn-print:hover { background: #1e293b; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 0.875rem; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); }
th { background: #f1f5f9; font-weight: 600; }

.screen-only { display: inline-flex; }

@media (max-width: 700px) {
    body { padding: 12px; }
    .input-row,
    .treatment-sheet-header,
    .actions-row { flex-direction: column; }
    .screen-only { width: 100%; justify-content: center; }
}

@media print {
    @page {
        size: letter portrait;
        margin: 0.35in;
    }

    :root {
        --primary: #000000;
        --primary-hover: #000000;
        --bg-color: #ffffff;
        --card-bg: #ffffff;
        --text-main: #000000;
        --text-muted: #333333;
        --border: #666666;
        --danger: #000000;
        --warning: #000000;
        --success: #000000;
    }

    body {
        background: #ffffff;
        color: #000000;
        padding: 0;
        font-size: 9.25pt;
        line-height: 1.25;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .container {
        max-width: none;
        margin: 0;
    }

    .profile-section,
    .tabs,
    .tab-content,
    .analysis-section,
    .actions-row,
    .screen-only,
    .instructions,
    .slider-container,
    .white-reference {
        display: none !important;
    }

    header {
        margin-bottom: 8pt;
        padding-bottom: 5pt;
        border-bottom: 1pt solid #000;
    }

    h1 {
        color: #000000;
        font-size: 16pt;
    }

    .treatment-sheet {
        display: block !important;
        margin-top: 0;
        padding: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .treatment-sheet-header {
        margin-bottom: 8pt;
        gap: 8pt;
    }

    .treatment-sheet h3 {
        border-bottom: 1pt solid #000;
        margin-bottom: 6pt;
        padding-bottom: 4pt;
        font-size: 13pt;
    }

    .treatment-sheet-subtitle {
        font-size: 8.5pt;
    }

    .treatment-meta {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6pt;
        margin-bottom: 8pt;
    }

    .readings-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 6pt;
        margin-bottom: 8pt;
    }

    .meta-card,
    .reading-card,
    .treatment-item {
        background: #ffffff !important;
        color: #000000 !important;
        border: 1pt solid #555 !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .meta-card,
    .reading-card {
        padding: 6pt 7pt;
    }

    .meta-card .meta-label,
    .reading-card .reading-label {
        font-size: 7pt;
        margin-bottom: 1pt;
    }

    .meta-card .meta-value,
    .reading-card .reading-value {
        font-size: 9pt;
    }

    .treatment-item {
        padding: 7pt 8pt;
        margin-bottom: 6pt;
        font-size: 8.6pt;
    }

    .treatment-item strong {
        font-size: 10pt;
        margin-bottom: 2pt;
    }

    .treatment-action {
        margin-top: 4pt;
        padding-top: 4pt;
        color: #000000;
    }

    .treatment-dose {
        margin-top: 2pt;
        color: #000000;
    }

    .treatment-item.status-only,
    .treatment-notes {
        display: none !important;
    }
}



/* =====================================================================
   HISTORY TAB — LINE CHART  (added 2026-08-27)
   Scoped additions for the charted History tab on pool-chemistry.html.
   All class names are new; nothing above is modified.
   ===================================================================== */
.chart-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    padding: 18px;
    margin-bottom: 22px;
}
.chart-head {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.chart-title { font-size: 1rem; font-weight: 700; }
.range-label { font-size: 0.8rem; color: var(--text-muted); }

.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.chip {
    display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none;
    border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px;
    font-size: 0.8rem; font-weight: 600; color: var(--text-main); background: #f8fafc;
    transition: opacity 0.15s, background 0.15s;
}
.chip:hover { background: #eef2f7; }
.chip .dot { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); }
.chip.off { opacity: 0.4; text-decoration: line-through; background: #fff; }

.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.grid-line { stroke: #eef2f7; stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
.target-band { fill: currentColor; opacity: 0.12; }
.target-edge { stroke: currentColor; opacity: 0.4; stroke-dasharray: 3 3; }
.series-line { fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.series-dot { stroke: #fff; stroke-width: 1.5; }
.hover-line { stroke: #94a3b8; stroke-width: 1; stroke-dasharray: 4 3; }
.crosshair-dot { stroke: #fff; stroke-width: 2; }

.tooltip {
    position: absolute; pointer-events: none; z-index: 10; min-width: 168px;
    background: rgba(15, 23, 42, 0.94); color: #fff; border-radius: 8px;
    padding: 9px 11px; font-size: 0.78rem; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    transform: translate(-50%, -100%); opacity: 0; transition: opacity 0.1s; white-space: nowrap;
}
.tooltip.show { opacity: 1; }
.tt-date { font-weight: 700; margin-bottom: 5px; padding-bottom: 5px; border-bottom: 1px solid rgba(255,255,255,0.2); }
.tt-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; line-height: 1.7; }
.tt-name { display: inline-flex; align-items: center; gap: 6px; }
.tt-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.chart-empty {
    text-align: center; color: var(--text-muted); padding: 40px 10px; font-size: 0.9rem;
}

.history-summary-grid { margin-bottom: 22px; }
.hist-card::before { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--accent, var(--primary)); }
.hist-trend { font-size: 0.76rem; margin-top: 4px; font-weight: 600; display:flex; align-items:center; gap:5px; }
.trend-up { color: var(--danger); }
.trend-down { color: var(--success); }
.trend-flat { color: var(--text-muted); }

.chart-footnote { margin-top: 16px; font-size: 0.78rem; color: var(--text-muted); display:flex; align-items:center; gap:8px; flex-wrap: wrap; }

@media (max-width: 700px) {
    .chart-card { padding: 14px; }
}


/* =====================================================================
   HISTORY TAB — TIME-RANGE FILTER + COLLAPSIBLE TABLE  (added 2026-08-27)
   Append-only: scoped to new class names; does not touch existing rules.
   ===================================================================== */

/* Range control bar that sits under the chart title / above the legend. */
.range-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin: 4px 0 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.range-presets {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}
.preset-chip {
    cursor: pointer;
    user-select: none;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1;
    color: var(--text-muted);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 13px;
    transition: all .15s ease;
}
.preset-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.preset-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
/* Manual from/to date fields, pushed to the right of the presets. */
.range-dates {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.range-dates label {
    font-weight: 600;
    white-space: nowrap;
}
.range-dates input[type="date"] {
    font-family: inherit;
    font-size: 0.82rem;
    color: var(--text-main);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 8px;
}
.range-dates input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
}
@media (max-width: 560px) {
    .range-dates { margin-left: 0; width: 100%; }
}

/* "No readings in this range" message reuses the empty-state slot. */
.chart-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 40px 0;
}

/* Collapsible raw-data table, hidden by default to keep the page clean. */
.table-toggle-row {
    display: flex;
    justify-content: flex-end;
    margin: 22px 0 0;
}
.table-toggle-btn {
    cursor: pointer;
    user-select: none;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 14px;
    transition: all .15s ease;
}
.table-toggle-btn:hover {
    background: rgba(2, 132, 199, 0.06);
    border-color: var(--primary);
}
.table-wrap[data-open="false"] {
    display: none;
}
