/* =====================================================================
   MR Connect — design system
   Mobile-first. Built for one-handed use in the field: large tap targets,
   high contrast in sunlight, nothing critical below the fold.
   ===================================================================== */

:root {
    /* brand */
    --teal-50:  #f0fdfa;
    --teal-100: #ccfbf1;
    --teal-200: #99f6e4;
    --teal-500: #14b8a6;
    --teal-600: #0d9488;
    --teal-700: #0f766e;
    --teal-800: #115e59;

    --indigo-50:  #eef2ff;
    --indigo-500: #6366f1;
    --indigo-600: #4f46e5;

    /* semantic */
    --ok-50:   #ecfdf5;
    --ok-500:  #10b981;
    --ok-700:  #047857;
    --warn-50: #fffbeb;
    --warn-500:#f59e0b;
    --warn-700:#b45309;
    --bad-50:  #fef2f2;
    --bad-500: #ef4444;
    --bad-700: #b91c1c;
    --info-50: #eff6ff;
    --info-500:#3b82f6;

    /* neutrals */
    --bg:         #f1f5f9;
    --surface:    #ffffff;
    --surface-2:  #f8fafc;
    --border:     #e2e8f0;
    --border-2:   #cbd5e1;
    --text:       #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --radius:    14px;
    --radius-sm: 10px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --shadow:    0 2px 4px rgba(15, 23, 42, .05), 0 4px 12px rgba(15, 23, 42, .07);
    --shadow-lg: 0 8px 28px rgba(15, 23, 42, .14);

    --appbar-h: 58px;
    --tabbar-h: 62px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #0b1220;
        --surface:    #131c2e;
        --surface-2:  #1a2438;
        --border:     #253149;
        --border-2:   #33415c;
        --text:       #e8eef7;
        --text-muted: #94a3b8;
        --text-faint: #64748b;

        --teal-50:  #082f2b;
        --teal-100: #0c463f;
        --ok-50:    #06281d;
        --warn-50:  #2e2109;
        --bad-50:   #2e1010;
        --info-50:  #0c1f3d;
        --indigo-50:#161a3d;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow:    0 2px 8px rgba(0, 0, 0, .45);
        --shadow-lg: 0 10px 30px rgba(0, 0, 0, .6);
    }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--teal-700); text-decoration: none; }
code { font-family: var(--mono); font-size: .85em; }

/* ─────────────────────────── Login ─────────────────────────── */

