@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* ============================================================
   Nurse Note Hub — clean / minimal redesign
   Layout: top bar → context row → two panes (entry | preview)
           → analytics (charts + history) at the bottom.
   All component class names match what app.js generates.
   ============================================================ */

:root {
    --primary-hue: 174;
    --primary: #0f766e;
    --primary-dark: #0b5c55;
    --primary-light: #e3f0ed;
    --secondary: #0f766e;
    --secondary-light: #e3f0ed;
    --accent: #d97706;           /* warm gold — handover / warnings accent */
    --accent-light: #fdf3e2;

    --night: #0369a1;
    --night-soft: #e6f1f9;
    --night-line: #b6d4ee;
    --day: #c2620c;
    --day-soft: #fbeede;
    --day-line: #eccfa8;

    --bg-base: #eef3f1;          /* page canvas */
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --border-color: #e2e9e6;
    --text-primary: #12211e;
    --text-secondary: #5c6b67;
    --text-light: #8b9a95;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(18,33,30,.05);
    --shadow-md: 0 1px 2px rgba(18,33,30,.05), 0 8px 22px -14px rgba(18,33,30,.20);
    --shadow-lg: 0 12px 34px -10px rgba(18,33,30,.24);
    --shadow-xl: 0 20px 48px -12px rgba(18,33,30,.30);
    --transition: all .2s cubic-bezier(.4,0,.2,1);
    --font: 'Sarabun','Outfit',system-ui,-apple-system,sans-serif;
}

[data-theme="dark"] {
    --primary: #2dd4bf;
    --primary-dark: #5eead4;
    --primary-light: #123029;
    --secondary: #2dd4bf;
    --secondary-light: #123029;
    --accent: #fbbf24;
    --accent-light: #2a2110;
    --night: #38bdf8;
    --night-soft: #0d2536;
    --night-line: #1d3f56;
    --day: #fb923c;
    --day-soft: #2a1c0e;
    --day-line: #4a3318;
    --bg-base: #0c1512;
    --bg-surface: #14201d;
    --bg-card: #14201d;
    --border-color: #223029;
    --text-primary: #eaf2ef;
    --text-secondary: #97aaa4;
    --text-light: #6f827c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --shadow-md: 0 1px 2px rgba(0,0,0,.35), 0 8px 22px -14px rgba(0,0,0,.7);
    --shadow-lg: 0 12px 34px -10px rgba(0,0,0,.7);
    --shadow-xl: 0 20px 48px -12px rgba(0,0,0,.8);
}

* { box-sizing: border-box; margin: 0; padding: 0; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
    font-family: var(--font);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color .4s ease, color .25s ease;
    padding-bottom: 2rem;
}

/* Per-shift wash across the whole workspace — clear night/day separation */
body.shift-night { --bg-base: hsl(208, 78%, 83%); }
[data-theme="dark"] body.shift-night { --bg-base: hsl(210, 62%, 9%); }
body.shift-day { --bg-base: hsl(36, 92%, 82%); }
[data-theme="dark"] body.shift-day { --bg-base: hsl(34, 52%, 9%); }

.app-shell { max-width: 1680px; margin: 0 auto; padding: 16px; }