.login-screen {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
    background:
        radial-gradient(1200px 600px at 50% -10%, var(--teal-100), transparent 60%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 30px 24px 24px;
    border: 1px solid var(--border);
}

.login-brand { text-align: center; margin-bottom: 26px; }

.login-logo {
    width: 60px; height: 60px;
    margin: 0 auto 14px;
    color: var(--teal-700);
}
.login-logo svg { width: 100%; height: 100%; }

.login-brand h1 { font-size: 26px; margin-bottom: 4px; }
.login-brand p { color: var(--text-muted); font-size: 14px; }

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-hint {
    margin-top: 22px;
    padding: 14px;
    background: var(--surface-2);
    border: 1px dashed var(--border-2);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.login-hint strong { color: var(--text); font-size: 12px; text-transform: uppercase;
    letter-spacing: .06em; margin-bottom: 2px; }
.login-hint code {
    background: var(--surface); padding: 1px 5px; border-radius: 4px;
    border: 1px solid var(--border);
}

.password-wrap { position: relative; display: flex; }
.password-wrap input { padding-right: 68px; width: 100%; }
.password-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: 0; color: var(--teal-700);
    font-size: 13px; font-weight: 600; cursor: pointer;
    padding: 8px 10px; font-family: inherit;
}

/* ─────────────────────────── Forms ─────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}
.field-label .req { color: var(--bad-500); }

.doctor-import {
    margin-bottom: 18px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--teal-600);
    border-radius: var(--radius-sm);
}
.doctor-import-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.doctor-import-head h2 { font-size: 16px; }
.doctor-import-head p { margin-top: 3px; color: var(--text-muted); font-size: 13px; }
.doctor-import-head .doctor-import-note { margin-top: 5px; font-size: 12px; }
.doctor-import-form { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.doctor-file-label {
    display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
    min-height: 48px; padding: 8px 10px; border: 1px dashed var(--border-2);
    border-radius: var(--radius-sm); cursor: pointer;
}
.doctor-file-label strong, .doctor-file-label small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doctor-file-label strong { font-size: 13px; }
.doctor-file-label small { color: var(--text-muted); font-size: 11px; }
.doctor-file-icon { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; background: var(--teal-50); color: var(--teal-700); font-size: 22px; }
.doctor-import-result { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.doctor-import-help { margin: 10px 0 12px; font-size: 13px; }
.doctor-import-city { margin-bottom: 4px; }
.doctor-import-help summary { cursor: pointer; color: var(--teal-700); font-weight: 600; }
.doctor-import-help p { margin-top: 8px; }
.doctor-import-columns {
    list-style: none; margin: 8px 0 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 16px;
}
.doctor-import-columns li { display: flex; flex-direction: column; padding: 4px 0; border-bottom: 1px solid var(--border); }
.doctor-import-columns li span { color: var(--text-muted); font-size: 12px; }
.doctor-import-counts { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; font-size: 13px; }
.doctor-import-counts strong { font-size: 16px; }
.doctor-import-counts .has-errors { color: var(--bad-700); }
.doctor-import-errors { margin: 8px 0 0; padding-left: 20px; color: var(--bad-700); font-size: 13px; }
.doctor-import-errors li + li { margin-top: 4px; }
@media (max-width: 480px) {
    .doctor-import-head { flex-direction: column; }
    .doctor-import-form { align-items: stretch; flex-direction: column; }
    .doctor-import-form .btn { width: 100%; }
}

input, select, textarea {
    font-family: inherit;
    font-size: 16px; /* 16px stops iOS zooming on focus */
    color: var(--text);
    background: var(--surface);
    border: 1.5px solid var(--border-2);
    border-radius: var(--radius-sm);
    padding: 12px 13px;
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    padding-right: 36px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--teal-600);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal-500) 22%, transparent);
}

/* The rule above strips native rendering from every input; checkboxes must
   get it back or they never draw a tick. */
input[type="checkbox"] {
    appearance: auto;
    -webkit-appearance: checkbox;
    width: 20px; height: 20px; flex: none;
    accent-color: var(--teal-600);
    border: 0;
    padding: 0;
    border-radius: 0;
    background: none;
}
input[type="checkbox"]:focus {
    outline: 2px solid var(--teal-600);
    outline-offset: 2px;
    box-shadow: none;
}

.form-error {
    background: var(--bad-50);
    color: var(--bad-700);
    border: 1px solid color-mix(in srgb, var(--bad-500) 35%, transparent);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
}

.checkbox-row {
    display: flex; align-items: flex-start; gap: 11px;
    padding: 12px 13px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.checkbox-row span { font-size: 14.5px; font-weight: 500; }
.checkbox-row small { display: block; color: var(--text-muted); font-weight: 400; font-size: 13px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 380px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
}

/* ─────────────────────────── Buttons ─────────────────────────── */

.btn {
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    padding: 12px 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    transition: transform .06s, background .15s, opacity .15s;
    text-decoration: none;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary { background: var(--teal-700); color: #fff; }
.btn-primary:hover { background: var(--teal-800); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-2);
}
.btn-ghost { background: transparent; color: var(--teal-700); }
.btn-danger { background: var(--bad-500); color: #fff; }
.btn-sm { min-height: 36px; padding: 7px 13px; font-size: 13.5px; }

.icon-btn {
    position: relative;
    background: transparent;
    border: 0;
    color: inherit;
    width: 40px; height: 40px;
    border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.16); }

/* ─────────────────────────── App bar ─────────────────────────── */

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.appbar {
    position: sticky; top: 0; z-index: 40;
    background: linear-gradient(135deg, var(--teal-700), var(--teal-800));
    color: #fff;
    padding-top: env(safe-area-inset-top);
    box-shadow: var(--shadow);
}

.appbar-main {
    height: var(--appbar-h);
    display: flex; align-items: center; gap: 4px;
    padding: 0 8px 0 12px;
}

.appbar-back {
    background: none; border: 0; color: #fff;
    width: 36px; height: 36px; margin-left: -4px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; border-radius: 9px;
}

.appbar-titles { flex: 1; min-width: 0; }
.appbar-titles h1 {
    font-size: 17.5px; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar-titles p {
    font-size: 12.5px; opacity: .8; line-height: 1.3;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.appbar-actions { display: flex; gap: 2px; }

.sync-badge {
    position: absolute; top: 3px; right: 3px;
    background: var(--warn-500); color: #422006;
    font-size: 10.5px; font-weight: 800;
    min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--teal-700);
}

.offline-bar {
    background: var(--warn-500);
    color: #422006;
    font-size: 12.5px; font-weight: 600;
    padding: 6px 14px;
    display: flex; align-items: center; gap: 8px;
}
.offline-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #422006;
    animation: pulse 1.8s ease-in-out infinite;
    flex: none;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

/* ─────────────────────────── Layout ─────────────────────────── */

.view {
    flex: 1;
    padding: 16px 14px calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom));
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    outline: none;
}

.section { margin-bottom: 22px; }

/* Doctor list: the city summary sits beside the list on a large screen and
   becomes a scrolling strip of city chips between the filters and the list
   on a phone. */
.view.view-wide { max-width: 1180px; }
.doctors-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "summary" "results";
}
.doctors-top { grid-area: top; min-width: 0; }
.doctors-results { grid-area: results; min-width: 0; }
.city-summary { grid-area: summary; min-width: 0; margin-bottom: 14px; }
.city-summary-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    margin-bottom: 8px;
}
.city-summary-head h2 { font-size: 14px; }
.city-summary-list {
    display: flex; gap: 8px;
    overflow-x: auto; scrollbar-width: none;
    margin: 0 -14px; padding: 0 14px 2px;
}
.city-summary-list::-webkit-scrollbar { display: none; }
.city-summary-item {
    flex: none;
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 12px;
    border-radius: 99px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: inherit; font: inherit; font-size: 13px;
    cursor: pointer; white-space: nowrap;
}
.city-summary-item.is-static { cursor: default; color: var(--text-muted); }
.city-summary-item.active { background: var(--teal-700); border-color: var(--teal-700); color: #fff; }
.city-summary-item.active .city-summary-sn { color: rgba(255,255,255,.75); }
.city-summary-name { font-weight: 600; }
.city-summary-sn { display: none; color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.city-summary-count {
    font-weight: 750; font-variant-numeric: tabular-nums;
    padding: 1px 8px; border-radius: 99px;
    background: var(--surface-2);
}
.city-summary-item.active .city-summary-count { background: rgba(255,255,255,.2); }

@media (min-width: 980px) {
    .doctors-layout {
        grid-template-columns: minmax(0, 1fr) 300px;
        grid-template-rows: auto 1fr;
        grid-template-areas: "top summary" "results summary";
        column-gap: 22px;
        align-items: start;
    }
    .city-summary {
        position: sticky; top: 76px;
        align-self: start;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-sm);
        padding: 14px;
        margin-bottom: 0;
        max-height: calc(100dvh - 180px);
        display: flex; flex-direction: column;
    }
    .city-summary-list {
        flex-direction: column; gap: 2px;
        overflow-x: visible; overflow-y: auto;
        margin: 0; padding: 0;
    }
    .city-summary-item {
        display: flex; justify-content: space-between;
        border: 0; border-radius: 10px;
        background: transparent;
        padding: 9px 10px;
        width: 100%; text-align: left;
    }
    .city-summary-item:hover:not(.is-static):not(.active) { background: var(--surface-2); }
    .city-summary-sn { display: inline; }
}

.section-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 12px; margin-bottom: 10px;
}
.section-head h2 { font-size: 15.5px; }
/* A button that looks like a text link (table actions, inline actions). */
button.link {
    background: none; border: 0; padding: 4px 2px; margin: 0;
    font: inherit; font-size: 13px; font-weight: 600;
    color: var(--teal-700); cursor: pointer;
}

.section-head a, .section-head button.link {
    font-size: 13.5px; font-weight: 600; color: var(--teal-700);
    background: none; border: 0; cursor: pointer; font-family: inherit; padding: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 15px;
}
.card + .card { margin-top: 11px; }
.card-tight { padding: 12px 14px; }