/* ─────────────── TOP BAR ─────────────── */
.topbar {
    display: flex; align-items: center; gap: 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    box-shadow: var(--shadow-md);
    /* Not sticky (owner request 2026-07-18): the bar scrolls away with the
       page instead of following down and covering content. */
    position: relative; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-icon {
    width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
    background: var(--primary); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: .5px;
}
.brand-title h1 { font-size: 1.02rem; font-weight: 700; color: var(--primary); letter-spacing: -.3px; }
.brand-title p { font-size: .72rem; color: var(--text-secondary); }
.topbar-spring { flex: 1; }
.header-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.save-indicator { font-size: .72rem; color: var(--text-light); white-space: nowrap; font-weight: 600; }

/* Patient selector chip + popover */
.patient-select { position: relative; }
.patient-chip {
    display: flex; align-items: center; gap: 9px;
    background: var(--bg-base); border: 1px solid var(--border-color);
    border-radius: 999px; padding: 5px 12px 5px 6px; cursor: pointer;
    font-family: inherit; color: var(--text-primary);
    transition: border-color .15s ease;
}
.patient-chip:hover { border-color: var(--primary); }
.patient-chip .avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
    background: var(--primary-light); color: var(--primary);
    display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.current-patient-display {
    font-weight: 700; font-size: .9rem; color: var(--text-primary);
    white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.patient-chip .caret { color: var(--text-light); font-size: 11px; }
.patient-panel {
    position: absolute; top: calc(100% + 8px); right: 0; width: min(420px, 92vw);
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    padding: 12px; z-index: 300; display: none;
}
.patient-select.open .patient-panel { display: block; }
.patient-panel-title { font-size: .78rem; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; }

/* header buttons + overflow menu */
.hdr-btn {
    background: none; border: 1px solid var(--border-color); color: var(--text-primary);
    padding: .42rem .7rem; border-radius: 9px; cursor: pointer;
    font-size: .8rem; font-weight: 600; font-family: inherit;
    display: flex; align-items: center; gap: .35rem; white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease;
}
.hdr-btn:hover { background-color: var(--bg-base); border-color: var(--text-secondary); }
.hdr-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.hdr-btn.primary:hover { opacity: .9; background: var(--primary); }
.hdr-menu { position: relative; }
.hdr-menu-panel {
    position: absolute; top: calc(100% + 6px); right: 0; min-width: 220px;
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    padding: .35rem; z-index: 300; display: none; flex-direction: column; gap: .15rem;
}
.hdr-menu.open .hdr-menu-panel { display: flex; }
.hdr-menu-item {
    display: flex; align-items: center; gap: .55rem; width: 100%; text-align: left;
    background: none; border: none; color: var(--text-primary);
    padding: .6rem .7rem; border-radius: 8px; cursor: pointer;
    font-size: .85rem; font-weight: 500; font-family: inherit; transition: background-color .12s ease;
}
.hdr-menu-item:hover { background-color: var(--bg-base); }
.hdr-menu-item.danger { color: #ea580c; }
.hdr-menu-item.danger:hover { background-color: rgba(234,88,12,.08); }

.btn-icon {
    background: none; border: 1px solid var(--border-color); color: var(--text-primary);
    width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center; cursor: pointer;
    transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
.btn-icon:hover { background-color: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* ─────────────── SHIFT / DATE CONTROLS (now in the left sidebar) ─────────────── */
.shift-tabs { display: flex; background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 4px; gap: 4px; box-shadow: var(--shadow-sm); }
.shift-tab {
    border: 0; background: transparent; color: var(--text-secondary);
    font-family: inherit; font-size: .9rem; font-weight: 600;
    padding: 8px 18px; border-radius: 9px; cursor: pointer;
    display: flex; align-items: center; gap: 7px; white-space: nowrap;
    transition: background-color .15s ease, color .15s ease;
}
.shift-tab:hover { color: var(--text-primary); }
#tabNightBtn.active { background: var(--night-soft); color: var(--night); }
#tabDayBtn.active { background: var(--day-soft); color: var(--day); }

.date-pill {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow-sm);
}
.date-pill .cal { color: var(--primary); }
.date-pill input[type="date"] {
    width: auto; border: none; background: none; padding: 4px 2px;
    font-weight: 600; font-size: .9rem; color: var(--text-primary);
}
.date-pill input[type="date"]:focus { outline: none; box-shadow: none; }
.mini-btn {
    padding: .38rem .6rem; background: none; border: 1px solid var(--border-color);
    border-radius: 8px; cursor: pointer; font-size: .78rem; font-weight: 600;
    white-space: nowrap; line-height: 1; font-family: inherit; color: var(--text-secondary);
    transition: border-color .15s ease, color .15s ease;
}
.mini-btn:hover { border-color: var(--primary); color: var(--primary); }
.mini-btn.today { color: var(--secondary); border-color: var(--secondary); }
.mini-btn.rollback { color: #dc2626; border-color: #f0a3a3; }
#autoDateBadge { font-weight: 600; color: var(--secondary); font-size: .72rem; }

.shift-handover-btn {
    white-space: nowrap; font-weight: 700; font-size: .84rem; padding: .55rem 1rem;
    border-radius: 10px; min-width: 140px; box-shadow: var(--shadow-sm);
    display: flex; align-items: center; justify-content: center; gap: .3rem;
    transition: opacity .15s ease, transform .1s ease;
}
.shift-handover-btn:hover { transform: translateY(-1px); }

/* ─────────────── LAYOUT GRID ─────────────── */
.app-container {
    display: grid; gap: 16px; align-items: start;
    margin-top: 14px; /* spacing that the removed context row used to provide */
    grid-template-columns: 236px minmax(0, 1.35fr) minmax(0, 1fr);
    grid-template-areas:
        "patients entry preview"
        "patients vitals preview"
        "analytics analytics analytics";
}
/* ── STICKY PANELS: two rules learned from the 2026-07-18 overlap bugs ──
   1. A sticky GRID ITEM is clamped to the whole grid container (including the
      analytics row), so it can ride down over the charts. Fix: the grid item
      is a full-height stretch wrapper (.col-patients / .side) and the CARD
      inside is the sticky element — clamped to the wrapper, which ends where
      analytics begins.
   2. Sticky content must be height-capped with internal scrolling, else a
      long patient list / resized preview overflows the viewport. */
.col-patients { grid-area: patients; align-self: stretch; min-width: 0; }
#patientSidebar {
    position: sticky; top: 12px;
    max-height: calc(100vh - 24px);
}
#patientSidebar .card-body { overflow-y: auto; min-height: 0; }
#entryCard { grid-area: entry; }
#vitalsCard { grid-area: vitals; }
.app-container > .side {
    grid-area: preview; align-self: stretch;
    /* Pin the column to its grid track: without a definite width the
       resizable textarea's max-width:100% resolves circularly and the whole
       column balloons past the track (horizontal-overflow bug). */
    width: 100%; min-width: 0;
}
.side .preview-card {
    position: sticky; top: 12px;
    max-height: calc(100vh - 24px);
    overflow-y: auto; overflow-x: hidden;
}
#analyticsSection { grid-area: analytics; }

@media (max-width: 1000px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-areas: "patients" "entry" "preview" "vitals" "analytics";
    }
    .col-patients, .app-container > .side { align-self: auto; }
    #patientSidebar, .side .preview-card { position: static; max-height: none; }
    #patientSidebar .card-body { overflow-y: visible; }
    .side .preview-card { overflow: hidden; }
}

/* Left sidebar — shift/date controls + patient list */
#patientSidebar .card-body { padding: .85rem; }
.sidebar-tabs { width: 100%; margin-bottom: .55rem; }
.sidebar-tabs .shift-tab { flex: 1; justify-content: center; padding: 8px 4px; font-size: .84rem; }
.sidebar-date { width: 100%; margin-bottom: .45rem; }
.sidebar-date input[type="date"] { flex: 1; min-width: 0; font-size: .84rem; }
.sidebar-date-btns { display: flex; gap: .4rem; margin-bottom: .55rem; }
.sidebar-date-btns .mini-btn { flex: 1; }
#patientSidebar .shift-handover-btn { width: 100%; min-width: 0; }
.sidebar-divider { height: 1px; background: var(--border-color); margin: .8rem 0; }
.sidebar-current {
    display: flex; align-items: center; gap: .5rem; background: var(--primary-light);
    border: 1px solid var(--primary); border-radius: var(--radius-md); padding: .55rem .7rem;
    font-weight: 700; color: var(--primary); font-size: .9rem; margin-bottom: .7rem;
    min-height: 42px; word-break: break-word;
}
/* Patient list gets its OWN scrollbar so a long roster never pushes the
   sidebar past the viewport (overlap-bug fix #2). */
#patientSidebar .profiles-list {
    flex-direction: column; flex-wrap: nowrap; gap: .35rem;
    max-height: 30vh; overflow-y: auto; padding-right: .2rem;
}
#patientSidebar .profile-chip { width: 100%; justify-content: space-between; border-radius: 10px; flex-shrink: 0; }

/* ─────────────── CARDS ─────────────── */
.card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    overflow: hidden; display: flex; flex-direction: column;
    transition: background-color .25s ease;
}
#entryCard { border-top: 3px solid var(--night); }
body.shift-day #entryCard { border-top: 3px solid var(--day); }
.card-header {
    padding: .85rem 1.15rem; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap;
    background: var(--bg-surface);
}
.card-title { font-size: .96rem; font-weight: 600; display: flex; align-items: center; gap: .45rem; color: var(--primary); }
.card-body { padding: 1.1rem 1.15rem; flex-grow: 1; }

/* ─────────────── FORMS ─────────────── */
.form-group { margin-bottom: .85rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .4rem; }
input, select, textarea {
    width: 100%; padding: .6rem .8rem; border: 1px solid var(--border-color);
    border-radius: 10px; background: var(--bg-surface); color: var(--text-primary);
    font-family: inherit; font-size: 16px; transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.help-text { font-size: .74rem; color: var(--text-light); margin-top: .25rem; }

/* ─────────────── BUTTONS ─────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .65rem 1.3rem; font-weight: 600; border-radius: 10px; cursor: pointer;
    font-family: inherit; font-size: .9rem; border: none;
    transition: background-color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-surface); border: 1px solid var(--border-color); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-base); border-color: var(--text-secondary); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { opacity: .9; }
.btn-water { background: #0891b2; color: #fff; border: none; }
.btn-water:hover { opacity: .9; }
.btn-sm { padding: .4rem .8rem; font-size: .82rem; border-radius: 8px; }

.preset-btn {
    background: var(--bg-surface); border: 1px solid var(--border-color);
    padding: .32rem .7rem; border-radius: 999px; font-size: .78rem; cursor: pointer;
    color: var(--text-secondary); font-family: inherit;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.preset-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.presets-container { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .6rem; }

/* ─────────────── SHIFT PANES / TIMELINE ─────────────── */
.shift-pane { display: none; }
.shift-pane.active { display: block; }

.timeline-builder { background: var(--bg-base); padding: .9rem; border-radius: var(--radius-md); border: 1px solid var(--border-color); }
.timeline-entry-row { display: flex; gap: .6rem; align-items: center; }
.timeline-entry-row .btn { flex: 0 0 auto; min-width: 84px; }
.time-select { display: flex; gap: .25rem; align-items: center; flex: 0 0 auto; }
.time-select select { padding: .6rem .3rem; text-align: center; font-weight: 700; width: 66px; }

/* Section 1 (care timeline) — boxed like 1.1, in the SHIFT color so the
   primary entry area leads visually (owner request 2026-07-18). */
.care-subsection { background: var(--night-soft); border: 1px solid var(--night-line); border-radius: var(--radius-md); padding: .75rem .85rem; }
body.shift-day .care-subsection { background: var(--day-soft); border-color: var(--day-line); }
.care-subsection-label { display: block; font-size: .88rem; font-weight: 700; color: var(--night); margin-bottom: .55rem; }
body.shift-day .care-subsection-label { color: var(--day); }

/* Water sub-section (1.1) — cyan "water" tint, secondary to section 1 */
.water-subsection { background: rgba(6, 182, 212, 0.08); border: 1px solid rgba(6, 182, 212, 0.35); border-radius: var(--radius-md); padding: .75rem .85rem; margin-top: .75rem; }
.water-subsection-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .55rem; }
.water-subsection-label { font-size: .84rem; font-weight: 700; color: #0e7490; }
[data-theme="dark"] .water-subsection-label { color: #22d3ee; }
.water-goal-quick {
    display: flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 700;
    color: #0e7490; background: var(--bg-surface); border: 1px solid rgba(6, 182, 212, 0.4);
    border-radius: 999px; padding: .15rem .6rem;
}
[data-theme="dark"] .water-goal-quick { color: #22d3ee; }
.water-goal-quick input { width: 58px; padding: .1rem .2rem; font-size: .8rem; font-weight: 700; text-align: right; border: none; background: none; color: inherit; }
.water-goal-quick input:focus { outline: none; box-shadow: none; }
.water-quick-fills { display: flex; gap: .4rem; margin-top: .5rem; flex-wrap: wrap; }
.wq-btn { border: 1px dashed rgba(6, 182, 212, 0.5); background: transparent; color: #0e7490; font-family: inherit; font-size: .74rem; font-weight: 600; padding: .25rem .7rem; border-radius: 999px; cursor: pointer; }
[data-theme="dark"] .wq-btn { color: #22d3ee; }
.wq-btn:hover { background: var(--bg-surface); }

.timeline-list { margin-top: .8rem; max-height: 190px; overflow-y: auto; display: flex; flex-direction: column; gap: .4rem; }
.timeline-item { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 9px; padding: .55rem .7rem; display: flex; justify-content: space-between; align-items: center; animation: slideIn .2s ease-out; }
.timeline-item-meta { font-weight: 700; color: var(--primary); font-size: .85rem; margin-right: .7rem; font-variant-numeric: tabular-nums; }
.timeline-item-text { flex-grow: 1; font-size: .88rem; }
.btn-remove { background: none; border: none; color: #dc2626; cursor: pointer; padding: .2rem; opacity: .55; transition: opacity .15s ease; }
.btn-remove:hover { opacity: 1; }

/* section subtitle used inside entry */
.section-label { margin: 1.15rem 0 .6rem; font-size: .9rem; font-weight: 700; color: var(--text-primary); display: flex; align-items: center; gap: .4rem; }
/* Vitals card: the pane's first label sits flush with the card top —
   no wasted space above "3. ค่าสัญญาณชีพ" (owner request 2026-07-18) */
#vitalsCard .shift-pane > .section-label:first-child { margin-top: 0; }
.divider { height: 1px; background: var(--border-color); margin: 1.15rem 0; }

/* ─────────────── VITALS ─────────────── */
.vitals-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; }
@media (max-width: 560px) { .vitals-grid { grid-template-columns: repeat(3, 1fr); } }
.input-with-label { background: var(--bg-base); padding: .5rem .55rem; border-radius: 10px; border: 1px solid var(--border-color); }
.input-with-label label { font-size: .74rem; margin-bottom: .2rem; }
.input-with-label input { padding: .45rem .4rem; text-align: center; font-weight: 700; font-size: 15px; }
.input-with-label .help-text { text-align: center; margin-top: .15rem; }
.save-vitals-btn {
    background: var(--night); color: #fff; font-weight: 700; padding: .5rem 1.1rem; border-radius: 9px;
    border: none; cursor: pointer; font-size: .85rem; font-family: inherit;
    display: inline-flex; align-items: center; gap: .35rem; transition: opacity .15s ease;
}
body.shift-day .save-vitals-btn { background: var(--day); }
.save-vitals-btn:hover { opacity: .9; }

/* Timestamped vitals readings list (multiple measurements per day) */
.vitals-log { display: flex; flex-direction: column; gap: .35rem; margin-top: .6rem; max-height: 160px; overflow-y: auto; }
.vitals-log-item {
    display: flex; align-items: center; gap: .6rem;
    background: var(--bg-base); border: 1px solid var(--border-color);
    border-radius: 9px; padding: .45rem .7rem; font-size: .84rem;
    animation: slideIn .2s ease-out;
}
.vl-time { font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.vl-vals { flex: 1; }

/* ─────────────── EXCRETION ─────────────── */
.exc-panel { background: var(--bg-base); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: .85rem; }
.exc-entry-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.exc-type-btn {
    background: var(--bg-surface); border: 1.5px solid var(--border-color); padding: .4rem .8rem;
    border-radius: 999px; font-size: .82rem; cursor: pointer; color: var(--text-secondary);
    font-family: inherit; font-weight: 500; transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.exc-type-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.exc-type-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.exc-counters { display: grid; grid-template-columns: repeat(4, 1fr); gap: .55rem; margin-top: .75rem; }
.exc-counter { background: var(--bg-base); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: .6rem .4rem; text-align: center; }
.exc-counter .ico { font-size: 1.2rem; }
.exc-counter .lbl { font-size: .72rem; color: var(--text-secondary); font-weight: 600; display: block; }
.exc-counter .val { font-size: 1.35rem; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.exc-counter .unit { font-size: .72rem; color: var(--text-secondary); }
.exc-counter.water { background: rgba(6, 182, 212, 0.08); border-color: rgba(6, 182, 212, 0.35); }
.exc-counter.water .val { color: #0891b2; }
[data-theme="dark"] .exc-counter.water .val { color: #22d3ee; }

/* ─────────────── STAFF SIGN-IN ─────────────── */
.staff-box { display: flex; gap: .75rem; align-items: center; background: var(--bg-base); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: .65rem .85rem; flex-wrap: wrap; }
.staff-box .tag { font-size: .82rem; font-weight: 700; white-space: nowrap; }
.staff-box .tag.night { color: var(--night); }
.staff-box .tag.day { color: var(--day); }
.staff-fields { display: flex; gap: .5rem; flex: 1; flex-wrap: wrap; }
.staff-field { display: flex; align-items: center; gap: .35rem; flex: 1; min-width: 140px; }
.staff-field label { font-size: .78rem; white-space: nowrap; color: var(--text-secondary); margin: 0; }
.staff-field input { padding: .4rem .6rem; font-size: .85rem; }

/* ─────────────── PREVIEW ─────────────── */
.preview-container {
    width: 100%; border: 1.5px dashed var(--border-color); background: var(--bg-base);
    border-radius: var(--radius-md); padding: 1.1rem; font-family: 'Sarabun', monospace;
    white-space: pre-wrap; word-break: break-word; font-size: .9rem; line-height: 1.62;
    color: var(--text-secondary); min-height: 300px; overflow: auto;
    /* Both-direction resize so staff can fit it to the company monitor.
       Capped so a tall/wide resize can never spill over other panels
       (overlap-bug fix #3) — the .side column also scrolls internally. */
    resize: both; max-width: 100%; max-height: 62vh;
    transition: border-color .15s ease, background-color .25s ease;
}
.preview-container:not([readonly]) { border-style: solid; color: var(--text-primary); background: var(--bg-surface); }
.preview-container:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.preview-actions { display: flex; gap: .75rem; margin-top: .85rem; }
.sent-badge { padding: .55rem .8rem; border-radius: 10px; font-size: .82rem; font-weight: 600; text-align: center; }
.sent-badge.not-sent { background: var(--bg-base); color: var(--text-light); border: 1px dashed var(--border-color); }
.sent-badge:not(.not-sent) { background: var(--secondary-light); color: var(--secondary); border: 1px solid var(--secondary); }

/* "Ready to send": every checklist item complete → the copy button goes
   bright green with a soft pulse, nudging staff to send on time */
#copyBtn.ready { background: #16a34a; animation: readyPulse 1.8s ease infinite; }
#copyBtn.ready:hover { background: #15803d; }
@keyframes readyPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.45); }
    50% { box-shadow: 0 0 0 9px rgba(22, 163, 74, 0); }
}

/* ─────────────── ANALYTICS (charts + history) ─────────────── */
.analytics-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.export-btn {
    background: var(--primary); color: #fff; border: none; padding: .5rem 1rem; border-radius: 10px;
    cursor: pointer; font-size: .84rem; font-weight: 700; font-family: inherit;
    display: flex; align-items: center; gap: .4rem; white-space: nowrap; transition: opacity .15s ease;
}
.export-btn:hover { opacity: .9; }
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; width: 100%; margin-top: .5rem; }
/* Plain neutral cell (no shift tint) so chart lines stay clearly visible */
.chart-box { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1rem .9rem; display: flex; flex-direction: column; gap: .7rem; min-height: 260px; }
.chart-box-title { font-size: .84rem; font-weight: 700; color: var(--text-primary); }
.chart-canvas-wrapper { position: relative; flex: 1; width: 100%; min-height: 200px; }
@media (min-width: 992px) { .excretion-chart-box { grid-column: span 2; } }

.history-filters { display: grid; grid-template-columns: 1.2fr 1fr; gap: .5rem; margin-bottom: .85rem; }
.history-filters select, .history-filters input { padding: .5rem .7rem; font-size: 15px; border-radius: 8px; }
.timeline-list.history-list { max-height: 260px; }
.history-item { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 9px; padding: .6rem .8rem; display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: background-color .15s ease, border-color .15s ease; }
.history-item:hover { border-color: var(--primary); background: var(--primary-light); }
.history-item-details { display: flex; flex-direction: column; gap: .12rem; }
.history-item-name { font-size: .86rem; font-weight: 700; color: var(--primary); }
.history-item-meta { font-size: .74rem; color: var(--text-secondary); }
.btn-delete-history { background: none; border: none; color: var(--text-light); cursor: pointer; padding: .2rem; transition: color .15s ease; }
.btn-delete-history:hover { color: #dc2626; }

/* ─────────────── PATIENT POPOVER LIST ─────────────── */
.profiles-list { display: flex; gap: .5rem; flex-wrap: wrap; max-height: 200px; overflow-y: auto; padding: .15rem; }
.profile-chip { padding: .4rem .8rem; border-radius: 999px; background: var(--bg-surface); border: 1px solid var(--border-color); cursor: pointer; font-size: .84rem; font-weight: 500; display: flex; align-items: center; gap: .4rem; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.profile-chip:hover { border-color: var(--primary); color: var(--primary); }
.profile-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.profile-chip .delete-profile { font-weight: bold; font-size: .8rem; opacity: .6; margin-left: .2rem; }
.profile-chip .delete-profile:hover { opacity: 1; color: #fecaca; }
.profile-chip .settings-profile { font-size: .85rem; opacity: .6; margin-left: .1rem; }
.profile-chip .settings-profile:hover { opacity: 1; }
.collapsible-toggle { display: flex; align-items: center; gap: .4rem; background: none; border: none; color: var(--text-secondary); font-family: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; padding: .55rem 0 .2rem; margin-top: .5rem; }
.collapsible-toggle:hover { color: var(--primary); }
.collapsible-toggle .chevron { transition: transform .2s ease; display: inline-block; }
.collapsible-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.collapsible-body { display: none; margin-top: .5rem; }
.collapsible-body.open { display: block; }

/* ─────────────── STATUS CHECKLIST ─────────────── */
.status-checklist { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.status-chip { display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .7rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid var(--border-color); background: var(--bg-surface); color: var(--text-secondary); }
.status-chip.done { background: var(--secondary-light); border-color: var(--secondary); color: var(--secondary); }
.status-chip.missing { background: #fef2f2; border-color: #f87171; color: #dc2626; }
[data-theme="dark"] .status-chip.missing { background: hsl(0,40%,14%); border-color: #b91c1c; color: #fca5a5; }

/* ─────────────── ALERT BANNERS ─────────────── */
.alert-banner-overdue { display: flex; align-items: center; gap: .75rem; background: var(--accent-light); border: 1px solid var(--accent); border-radius: var(--radius-md); padding: .8rem 1.1rem; margin-bottom: 1rem; color: var(--accent); font-size: .86rem; line-height: 1.5; }
.alert-banner-overdue strong { color: var(--accent); }
.alert-banner-overdue .alert-icon { font-size: 1.5rem; flex-shrink: 0; }
.alert-banner-overdue.crit { align-items: flex-start; background: #fef2f2; border-color: #ef4444; color: #dc2626; }
.alert-banner-overdue.crit strong { color: #dc2626; }
[data-theme="dark"] .alert-banner-overdue.crit { background: hsl(0,40%,14%); border-color: #b91c1c; color: #fca5a5; }
[data-theme="dark"] .alert-banner-overdue.crit strong { color: #fca5a5; }
.stool-overdue-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.stool-overdue-chip { display: inline-flex; align-items: center; gap: .3rem; background: var(--bg-surface); border: 1px solid #f3bcbc; color: #dc2626; border-radius: 999px; padding: .25rem .6rem; font-size: .78rem; font-weight: 600; font-family: inherit; cursor: pointer; }
.stool-overdue-chip:hover { background: #fef2f2; }
.stool-overdue-chip .d { opacity: .75; font-weight: 400; margin-left: .15rem; }
[data-theme="dark"] .stool-overdue-chip { border-color: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .stool-overdue-chip:hover { background: hsl(0,40%,14%); }
.shift-end-reminder { display: none; align-items: center; gap: .6rem; background: var(--accent-light); border: 1px solid var(--accent); border-radius: var(--radius-md); padding: .7rem 1rem; margin-bottom: 1rem; font-size: .84rem; color: var(--text-secondary); }
.shift-end-reminder.show { display: flex; }
.shift-end-reminder .alert-icon { font-size: 1.3rem; }

/* ─────────────── MODALS ─────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1100; padding: 1rem; animation: fadeIn .2s ease-out; }
.modal-content { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); max-width: 500px; width: 100%; padding: 1.6rem; box-shadow: var(--shadow-xl); animation: slideUp .3s cubic-bezier(.16,1,.3,1); text-align: center; }
.modal-content h3 { margin-top: 0; color: var(--primary); font-size: 1.2rem; display: flex; align-items: center; justify-content: center; gap: .5rem; }
.modal-content p { font-size: .9rem; color: var(--text-secondary); margin-bottom: 1.4rem; line-height: 1.5; }
.modal-toggle-label { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 2px solid var(--border-color); border-radius: var(--radius-md); padding: .75rem; cursor: pointer; user-select: none; transition: all .2s ease; background: var(--bg-base); color: var(--text-primary); }
.modal-toggle-label:hover { border-color: var(--primary); background: var(--primary-light); }
.modal-toggle-label:has(input:checked) { border-color: var(--primary) !important; background: var(--primary-light) !important; color: var(--primary) !important; transform: scale(1.02); box-shadow: 0 0 0 1px var(--primary); }
.modal-toggle-label.attention { border: 2px dashed #ef4444 !important; animation: pulseBorderRed 1.1s ease infinite; }
.exc-modal-error { display: flex; gap: .5rem; align-items: flex-start; text-align: left; background: #fef2f2; border: 1.5px solid #ef4444; color: #dc2626; border-radius: var(--radius-sm); padding: .65rem .8rem; margin-bottom: 1rem; font-size: .86rem; line-height: 1.5; }
[data-theme="dark"] .exc-modal-error { background: hsl(0,40%,14%); border-color: #b91c1c; color: #fca5a5; }
.modal-content.shake { animation: modalShake .45s ease; }

/* shift-status dashboard */
.shift-status-list { display: flex; flex-direction: column; gap: .4rem; max-height: 55vh; overflow-y: auto; }
.ss-head, .ss-row { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: .5rem; align-items: center; padding: .55rem .75rem; border-radius: var(--radius-sm); }
.ss-head { font-size: .78rem; font-weight: 700; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); border-radius: 0; position: sticky; top: 0; background: var(--bg-surface); }
.ss-row { background: var(--bg-base); border: 1px solid var(--border-color); font-size: .85rem; }
.ss-row.pending { border-color: #f87171; background: #fef2f2; }
[data-theme="dark"] .ss-row.pending { background: hsl(0,40%,14%); border-color: #b91c1c; }
.ss-name { font-weight: 600; color: var(--text-primary); }
.ss-name small { display: block; font-weight: 400; color: var(--text-light); font-size: .72rem; }
.ss-name small.ss-cancel { color: #dc2626; font-weight: 600; }
[data-theme="dark"] .ss-name small.ss-cancel { color: #fca5a5; }
.ss-ok { color: var(--secondary); font-weight: 600; font-size: .8rem; }
.ss-pending { color: #dc2626; font-weight: 700; font-size: .8rem; }
[data-theme="dark"] .ss-pending { color: #fca5a5; }

/* ─────────────── STICKY NOTE BAR (narrow only) ─────────────── */
.sticky-note-bar { display: none; }
@media (max-width: 1000px) {
    .sticky-note-bar { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900; background: var(--bg-surface); border-top: 2px solid var(--primary); box-shadow: 0 -4px 16px rgba(0,0,0,.12); }
    body { padding-bottom: 62px; }
    .notification { bottom: 5.5rem; }
}
.sticky-note-collapsed { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem 1rem; cursor: pointer; min-height: 46px; }
.sticky-note-title { font-size: .72rem; color: var(--text-secondary); display: block; }
.sticky-note-status { font-size: .8rem; font-weight: 600; display: block; margin-top: .1rem; }
.sticky-note-status .sn-ok { color: var(--secondary); }
.sticky-note-status .sn-miss { color: var(--text-light); }
.sticky-note-toggle { font-size: .78rem; font-weight: 600; color: var(--primary); white-space: nowrap; flex-shrink: 0; }
.sticky-note-expanded { flex-direction: column; padding: 0 1rem .85rem; border-top: 1px dashed var(--border-color); }
.sticky-note-mirror { background: var(--bg-base); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: .6rem .7rem; margin-top: .6rem; font-size: .75rem; line-height: 1.65; white-space: pre-wrap; max-height: 40vh; overflow-y: auto; color: var(--text-primary); }

/* ─────────────── NOTIFICATION / SAVE FAILURE ─────────────── */
.notification { position: fixed; bottom: 2rem; right: 2rem; background: var(--primary); color: #fff; padding: .75rem 1.4rem; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 1000; font-weight: 500; animation: slideUp .3s ease-out; max-width: min(430px, calc(100vw - 3rem)); line-height: 1.5; white-space: pre-line; }
.save-failure-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; gap: .4rem; flex-wrap: wrap; background: #dc2626; color: #fff; padding: .7rem 1rem; font-size: .9rem; text-align: center; box-shadow: 0 2px 10px rgba(0,0,0,.3); }

/* ─────────────── FOOTER ─────────────── */
footer { text-align: center; padding: 1.25rem; font-size: .78rem; color: var(--text-light); margin-top: 1rem; }

/* ─────────────── ANIMATIONS ─────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes modalShake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes pulseBorderRed { 0%,100% { border-color: #ef4444; } 50% { border-color: transparent; } }