.stack { display: flex; flex-direction: column; gap: 11px; }

/* ─────────────────────────── Tab bar ─────────────────────────── */

.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    box-shadow: 0 -2px 12px rgba(15, 23, 42, .07);
}

.tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    color: var(--text-faint);
    font-size: 10.5px; font-weight: 600;
    text-decoration: none;
    position: relative;
    padding-top: 6px;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--teal-700); }

.tab-primary { color: var(--teal-700); }
.tab-fab {
    width: 46px; height: 46px; margin-top: -20px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--teal-600), var(--teal-800));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--teal-700) 45%, transparent);
    border: 3px solid var(--surface);
}
.tab-fab svg { width: 22px; height: 22px; }

/* ─────────────────────────── Stats ─────────────────────────── */

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px 14px;
    box-shadow: var(--shadow-sm);
}
.stat-label {
    font-size: 11.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-muted);
    display: flex; align-items: center; gap: 5px;
}
.stat-value {
    font-size: 25px; font-weight: 800; line-height: 1.15; margin-top: 5px;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
}
.stat-value.sm { font-size: 20px; }
.stat-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.stat-accent-teal  { color: var(--teal-700); }
.stat-accent-ok    { color: var(--ok-700); }
.stat-accent-warn  { color: var(--warn-700); }
.stat-accent-bad   { color: var(--bad-700); }

/* ─────────────────── Target progress ─────────────────── */

.target-card { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow-sm); }

.target-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; margin-bottom: 11px;
}
.target-title { font-size: 14px; font-weight: 700; }
.target-amount { font-size: 21px; font-weight: 800; letter-spacing: -.02em;
    font-variant-numeric: tabular-nums; }
.target-of { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

.progress {
    height: 9px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 99px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--teal-500), var(--teal-700));
    transition: width .5s cubic-bezier(.4,0,.2,1);
    min-width: 2px;
}
.progress-fill.is-behind { background: linear-gradient(90deg, var(--warn-500), var(--warn-700)); }
.progress-fill.is-bad    { background: linear-gradient(90deg, var(--bad-500), var(--bad-700)); }
.progress-fill.is-done   { background: linear-gradient(90deg, var(--ok-500), var(--ok-700)); }

.target-foot {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 9px; font-size: 12.5px; color: var(--text-muted); gap: 10px;
}

/* ─────────────────── Sales target sheet ─────────────────── */

.st-hero {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    background: linear-gradient(135deg, var(--teal-50), var(--surface) 70%);
    box-shadow: var(--shadow-sm);
}
.st-hero-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.st-hero-label { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-muted); }
.st-hero-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1;
    font-variant-numeric: tabular-nums; margin-top: 4px; }
.st-hero-of { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.st-hero-pct { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1;
    font-variant-numeric: tabular-nums; }
.st-hero .st-bar { height: 12px; margin-top: 14px; }
.st-hero-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    margin-top: 10px; font-size: 12.5px; color: var(--text-muted); }
.st-tally { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; }
.st-tally b { font-variant-numeric: tabular-nums; }
.st-dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; margin-right: 6px;
    vertical-align: middle; }

.st-bar {
    position: relative;
    height: 7px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 99px;
}
.st-bar > i {
    position: absolute; inset: 0 auto 0 0;
    border-radius: 99px;
    min-width: 3px;
    transition: width .5s cubic-bezier(.4,0,.2,1);
}
/* Where the month's pace says you should be by today. */
.st-pace {
    position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px;
    background: var(--text); opacity: .45; border-radius: 2px;
}

.st-met    { --st: var(--ok-500);   --st-ink: var(--ok-700);   --st-bg: var(--ok-50); }
.st-pacing { --st: var(--teal-500); --st-ink: var(--teal-700); --st-bg: var(--teal-50); }
.st-behind { --st: var(--warn-500); --st-ink: var(--warn-700); --st-bg: var(--warn-50); }
.st-far    { --st: var(--bad-500);  --st-ink: var(--bad-700);  --st-bg: var(--bad-50); }
.st-none   { --st: var(--border-2); --st-ink: var(--text-muted); --st-bg: var(--surface-2); }
.st-bar > i { background: var(--st, var(--teal-500)); }

.st-list { display: flex; flex-direction: column; gap: 9px; }
.st-brand {
    display: block; width: 100%; text-align: left; font: inherit; color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--st);
    border-radius: var(--radius-sm);
    padding: 11px 13px 10px;
    box-shadow: var(--shadow-sm);
}
button.st-brand { cursor: pointer; }
.st-brand[hidden] { display: none; }
button.st-brand:active { transform: scale(.995); }
.st-brand-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
    margin-bottom: 8px; }
.st-brand-name { font-weight: 700; font-size: 14px; line-height: 1.3; }
.st-brand-pct { flex: none; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums;
    color: var(--st-ink); }
.st-chev { margin-left: 6px; color: var(--text-faint); font-weight: 600; }
.st-brand-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px;
    margin-top: 8px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.st-brand-foot b { color: var(--text); font-weight: 700; }
.st-status { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px;
    background: var(--st-bg); color: var(--st-ink); }
.st-more { display: block; margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--teal-700); }

/* The -700 inks are too dark on dark-mode tints; use the brighter tones. */
@media (prefers-color-scheme: dark) {
    .st-met    { --st-ink: var(--ok-500); }
    .st-pacing { --st-ink: var(--teal-500); }
    .st-behind { --st-ink: var(--warn-500); }
    .st-far    { --st-ink: var(--bad-500); }
    .st-more   { color: var(--teal-500); }
    .st-hero   { background: linear-gradient(135deg, var(--teal-50), var(--surface) 70%); }
}

/* ─────────────────────────── Pills ─────────────────────────── */

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 700;
    padding: 3px 9px;
    border-radius: 99px;
    white-space: nowrap;
    line-height: 1.5;
}
.pill-teal { background: var(--teal-50);  color: var(--teal-700); }
.pill-ok   { background: var(--ok-50);    color: var(--ok-700); }
.pill-warn { background: var(--warn-50);  color: var(--warn-700); }
.pill-bad  { background: var(--bad-50);   color: var(--bad-700); }
.pill-info { background: var(--info-50);  color: var(--info-500); }
.pill-grey { background: var(--surface-2); color: var(--text-muted); }

.cat-badge {
    width: 25px; height: 25px; flex: none;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800;
}
.cat-A { background: var(--ok-50);   color: var(--ok-700); }
.cat-B { background: var(--info-50); color: var(--info-500); }
.cat-C { background: var(--surface-2); color: var(--text-muted); }

/* ─────────────────────────── List rows ─────────────────────────── */

.list { display: flex; flex-direction: column; gap: 9px; }

.row {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
    text-align: left;
    width: 100%;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    cursor: pointer;
}
.row:active { background: var(--surface-2); }

.row-avatar {
    width: 40px; height: 40px; flex: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--teal-100), var(--teal-200));
    color: var(--teal-800);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 14.5px;
}

.row-serial {
    flex: none; min-width: 26px;
    text-align: right;
    font-weight: 750; font-size: 13.5px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.doc-group {
    display: flex; justify-content: space-between; gap: 12px;
    margin: 10px 2px 0;
    font-size: 12px; font-weight: 750;
    letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-muted);
}
.doc-group:first-child { margin-top: 0; }

.row-body { flex: 1; min-width: 0; }
.row-title {
    font-weight: 650; font-size: 14.5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-sub {
    font-size: 12.5px; color: var(--text-muted); margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-meta { text-align: right; flex: none; }
.row-meta-value { font-weight: 750; font-size: 14px; font-variant-numeric: tabular-nums; }
.row-meta-label { font-size: 11.5px; color: var(--text-muted); }

/* ─────────────────────────── Actions ─────────────────────────── */

.action {
    display: flex; gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border-2);
    border-radius: var(--radius);
    padding: 13px 14px;
    box-shadow: var(--shadow-sm);
}
.action-HIGH   { border-left-color: var(--bad-500);  background: var(--bad-50); }
.action-MEDIUM { border-left-color: var(--warn-500); background: var(--warn-50); }
.action-LOW    { border-left-color: var(--info-500); }

.action-body { flex: 1; min-width: 0; }
.action-title { font-weight: 700; font-size: 14px; }
.action-detail { font-size: 13px; color: var(--text-muted); margin-top: 3px; line-height: 1.45; }

/* ─────────────────────────── Filters ─────────────────────────── */

.filter-bar {
    display: flex; gap: 8px; overflow-x: auto;
    padding-bottom: 4px; margin-bottom: 12px;
    scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }

.chip {
    flex: none;
    background: var(--surface);
    border: 1.5px solid var(--border-2);
    border-radius: 99px;
    padding: 7px 14px;
    font-size: 13px; font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}
.chip.active {
    background: var(--teal-700); border-color: var(--teal-700); color: #fff;
}

.search-wrap { position: relative; margin-bottom: 12px; }
.search-wrap svg {
    position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
    color: var(--text-faint); pointer-events: none;
}
.search-wrap input { padding-left: 40px; }

/* ─────────────────────────── Brand picker ─────────────────────────── */

.brand-item {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
}
.brand-item.selected {
    border-color: var(--teal-600);
    background: var(--teal-50);
}
.brand-info { flex: 1; min-width: 0; }
.brand-name { font-weight: 650; font-size: 14px; }
.brand-comp { font-size: 12px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-rate { text-align: right; font-size: 13px; font-weight: 700; flex: none; }
.brand-rate small { display: block; font-weight: 500; color: var(--text-muted); font-size: 11px; }
.pob-rate-field { display: flex; flex-direction: column; gap: 2px; width: 88px; flex: none; }
.pob-rate-field span { color: var(--text-muted); font-size: 10px; font-weight: 600; }
.pob-rate-field input { height: 34px; padding: 4px 6px; font-size: 14px; }
.pob-product-picker { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 8px; }
.pob-product-picker .field { flex: 1; min-width: 0; }
.pob-product-picker .btn { min-height: 48px; flex: none; }
.pob-empty { padding: 8px 0; color: var(--text-muted); font-size: 13px; }
.pob-line { padding: 12px 0; border-top: 1px solid var(--border); }
.doctor-rate-row { padding: 12px 0; border-top: 1px solid var(--border); }
.doctor-rate-row:first-child { border-top: 0; }
.plan-calendar-year { width: 104px; flex: none; }
.plan-calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.plan-calendar-weekday { padding: 5px 0; color: var(--text-muted); font-size: 11px; font-weight: 650; text-align: center; }
.plan-calendar-blank, .plan-calendar-day { aspect-ratio: 1; }
.plan-calendar-day {
    position: relative; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
    color: var(--text); font: inherit; cursor: pointer;
}
.plan-calendar-day.selected { border-color: var(--teal-700); background: var(--teal-700); color: white; }
.plan-calendar-day.has-plan::after {
    position: absolute; bottom: 4px; width: 5px; height: 5px; border-radius: 50%;
    background: var(--teal-600); content: '';
}
.plan-calendar-day.selected.has-plan::after { background: white; }
/* A planned date shows the city of its tour under the day number. */
.plan-calendar-day { flex-direction: column; gap: 1px; padding: 1px; min-width: 0; }
.plan-calendar-day.has-city::after { display: none; }
.plan-calendar-city {
    max-width: 100%;
    font-size: 9px; line-height: 1.1; font-weight: 650; letter-spacing: -0.2px;
    color: var(--teal-600);
    text-align: center; overflow-wrap: break-word;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
    overflow: hidden;
}
.plan-calendar-day.selected .plan-calendar-city { color: white; }
/* Inventory */
.inv-head { flex-wrap: wrap; }
.inv-period { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; align-items: end; }
.inv-period .inv-quick { grid-column: 1 / -1; }
@media (min-width: 760px) {
    .inv-period { grid-template-columns: 170px 170px 1fr; }
    .inv-period .inv-quick { grid-column: auto; }
}
.inv-quick { flex-wrap: wrap; align-items: center; }
.inv-search { flex: 1; min-width: 160px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 99px;
              background: var(--surface); color: var(--text); font: inherit; font-size: 13px; }
.inv-neg { color: var(--bad-500) !important; }
.inv-pos { color: var(--ok-700); }
@media (prefers-color-scheme: dark) { .inv-pos { color: var(--ok-500); } }

/* Row-and-column statements: scroll sideways on a phone, brand / party column stays put. */
.inv-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.inv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.inv-table th, .inv-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
.inv-table thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; font-weight: 700;
                      color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.inv-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.inv-table tbody th, .inv-table tfoot th, .inv-table thead th:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--surface); font-weight: 650; max-width: 190px;
    white-space: normal; box-shadow: 1px 0 0 var(--border);
}
.inv-table thead th:first-child { background: var(--surface-2); z-index: 2; }
.inv-table tbody th, .inv-table tfoot th {
    text-transform: none; letter-spacing: normal; font-size: 13px; color: var(--text); min-width: 150px;
}
.inv-table th small { display: block; font-weight: 500; color: var(--text-muted); font-size: 11px; }
.inv-table tfoot th, .inv-table tfoot td { font-weight: 750; background: var(--surface-2); border-bottom: 0; }
.inv-table tfoot th { background: var(--surface-2); }
.inv-table .pill { font-size: 11px; }
.inv-party { cursor: pointer; }
.inv-party:hover th, .inv-party:hover td { background: var(--surface-2); }
.inv-caret { display: inline-block; width: 12px; color: var(--text-muted); }
.inv-sub th { padding-left: 30px; font-weight: 500 !important; }
.inv-sub th, .inv-sub td { background: var(--surface-2) !important; font-size: 12.5px; }
.inv-line { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.inv-line-money { margin-top: 8px; color: var(--text-muted); }
/* Purchase history of the brand on a purchase line */
.inv-hist { margin-top: 10px; padding: 10px; border-radius: 10px; background: var(--surface-2); font-size: 12.5px; }
.inv-hist-head { color: var(--text-muted); }
.inv-hist-head b { color: var(--text); }
.inv-hist-wrap { overflow-x: auto; margin-top: 8px; }
.inv-hist-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.inv-hist-table th, .inv-hist-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
.inv-hist-table th { font-size: 10.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.inv-hist-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.inv-hist-table small { display: block; color: var(--text-muted); font-size: 10.5px; }
.inv-hist-table tr:last-child td { border-bottom: 0; }
.inv-hist-row { cursor: pointer; }
.inv-hist-row:hover td, .inv-hist-row:active td { background: var(--surface); }
.inv-hist-tip { margin: 0 0 4px; color: var(--text-muted); font-size: 11.5px; }
.inv-line-money b { color: var(--text); }
.inv-totals { font-size: 14px; }
.inv-grand { padding-top: 8px; border-top: 1px solid var(--border); font-size: 16px; }

/* Doctor pick lists (planning and today's plan): a tick box on every row. */
.plan-row { cursor: pointer; user-select: none; }
.plan-check {
    flex: none; width: 22px; height: 22px; margin: 0;
    accent-color: var(--teal-600); cursor: pointer;
}
.plan-row.is-selected { border-color: var(--teal-600); box-shadow: 0 0 0 1px var(--teal-600) inset; }
.plan-row.is-planned { cursor: default; opacity: .75; }
.plan-row.is-planned .plan-check { cursor: default; }
.plan-tour-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.plan-tour-row {
    display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 10px; align-items: center;
    padding: 9px 12px; border: 0; border-top: 1px solid var(--border);
    background: var(--surface); color: inherit; font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.plan-tour-row:first-child { border-top: 0; }
.plan-tour-date { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.plan-tour-city { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-tour-count { color: var(--text-muted); font-size: 12px; }
.pob-line-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.pob-line-fields { display: grid; grid-template-columns: minmax(70px, .8fr) minmax(100px, 1fr) minmax(80px, .8fr); align-items: end; gap: 10px; }
.pob-line-value-wrap { display: flex; min-height: 60px; flex-direction: column; justify-content: center; gap: 6px; }
.pob-line-value-wrap strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.brand-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 150px; }
.doctor-actions { display: flex; gap: 10px; }
.doctor-actions > * { flex: 1; }
@media (max-width: 540px) {
    .brand-actions { min-width: 0; }
    .brand-actions .btn { padding: 7px 8px; }
    .pob-product-picker { align-items: stretch; flex-direction: column; }
    .pob-product-picker .btn { width: 100%; }
}

.qty-stepper { display: flex; align-items: center; gap: 0; flex: none; }
.qty-stepper button {
    width: 34px; height: 34px;
    border: 1.5px solid var(--border-2);
    background: var(--surface);
    color: var(--text);
    font-size: 18px; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.qty-stepper button:first-child { border-radius: 9px 0 0 9px; }
.qty-stepper button:last-child  { border-radius: 0 9px 9px 0; }
.qty-stepper input {
    width: 50px; height: 34px; text-align: center;
    border-radius: 0; border-left: 0; border-right: 0;
    padding: 0; font-size: 14px; font-weight: 700;
}

/* ─────────────────────────── Table ─────────────────────────── */

.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); font-weight: 700;
    padding: 11px 12px; border-bottom: 1.5px solid var(--border);
    background: var(--surface-2); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 130px; }
/* Multi-select as tick boxes that wrap like chips */
.check-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.call-days { border: 0; padding: 0; margin: 0; min-width: 0; }
.call-days legend { padding: 0; margin-bottom: 6px; }
.check-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 12px; border: 1.5px solid var(--border-2); border-radius: 99px;
    font-size: 13px; font-weight: 600; cursor: pointer; user-select: none;
}
.check-chip input { margin: 0; }
.check-chip:has(input:checked) {
    border-color: var(--teal-600, #0d9488);
    background: color-mix(in srgb, var(--teal-600, #0d9488) 14%, transparent);
}

.table-compact { font-size: 12px; }
.table-compact th, .table-compact td { padding: 9px 7px; }
.table-compact th:first-child, .table-compact td:first-child { padding-left: 12px; }
.table-compact td.wrap { min-width: 96px; }
.table-compact th { font-size: 10px; letter-spacing: .02em; padding-top: 7px; padding-bottom: 7px; }
.table-compact th.text-center { text-align: center; border-bottom-width: 1px; }

/* ─────────────────────────── Empty / loading ─────────────────────────── */

.empty {
    text-align: center;
    padding: 40px 22px;
    color: var(--text-muted);
}
.empty-icon {
    width: 54px; height: 54px; margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-faint);
}
.empty h3 { font-size: 15.5px; color: var(--text); margin-bottom: 5px; }
.empty p { font-size: 13.5px; max-width: 280px; margin: 0 auto; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }
.skeleton-row { height: 66px; margin-bottom: 9px; }

.spinner {
    width: 17px; height: 17px;
    border: 2.5px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ─────────────────────────── Toast ─────────────────────────── */

.toast-host {
    position: fixed; left: 0; right: 0;
    bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
    z-index: 90;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    pointer-events: none;
    padding: 0 16px;
}
.toast {
    background: #0f172a; color: #fff;
    padding: 11px 17px;
    border-radius: 99px;
    font-size: 13.5px; font-weight: 600;
    box-shadow: var(--shadow-lg);
    max-width: 100%;
    animation: toast-in .24s cubic-bezier(.2,.8,.3,1);
    display: flex; align-items: center; gap: 8px;
}
.toast-ok   { background: var(--ok-700); }
.toast-bad  { background: var(--bad-700); }
.toast-warn { background: var(--warn-700); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) } }

/* ─────────────────────────── Bottom sheet ─────────────────────────── */

.sheet-host {
    position: fixed; inset: 0; z-index: 80;
    background: rgba(15, 23, 42, .5);
    display: flex; align-items: flex-end;
    animation: fade-in .18s;
}
@keyframes fade-in { from { opacity: 0 } }

.sheet {
    background: var(--surface);
    width: 100%;
    max-height: 90dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    overflow-y: auto;
    animation: sheet-up .26s cubic-bezier(.2,.8,.3,1);
    margin: 0 auto;
    max-width: 780px;
}
@keyframes sheet-up { from { transform: translateY(100%) } }

.sheet-handle {
    width: 38px; height: 4px; border-radius: 99px;
    background: var(--border-2);
    margin: 6px auto 14px;
}
.sheet-title { font-size: 17px; margin-bottom: 4px; }
.sheet-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* ─────────────────────────── Utilities ─────────────────────────── */

.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.tnum  { font-variant-numeric: tabular-nums; }
.mt-8  { margin-top: 8px; }
.mt-14 { margin-top: 14px; }
.mt-10 { margin-top: 10px; }
.mb-10 { margin-bottom: 10px; }
.flex  { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.grow { flex: 1; }
.text-right { text-align: right; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}
