/* =============================================
   Mom Health Tracker — style.css
   Design: Trustworthy Medical, Warm & Clear
   ============================================= */

/* --- Design Tokens --- */
:root {
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --surface-3: #eef1f5;

    --primary: #1d4ed8;
    /* Deep professional blue */
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    --primary-xlight: #eff6ff;

    --success: #16a34a;
    --success-light: #f0fdf4;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #2563eb;
    --info-light: #eff6ff;
    --purple: #7c3aed;
    --purple-light: #faf5ff;

    --text: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;
    --border: #dde3ec;
    --border-focus: var(--primary);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, .06), 0 3px 10px rgba(0, 0, 0, .06);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, .10);

    --radius: 8px;
    --radius-sm: 5px;
    --radius-xs: 3px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.55;
}

/* =============================================
   HEADER
   ============================================= */
.app-header {
    background: #0d1b2e;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 58px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 2px 8px rgba(0, 0, 0, .25);
    position: sticky;
    top: 0;
    z-index: 200;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header__icon {
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, .08);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, .12);
}

.app-header__title {
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    letter-spacing: 0;
}

.app-header__sub {
    color: rgba(255, 255, 255, .75);
    font-size: 12px;
    margin-top: 1px;
}

.app-header__badge {
    background: rgba(255, 255, 255, .07);
    color: rgba(255, 255, 255, .7);
    font-size: 11px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, .12);
    letter-spacing: .2px;
}

/* =============================================
   NAV TABS
   ============================================= */
.app-nav {
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: center;
    overflow-x: auto;
    scrollbar-width: none;
    position: sticky;
    top: 64px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

.app-nav::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    padding: 14px 28px;
    font-size: 13.5px;
    font-weight: 600;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    color: var(--text-2);
    cursor: pointer;
    white-space: nowrap;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color .15s, border-color .15s, background .15s;
    user-select: none;
    flex-shrink: 0;
    letter-spacing: .2px;
    text-decoration: none;
}

.nav-tab--link {
    color: var(--text-2);
    border-bottom-color: transparent;
}

.nav-tab--link:hover {
    color: var(--primary);
    background: var(--primary-xlight);
    border-bottom-color: var(--primary);
}

@media (max-width: 600px) {
    .app-nav {
        overflow-x: hidden;
        justify-content: stretch;
    }

    .nav-tab {
        flex: 1;
        padding: 12px 4px;
        font-size: 11.5px;
        letter-spacing: 0;
    }
}

.nav-tab:hover {
    color: var(--primary);
    background: var(--primary-xlight);
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--primary-xlight);
    font-weight: 700;
}



/* =============================================
   LAYOUT
   ============================================= */
.app-content {
    padding: 20px 16px 40px;
    max-width: 920px;
    margin: 0 auto;
}

/* =============================================
   CARDS
   ============================================= */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 20px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}

.card--flat {
    background: var(--surface-2);
    box-shadow: none;
    border: 1.5px solid var(--border);
}

.card--priority {
    border-color: #bfdbfe;
    background: #ffffff;
}

.card-title {
    font-size: 11px;
    font-weight: 700;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-edit-btn {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    letter-spacing: .3px;
    padding: 3px 10px;
    border-radius: 4px;
    border: 1.5px solid var(--border);
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .15s, color .15s, background .15s;
    text-transform: none;
}

.card-edit-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-xlight);
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    color: var(--text);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* =============================================
   PATIENT HERO
   ============================================= */
.patient-hero {
    background: #0d1b2e;
    border-radius: var(--radius);
    padding: 20px 18px;
    color: #fff;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    border: 1px solid #1a2e47;
}

.patient-avatar {
    width: 52px;
    height: 52px;
    background: rgba(255, 255, 255, .10);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0;
    color: #fff;
    flex-shrink: 0;
    border: 1.5px solid rgba(255, 255, 255, .18);
}

.patient-info__name {
    font-size: 20px;
    font-weight: 700;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    letter-spacing: -.1px;
}

.patient-info__meta {
    font-size: 13px;
    opacity: .8;
    margin-top: 3px;
}

.condition-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.badge {
    padding: 3px 9px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(255, 255, 255, .08);
    color: rgba(255, 255, 255, .85);
    border: 1px solid rgba(255, 255, 255, .14);
}

.badge--red {
    background: var(--danger-light);
    color: var(--danger);
    border-color: #fecaca;
}

.badge--amber {
    background: var(--warning-light);
    color: var(--warning);
    border-color: #fde68a;
}

.badge--blue {
    background: var(--info-light);
    color: var(--info);
    border-color: #bfdbfe;
}

.badge--purple {
    background: var(--purple-light);
    color: var(--purple);
    border-color: #ddd6fe;
}

/* =============================================
   VITAL CARDS GRID
   ============================================= */
.vital-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}

.vital-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-top: 3px solid var(--primary);
    transition: box-shadow .2s;
}

.vital-card--danger {
    border-top-color: var(--danger);
}

.vital-card--warning {
    border-top-color: var(--warning);
}

.vital-card--info {
    border-top-color: var(--info);
}

.vital-card--purple {
    border-top-color: var(--purple);
}

.vital-card:hover {
    box-shadow: var(--shadow-md);
}

.vital-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .6px;
}

.vital-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    margin: 6px 0 3px;
    color: var(--text);
}

.vital-value small {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-3);
}

.vital-date {
    font-size: 11px;
    color: var(--text-3);
}

/* ── Dashboard enhancements ── */
.vital-value-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 6px 0 4px;
}

.vital-trend {
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
}

.trend-good {
    color: #16a34a;
}

.trend-bad {
    color: var(--danger);
}

.trend-stable {
    color: var(--text-3);
    font-size: 14px;
}

.spark-wrap {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 30px;
    overflow: hidden;
    margin: 2px 0 5px;
    justify-content: flex-start;
}

.spark-bar {
    flex: 0 0 10px;
    width: 10px;
    border-radius: 2px 2px 0 0;
    transition: height 0.4s ease;
}

.spark-bar--ok {
    background: #22c55e;
}

.spark-bar--warn {
    background: #f59e0b;
}

.spark-bar--danger {
    background: #ef4444;
}

.vital-footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.vital-target {
    font-size: 10px;
    color: var(--text-3);
    white-space: nowrap;
}

/* Dynamic status colour via data-status attribute */
.vital-card[data-status="ok"] {
    border-top-color: #22c55e;
}

.vital-card[data-status="warn"] {
    border-top-color: var(--warning);
}

.vital-card[data-status="danger"] {
    border-top-color: var(--danger);
}

/* Status pills */
.pill {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 5px;
}

.pill--ok {
    background: var(--success-light);
    color: var(--success);
}

.pill--warn {
    background: var(--warning-light);
    color: var(--warning);
}

.pill--bad {
    background: var(--danger-light);
    color: var(--danger);
}

.pill--neutral {
    background: var(--surface-3);
    color: var(--text-2);
}

/* =============================================
   ALERTS
   ============================================= */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 14px;
    border-left: 3px solid;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.5;
}

.alert--info {
    background: var(--info-light);
    color: #1e40af;
    border-color: var(--info);
}

.alert--warn {
    background: var(--warning-light);
    color: #92400e;
    border-color: var(--warning);
}

.alert--danger {
    background: var(--danger-light);
    color: #991b1b;
    border-color: var(--danger);
}

.alert--success {
    background: var(--success-light);
    color: #14532d;
    border-color: var(--success);
}

/* =============================================
   FORMS
   ============================================= */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.fg {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.fg label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-2);
    letter-spacing: .1px;
}

/* Diabetes toggle inside patient drawer */
.dm-toggle {
    display: flex !important;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: #fff7ed;
    border: 1.5px solid #fdba74;
    border-radius: 10px;
    cursor: pointer;
    transition: all .2s ease;
}

.dm-toggle:hover {
    background: #ffedd5;
}

.dm-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: #ea580c;
    cursor: pointer;
    flex-shrink: 0;
}

.dm-toggle__text {
    font-size: 13px;
    color: #9a3412;
    font-weight: 500;
    line-height: 1.4;
    text-transform: none;
    letter-spacing: 0;
}

.dm-toggle__text b {
    color: #7c2d12;
}

.dm-toggle__hint {
    display: block;
    font-size: 11px;
    color: #c2410c;
    font-weight: 400;
    margin-top: 2px;
}

.fg input,
.fg select,
.fg textarea {
    padding: 9px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: 'Sarabun', sans-serif;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

.fg input:focus,
.fg select:focus,
.fg textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, .12);
}

.fg textarea {
    resize: vertical;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
    padding: 9px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    font-family: 'Sarabun', sans-serif;
    cursor: pointer;
    border: none;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn--primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 4px rgba(29, 78, 216, .20);
}

.btn--primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 2px 8px rgba(29, 78, 216, .30);
    transform: translateY(-1px);
}

.btn--outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-2);
}

.btn--outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn--danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.btn--danger:hover {
    background: #fee2e2;
}

.btn--print {
    background: var(--info-light);
    color: var(--info);
    border: 1.5px solid #bfdbfe;
}

.btn--sm {
    padding: 5px 12px;
    font-size: 12px;
}

/* =============================================
   DATA TABLE
   ============================================= */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    background: var(--surface-2);
    padding: 9px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .6px;
    border-bottom: 1.5px solid var(--border);
}

.data-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td {
    background: var(--primary-xlight);
}

/* =============================================
   CKD STAGE SELECTOR
   ============================================= */
.ckd-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.ckd-btn {
    padding: 12px 8px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    font-weight: 700;
    font-family: 'Sarabun', sans-serif;
    cursor: pointer;
    text-align: center;
    transition: all .2s;
    line-height: 1.4;
    color: var(--text);
}

.ckd-btn__sub {
    display: block;
    font-size: 10px;
    font-weight: 400;
    color: var(--text-3);
    margin-top: 2px;
}

.ckd-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-xlight);
}

.ckd-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 1px 4px rgba(29, 78, 216, .25);
}

.ckd-btn.active .ckd-btn__sub {
    color: rgba(255, 255, 255, .75);
}

/* ── Segmented pick buttons (replaces select dropdowns) ── */
.seg-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.seg-btn {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 13px;
    font-weight: 500;
    font-family: 'Sarabun', sans-serif;
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, background .15s, color .15s;
    color: var(--text);
    white-space: nowrap;
    line-height: 1.4;
}

.seg-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-xlight);
}

.seg-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

.seg-sub {
    display: block;
    font-size: 10px;
    font-weight: 400;
    color: var(--text-3);
    margin-top: 2px;
}

.seg-btn.active .seg-sub {
    color: rgba(255, 255, 255, .75);
}

/* =============================================
   NUTRIENT BARS
   ============================================= */
.bar-section {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.bar-item {
    margin-bottom: 12px;
}

.bar-item:last-child {
    margin-bottom: 0;
}

.bar-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 13px;
}

.bar-header b {
    font-weight: 700;
}

.bar-header span {
    color: var(--text-2);
    font-size: 12px;
}

.bar-track {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width .5s ease;
    width: 0;
}

.bar-fill--ok {
    background: #16a34a;
}

.bar-fill--warn {
    background: #d97706;
}

.bar-fill--bad {
    background: #dc2626;
}

/* =============================================
   FOOD SEARCH
   ============================================= */
.food-search {
    position: relative;
    margin-bottom: 14px;
}

.food-search__input {
    width: 100%;
    padding: 11px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: 'Sarabun', sans-serif;
    transition: border-color .2s, box-shadow .2s;
    outline: none;
    background: var(--surface);
}

.food-search__input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, .12);
}

.food-dropdown {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    position: absolute;
    width: 100%;
    z-index: 100;
    top: calc(100% + 4px);
}

.food-item {
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background .15s;
}

.food-item:hover {
    background: var(--primary-xlight);
}

.food-item:last-child {
    border-bottom: none;
}

.food-item__name {
    font-size: 14px;
    font-weight: 600;
}

.food-item__meta {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 2px;
}

.food-item__warn {
    font-size: 11px;
    color: var(--danger);
    font-weight: 700;
}

.food-item__decision {
    margin-top: 5px;
}

.food-item__plus {
    color: var(--primary);
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
    padding-left: 8px;
}

.cat-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--surface-3);
    color: var(--text-2);
    font-weight: 500;
    margin-left: 4px;
}

/* =============================================
   MEDICINE LIST
   ============================================= */
.med-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    transition: opacity .2s;
}

.med-item:last-child {
    border-bottom: none;
}

.med-item--paused {
    opacity: .6;
    background: var(--warning-light);
    margin: 0 -20px;
    padding: 12px 20px;
}

.med-item--stopped {
    opacity: .4;
    background: var(--surface-2);
    margin: 0 -20px;
    padding: 12px 20px;
}

.med-hosp-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--info-light);
    color: var(--info);
    font-weight: 600;
    margin-left: 6px;
    border: 1px solid #bfdbfe;
    vertical-align: middle;
}

/* Per-hospital colour variants */
.med-hosp-tag--blue {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.med-hosp-tag--teal {
    background: #f0fdfa;
    color: #0f766e;
    border-color: #99f6e4;
}

.med-hosp-tag--purple {
    background: #faf5ff;
    color: #7c3aed;
    border-color: #ddd6fe;
}

.med-hosp-tag--amber {
    background: #fffbeb;
    color: #b45309;
    border-color: #fcd34d;
}

.med-hosp-tag--rose {
    background: #fff1f2;
    color: #be123c;
    border-color: #fecdd3;
}

.med-status-note {
    font-size: 11px;
    color: var(--text-2);
    margin-top: 4px;
    padding: 3px 7px;
    background: rgba(0, 0, 0, .04);
    border-radius: 3px;
    display: inline-block;
}

.med-inline-form {
    margin-top: 10px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.med-inline-form--edit {
    border-color: var(--primary);
    background: var(--primary-xlight);
}

.med-inline-form__title {
    font-size: 12px;
    font-weight: 700;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    color: var(--warning);
    margin-bottom: 2px;
}

.med-inline-form--edit .med-inline-form__title {
    color: var(--primary);
}

.btn--edit-icon {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-3);
    font-size: 15px;
    padding: 4px 8px;
}

.btn--edit-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* Inline edit inputs inside table rows */
.tr--editing td {
    background: var(--primary-xlight);
    padding: 6px 8px;
}

.input-inline {
    width: 100%;
    padding: 4px 6px;
    font-size: 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
}

.input-inline:focus {
    border-color: var(--primary);
    outline: none;
}

.input-bp-wrap {
    display: flex;
    align-items: center;
    gap: 3px;
}

.input-bp {
    width: 52px !important;
}

.input-sm {
    width: 64px !important;
}

.td-actions {
    white-space: nowrap;
}

.med-status-btns {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: flex-start;
    padding-top: 2px;
}

.btn--paused-on {
    background: var(--warning-light);
    color: var(--warning);
    border: 1.5px solid #fde68a;
}

.btn--stopped-on {
    background: var(--surface-3);
    color: var(--text-3);
    border: 1.5px solid var(--border);
}

.med-filter-row {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.med-filter-btn {
    padding: 5px 14px;
    border-radius: 5px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 12px;
    font-weight: 600;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    color: var(--text-2);
    cursor: pointer;
    transition: all .15s;
}

.med-filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Hospital sub-filter row */
.med-filter-row--hosp {
    margin-top: -6px;
    margin-bottom: 14px;
}

.med-filter-btn--hosp {
    font-size: 11px;
    padding: 3px 10px;
    font-weight: 600;
    border-radius: 20px;
}

/* When a hosp btn is active, override with its own tag colour */
.med-filter-btn--hosp.med-hosp-tag--blue.active {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #fff;
}

.med-filter-btn--hosp.med-hosp-tag--teal.active {
    background: #0f766e;
    border-color: #0f766e;
    color: #fff;
}

.med-filter-btn--hosp.med-hosp-tag--purple.active {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #fff;
}

.med-filter-btn--hosp.med-hosp-tag--amber.active {
    background: #b45309;
    border-color: #b45309;
    color: #fff;
}

.med-filter-btn--hosp.med-hosp-tag--rose.active {
    background: #be123c;
    border-color: #be123c;
    color: #fff;
}

.med-inactive-note {
    margin-top: 10px;
}

.med-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.med-name {
    font-size: 14px;
    font-weight: 700;
}

.med-dose {
    font-size: 12px;
    color: var(--text-2);
    margin-top: 2px;
}

.med-tag {
    display: inline-block;
    background: var(--success-light);
    color: var(--success);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
}

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
    text-align: center;
    padding: 28px 16px;
    color: var(--text-3);
    font-size: 13px;
}

.empty-state__icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
    opacity: .5;
}

/* =============================================
   LAB RESULT GRID
   ============================================= */
.lab-result-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.lab-item {
    background: var(--surface-2);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.lab-item__label {
    font-size: 11px;
    color: var(--text-3);
}

.lab-item__value {
    font-size: 15px;
    font-weight: 700;
    margin-top: 2px;
}

.lab-item__unit {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-3);
    margin-left: 2px;
}

/* =============================================
   FOOD LOG SUMMARY BAR
   ============================================= */
.food-summary {
    background: var(--success-light);
    border: 1px solid #bbf7d0;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 13px;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.food-log-row--warn td {
    background: #fff7ed;
}

.food-log-warning {
    font-size: 11px;
    color: var(--danger);
    font-weight: 700;
    margin-left: 4px;
}

/* =============================================
   GUIDE PANELS
   ============================================= */
.guide-panel {
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 10px;
}

.guide-panel--ok {
    background: var(--success-light);
    border: 1px solid #bbf7d0;
}

.guide-panel--warn {
    background: var(--warning-light);
    border: 1px solid #fde68a;
}

.guide-panel--avoid {
    background: var(--danger-light);
    border: 1px solid #fecaca;
}

.guide-panel__title {
    font-weight: 700;
    margin-bottom: 10px;
    font-size: 14px;
}

.guide-panel--ok .guide-panel__title {
    color: var(--success);
}

.guide-panel--warn .guide-panel__title {
    color: var(--warning);
}

.guide-panel--avoid .guide-panel__title {
    color: var(--danger);
}

.guide-item {
    font-size: 13px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, .06);
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.guide-item:last-child {
    border-bottom: none;
}

/* ── Diet intro & target cards ── */
.diet-intro {
    background: var(--primary-xlight);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 16px;
}

.diet-intro__title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-weight: 700;
    color: var(--primary);
    font-size: 15px;
    margin-bottom: 4px;
}

.diet-intro__text {
    font-size: 13px;
    color: var(--text-2);
    margin: 0;
    line-height: 1.55;
}

.daily-target-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.target-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.target-card--protein {
    border-top-color: #db2777;
}

.target-card--k {
    border-top-color: #d97706;
}

.target-card--p {
    border-top-color: #7c3aed;
}

.target-card--na {
    border-top-color: var(--danger);
}

.target-card--water {
    border-top-color: #0891b2;
}

.target-card__icon {
    font-size: 18px;
    margin-bottom: 2px;
}

.target-card__label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .3px;
    margin-bottom: 4px;
}

.target-card__value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.target-card__value small {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-3);
}

.target-card__hint {
    font-size: 10.5px;
    color: var(--text-3);
    margin-top: 4px;
}

/* ── Tips & warning signs ── */
.tips-card {
    background: var(--primary-xlight);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 12px 0 14px;
    border: 1px solid #c7d2fe;
}

.tips-card__title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-weight: 700;
    color: var(--primary);
    font-size: 14px;
    margin-bottom: 8px;
}

.tips-list {
    margin: 0;
    padding-left: 22px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
}

.tips-list li {
    margin-bottom: 4px;
}

.warning-signs {
    background: var(--danger-light);
    border: 1.5px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
}

.warning-signs__title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-weight: 700;
    color: var(--danger);
    font-size: 14px;
    margin-bottom: 10px;
}

.warning-signs__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.warning-sign {
    background: var(--surface);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12.5px;
    line-height: 1.4;
}

.warning-sign small {
    color: var(--text-3);
    font-size: 11px;
}

/* ── Nutrient explainer ── */
.nutrient-explainer {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
    margin-bottom: 18px;
}

.nutrient-exp-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    border: 1px solid var(--border);
}

.nutrient-exp-icon {
    font-size: 22px;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 1px;
}

.nutrient-exp-item b {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.nutrient-exp-item p {
    font-size: 12px;
    color: var(--text-3);
    margin: 0;
    line-height: 1.45;
}

/* ── Guide panel subtitle ── */
.guide-panel__sub {
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: 10px;
    margin-top: -4px;
    line-height: 1.4;
}

/* =============================================
   DIVIDER
   ============================================= */
.divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

/* =============================================
   ACTIONS ROW
   ============================================= */
.actions-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* =============================================
   DOCTOR BRIEF & PREP
   ============================================= */
.brief-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.brief-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.brief-card--full {
    grid-column: 1 / -1;
}

.brief-card__label {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.brief-card__value {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    margin-top: 4px;
}

.brief-card__note {
    color: var(--text-2);
    font-size: 12px;
    margin-top: 4px;
}

.brief-card__list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.symptom-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.check-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
}

.check-card input {
    accent-color: var(--primary);
}

.check-card:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-xlight);
    color: var(--primary-dark);
}

/* =============================================
   CKD QUOTA
   ============================================= */
.quota-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 14px;
}

.quota-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.quota-card__label {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 700;
}

.quota-card__value {
    font-size: 16px;
    font-weight: 700;
    margin-top: 2px;
}

.quota-card__value--ok {
    color: var(--success);
}

.quota-card__value--warn {
    color: var(--warning);
}

.quota-card__value--bad {
    color: var(--danger);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: -4px 0 14px;
}

/* ── Quick meal groups ── */
.quick-meal-groups {
    margin: 0 0 14px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px 20px;
    align-items: start;
}

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

.qmg-label {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .4px;
}

.qmg-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Accordion style ── */
.qmg-accordion {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 14px;
}

.qmg-group {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.qmg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    background: var(--surface-2);
    user-select: none;
    transition: background .15s;
}

.qmg-header::-webkit-details-marker {
    display: none;
}

.qmg-header::after {
    content: '›';
    margin-left: auto;
    font-size: 16px;
    color: var(--text-3);
    transition: transform .2s;
}

.qmg-group[open]>.qmg-header {
    background: var(--primary-xlight);
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.qmg-group[open]>.qmg-header::after {
    transform: rotate(90deg);
}

.qmg-body {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 14px 12px;
    background: var(--surface);
}

/* ── Elder-friendly diet page ── */
body[data-page="diet"] .app-content {
    max-width: 1160px;
}

body[data-page="diet"] .card {
    border-radius: 12px;
}

.diet-step-card {
    background: linear-gradient(180deg, #f8fbff 0%, #f3f8ff 100%);
    border: 1px solid #dbeafe;
}

.diet-ckd-dock {
    border: 2px solid #bfdbfe;
    background: #f8fbff;
}

.diet-ckd-note {
    font-size: 14px;
    color: var(--text-2);
    margin: -2px 0 10px;
}

.diet-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.diet-step {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid #dbeafe;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.diet-step span {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

.diet-switch-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.diet-switch-btn {
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text-2);
    min-height: 48px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 700;
    font-family: 'Prompt', 'Sarabun', sans-serif;
    cursor: pointer;
    transition: all .15s;
}

.diet-switch-btn.active {
    color: var(--primary);
    border-color: #93c5fd;
    background: var(--primary-xlight);
}

body[data-page="diet"] .section-title {
    font-size: 22px;
}

body[data-page="diet"] .ckd-btn {
    min-height: 70px;
    font-size: 18px;
    border-radius: 10px;
}

body[data-page="diet"] .ckd-btn__sub {
    font-size: 14px;
}

body[data-page="diet"] .food-search__input {
    min-height: 56px;
    font-size: 20px;
}

body[data-page="diet"] .qmg-header {
    min-height: 58px;
    font-size: 19px;
    font-weight: 700;
}

body[data-page="diet"] .qmg-body .btn {
    min-height: 50px;
    font-size: 18px;
    padding: 8px 14px;
}

@media (max-width: 720px) {
    .diet-switch-row {
        grid-template-columns: 1fr;
    }

    body[data-page="diet"] .section-title {
        font-size: 20px;
    }

    body[data-page="diet"] .food-search__input {
        font-size: 17px;
    }

    body[data-page="diet"] .qmg-header {
        font-size: 16px;
    }

    body[data-page="diet"] .qmg-body .btn {
        font-size: 15px;
    }
}

/* =============================================
   TRAFFIC-LIGHT DIET PAGE (.tl-*)
   ============================================= */

/* ── CKD compact bar ── */
.tl-ckd-bar {
    padding: 12px 16px;
}

.tl-ckd-current {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 6px 0;
}

.tl-ckd-label {
    font-size: 16px;
    color: var(--text-2);
    flex-shrink: 0;
}

.tl-ckd-current strong {
    font-size: 20px;
    color: var(--primary);
    font-family: 'Prompt', sans-serif;
}

.tl-ckd-chevron {
    margin-left: auto;
    font-size: 18px;
    color: var(--primary);
    transition: transform .2s;
}

/* ── Traffic-light grid card ── */
.tl-grid-card {
    padding: 14px 16px;
}

.tl-main-title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.tl-legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-2);
}

/* ── How-to guide (kid-friendly explainer) ── */
.tl-howto {
    background: #f0f9ff;
    border: 1px dashed #7dd3fc;
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tl-howto-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text);
    line-height: 1.4;
}

.tl-howto-row b {
    color: #0369a1;
}

.tl-howto-badge {
    position: static !important;
    flex-shrink: 0;
}

.tl-howto-portion {
    display: inline-block;
    min-width: 50px;
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    background: #fff;
    border: 1px solid #e0f2fe;
    border-radius: 6px;
    padding: 2px 6px;
    font-weight: 500;
    flex-shrink: 0;
}

body[data-page="diet"] .tl-howto-row {
    font-size: 13px;
}

/* ── 7-day history strip ── */
#tl-history:empty,
#tl-suggest:empty {
    display: none;
}

.tl-hist-strip {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 14px;
}

.tl-hist-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font-family: inherit;
    cursor: pointer;
    transition: transform .15s, border-color .15s;
}

.tl-hist-day:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.tl-hist-day.is-today {
    border-color: var(--primary);
    background: rgba(8, 145, 178, .06);
    box-shadow: 0 0 0 2px rgba(8, 145, 178, .15);
}

.tl-hist-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #cbd5e1;
}

.tl-hist-day--ok .tl-hist-dot {
    background: #22c55e;
}

.tl-hist-day--warn .tl-hist-dot {
    background: #eab308;
}

.tl-hist-day--over .tl-hist-dot {
    background: #ef4444;
}

.tl-hist-day--empty .tl-hist-dot {
    background: #e2e8f0;
}

.tl-hist-label {
    font-size: 11px;
    color: var(--text-2);
    font-weight: 600;
}

.tl-hist-day.is-today .tl-hist-label {
    color: var(--primary);
}

.tl-hist-count {
    font-size: 10px;
    color: var(--text-2);
    opacity: .7;
}

/* History modal */
.tl-hist-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    animation: tl-warn-in .2s ease;
}

.tl-hist-modal-inner {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tl-hist-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.tl-hist-modal-head h3 {
    margin: 0;
    font-size: 17px;
    color: var(--text);
    font-family: 'Prompt', sans-serif;
}

.tl-hist-close {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: #f1f5f9;
    color: var(--text-2);
    font-size: 14px;
    cursor: pointer;
}

.tl-hist-close:hover {
    background: #e2e8f0;
}

.tl-hist-modal-body {
    padding: 14px 18px 18px;
    overflow-y: auto;
}

.tl-hist-totals {
    background: #f8fafc;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.85;
    color: var(--text-2);
}

.tl-hist-totals b {
    color: var(--text);
    font-weight: 700;
}

.tl-hist-items-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.tl-hist-items {
    margin: 0;
    padding-left: 18px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
}

.tl-hist-items li.muted {
    color: var(--text-2);
    list-style: none;
    padding-left: 0;
}

/* ── Smart suggestions ── */
.tl-suggest-card {
    background: linear-gradient(135deg, #ecfeff 0%, #f0fdf4 100%);
    border: 1.5px solid #a7f3d0;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.tl-suggest-card--full {
    background: linear-gradient(135deg, #fef3c7 0%, #fef9c3 100%);
    border-color: #fde68a;
}

.tl-suggest-head {
    margin-bottom: 8px;
}

.tl-suggest-title {
    font-size: 15px;
    font-weight: 700;
    color: #065f46;
    font-family: 'Prompt', sans-serif;
}

.tl-suggest-card--full .tl-suggest-title {
    color: #92400e;
}

.tl-suggest-sub {
    font-size: 12px;
    color: var(--text-2);
    margin-top: 1px;
}

.tl-suggest-msg {
    font-size: 13px;
    color: #92400e;
    line-height: 1.5;
}

.tl-suggest-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tl-suggest-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 11px;
    border: 1.5px solid #6ee7b7;
    border-radius: 999px;
    background: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #065f46;
    cursor: pointer;
    transition: transform .12s, background .15s;
}

.tl-suggest-chip:hover {
    background: #d1fae5;
    transform: translateY(-1px);
}

.tl-suggest-emoji {
    font-size: 15px;
}

/* ── Toolbar: search + filters ── */
.tl-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
}

.tl-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.tl-search-icon {
    position: absolute;
    left: 12px;
    font-size: 16px;
    pointer-events: none;
    opacity: .65;
}

.tl-search-input {
    width: 100%;
    padding: 11px 38px 11px 38px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}

.tl-search-input::-webkit-search-cancel-button {
    display: none;
}

.tl-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, .15);
}

.tl-search-clear {
    position: absolute;
    right: 8px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}

.tl-search-clear:hover {
    background: #cbd5e1;
}

.tl-search-clear.is-hidden {
    display: none;
}

.tl-filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tl-chip {
    padding: 7px 14px;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text-2);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.tl-chip:hover {
    border-color: var(--primary);
    color: var(--text);
}

.tl-chip.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.tl-chip--ok.is-active {
    background: #16a34a;
    border-color: #16a34a;
}

.tl-chip--warn.is-active {
    background: #ca8a04;
    border-color: #ca8a04;
}

.tl-chip--avoid.is-active {
    background: #dc2626;
    border-color: #dc2626;
}

/* ── Recent foods strip ── */
.tl-category--recent .tl-cat-label {
    color: #b45309;
    border-bottom-color: #fde68a;
}

.tl-grid-empty {
    text-align: center;
    font-size: 18px;
    color: var(--text-2);
    padding: 20px 0;
}

/* ── Category ── */
.tl-category {
    margin-bottom: 16px;
}

.tl-cat-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
    padding-bottom: 5px;
    border-bottom: 1.5px solid var(--border);
}

.tl-cat-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

/* ── Food card ── */
.tl-food-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    padding: 8px 4px 6px;
    border-radius: 12px;
    border: 2px solid transparent;
    cursor: pointer;
    font-family: 'Sarabun', sans-serif;
    transition: transform .12s, box-shadow .12s;
    min-height: 72px;
    background: #fff;
    -webkit-tap-highlight-color: transparent;
}

.tl-food-card:active {
    transform: scale(0.93);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, .2);
}

/* Dot: plain solid circle at top-right corner (legacy, kept for compat) */
.tl-food-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tl-food-dot--ok {
    background: #22c55e;
}

.tl-food-dot--warn {
    background: #f59e0b;
}

.tl-food-dot--red {
    background: #ef4444;
}

/* ── Count badge (kid-friendly remaining portions) ── */
.tl-food-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 24px;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    color: #fff;
    letter-spacing: .1px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
    pointer-events: none;
    white-space: nowrap;
}

.tl-food-badge--ok {
    background: #16a34a;
}

.tl-food-badge--warn {
    background: #d97706;
}

.tl-food-badge--full {
    background: #94a3b8;
    font-size: 10px;
}

.tl-food-badge--avoid {
    background: #dc2626;
    font-size: 10px;
}

/* Portion unit hint below name */
.tl-food-portion {
    font-size: 10px;
    color: #94a3b8;
    line-height: 1.2;
    margin-top: 1px;
    font-weight: 500;
}

body[data-page="diet"] .tl-food-portion {
    font-size: 11px;
}

body[data-page="diet"] .tl-food-badge {
    font-size: 12px;
    height: 22px;
    min-width: 28px;
    line-height: 22px;
}

.tl-food-emoji {
    font-size: 26px;
    line-height: 1.1;
    margin-top: 2px;
}

.tl-food-name {
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
    margin-top: 3px;
}

.tl-card--green {
    background: #f0fdf4;
    border-color: #86efac;
    color: #166534;
}

.tl-card--yellow {
    background: #fffbeb;
    border-color: #fcd34d;
    color: #78350f;
}

.tl-card--red {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #991b1b;
}

/* ── Log section ── */
.tl-log-title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}

.tl-log-empty {
    text-align: center;
    font-size: 17px;
    color: var(--text-2);
    padding: 14px 0;
}

.tl-food-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.tl-food-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-xlight);
    color: var(--primary);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
}

.tl-food-pill button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    font-size: 14px;
    padding: 0;
    line-height: 1;
    opacity: .7;
    transition: opacity .15s;
}

.tl-food-pill button:hover {
    opacity: 1;
}

.tl-clear-btn {
    margin-top: 4px;
}

/* ── Elder-friendly overrides on diet page ── */
body[data-page="diet"] .tl-food-card {
    min-height: 82px;
    padding: 8px 4px 6px;
}

body[data-page="diet"] .tl-food-emoji {
    font-size: 30px;
}

body[data-page="diet"] .tl-food-name {
    font-size: 14px;
}

body[data-page="diet"] .tl-food-dot {
    width: 9px;
    height: 9px;
}

body[data-page="diet"] .tl-main-title {
    font-size: 22px;
}

body[data-page="diet"] .tl-log-title {
    font-size: 20px;
}

body[data-page="diet"] .tl-food-pill {
    font-size: 17px;
    padding: 9px 16px;
}

body[data-page="diet"] .tl-ckd-current strong {
    font-size: 22px;
}

body[data-page="diet"] .ckd-btn {
    min-height: 64px;
    font-size: 17px;
}

/* ── Mobile: 4 columns on small screens ── */
@media (max-width: 480px) {
    .tl-cat-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 5px;
    }

    .tl-food-name {
        font-size: 12px;
    }

    body[data-page="diet"] .tl-food-name {
        font-size: 13px;
    }
}

/* ── Toast ── */
.tl-toast {
    position: fixed;
    top: 68px;
    left: 50%;
    transform: translateX(-50%);
    background: #1d4ed8;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    font-family: 'Sarabun', sans-serif;
    padding: 11px 22px;
    border-radius: 999px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .22);
    z-index: 1000;
    white-space: nowrap;
    animation: tl-toast-in .2s ease;
    transition: opacity .32s ease;
}

.tl-toast.tl-toast--hide {
    opacity: 0;
}

@keyframes tl-toast-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ── Sticky bottom bar ── */
.tl-sticky {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 14px 12px;
    background: #0f172a;
    color: #fff;
    font-family: 'Sarabun', sans-serif;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, .32);
    z-index: 100;
    animation: tl-sticky-in .25s ease;
}

/* ── Status banner (3-level: ok / warn / over) ── */
.tl-status-banner {
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 8px;
    border: 1px solid transparent;
    animation: tl-warn-in .3s ease;
}

.tl-status--ok {
    background: rgba(34, 197, 94, .15);
    border-color: rgba(34, 197, 94, .40);
}

.tl-status--warn {
    background: rgba(234, 179, 8, .18);
    border-color: rgba(234, 179, 8, .50);
}

.tl-status--over {
    background: rgba(239, 68, 68, .18);
    border-color: rgba(239, 68, 68, .50);
}

.tl-status-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tl-status-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}

.tl-status-chip--ok {
    background: rgba(34, 197, 94, .25);
    color: #bbf7d0;
}

.tl-status-chip--warn {
    background: rgba(234, 179, 8, .28);
    color: #fef08a;
}

.tl-status-chip--over {
    background: rgba(239, 68, 68, .30);
    color: #fecaca;
}

.tl-status-details {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, .12);
}

.tl-status-row {
    font-size: 12px;
    line-height: 1.45;
    font-weight: 500;
}

.tl-status-row--over {
    color: #fecaca;
}

.tl-status-row--warn {
    color: #fef9c3;
}

.tl-status-row--ok {
    color: #bbf7d0;
}

.tl-status-row b {
    color: #fff;
    font-weight: 700;
}

body[data-page="diet"] .tl-status-row {
    font-size: 13px;
}

body[data-page="diet"] .tl-status-chip {
    font-size: 13px;
}

@keyframes tl-warn-in {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes tl-sticky-in {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* Two-column inner wrapper — desktop default */
.tl-sb-inner {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

/* LEFT: pills + action buttons */
.tl-sb-left {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Pills row — desktop: wrap, mobile: single horizontal scroll */
.tl-sb-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tl-sb-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.tl-sb-pill button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, .6);
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color .15s;
}

.tl-sb-pill button:hover {
    color: #f87171;
}

/* Action buttons */
.tl-sb-actions {
    display: flex;
    gap: 8px;
}

.tl-sb-btn {
    font-family: 'Sarabun', sans-serif;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    transition: opacity .15s;
}

.tl-sb-btn--undo {
    background: rgba(255, 255, 255, .13);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, .28);
}

.tl-sb-btn--clear {
    background: #ef4444;
    color: #fff;
}

.tl-sb-btn:hover {
    opacity: .82;
}

/* RIGHT: nutrient stats panel — desktop 2-column grid */
.tl-sb-stats {
    flex-shrink: 0;
    width: 270px;
    border-left: 1px solid rgba(255, 255, 255, .14);
    padding-left: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    row-gap: 5px;
    align-content: start;
}

.tl-sb-stats-title {
    grid-column: 1 / -1;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .4);
    margin-bottom: 0;
}

/* Each nutrient stat row */
.tl-sr {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tl-sr-top {
    display: none;
}

.tl-sr-label {
    font-size: 10px;
    font-weight: 600;
    color: rgba(255, 255, 255, .55);
    white-space: nowrap;
    line-height: 1;
}

.tl-sr-val {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1.2;
}

.tl-sr-val small {
    font-size: 9px;
    font-weight: 400;
    color: rgba(255, 255, 255, .4);
}

/* Mini progress bar */
.tl-sr-bar {
    height: 3px;
    background: rgba(255, 255, 255, .1);
    border-radius: 99px;
    overflow: hidden;
}

.tl-sr-fill {
    height: 100%;
    border-radius: 99px;
    transition: width .3s ease;
}

/* Color states */
.tl-sr--ok .tl-sr-val {
    color: #86efac;
}

.tl-sr--ok .tl-sr-fill {
    background: #22c55e;
}

.tl-sr--warn .tl-sr-val {
    color: #fde68a;
}

.tl-sr--warn .tl-sr-fill {
    background: #f59e0b;
}

.tl-sr--over .tl-sr-val {
    color: #fca5a5;
}

.tl-sr--over .tl-sr-fill {
    background: #ef4444;
}

/* ── Mobile: column stack layout ── */
@media (max-width: 599px) {

    /* Stack everything vertically */
    .tl-sb-inner {
        flex-direction: column;
        gap: 8px;
        min-width: 0;
        width: 100%;
    }

    /* LEFT col takes full width */
    .tl-sb-left {
        width: 100%;
        min-width: 0;
    }

    /* Pills: single scrollable row — width constrained so overflow-x:auto works */
    .tl-sb-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .tl-sb-pills::-webkit-scrollbar {
        display: none;
    }

    /* Stats: horizontal scrollable strip — override specificity with !important */
    .tl-sb-stats,
    body[data-page="diet"] .tl-sb-stats {
        width: 100% !important;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, .12);
        padding-left: 0;
        padding-top: 8px;
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        gap: 12px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tl-sb-stats::-webkit-scrollbar {
        display: none;
    }

    .tl-sb-stats-title {
        display: none;
    }

    /* Each stat item: compact vertical chip */
    .tl-sr,
    body[data-page="diet"] .tl-sr {
        flex-shrink: 0;
        min-width: 64px;
    }

    .tl-sr-top {
        gap: 2px;
    }

    /* Smaller actions row */
    .tl-sb-actions {
        gap: 6px;
    }

    .tl-sb-btn {
        font-size: 13px;
        padding: 7px 16px;
    }
}

/* ── Flash animation when card is tapped ── */
@keyframes tl-flash {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }

    35% {
        transform: scale(0.88);
        filter: brightness(1.3);
    }

    70% {
        transform: scale(1.04);
        filter: brightness(1.1);
    }

    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

.tl-card--flash {
    animation: tl-flash .45s ease;
}

/* Elder-friendly sizing — desktop only */
body[data-page="diet"] .tl-sb-pill {
    font-size: 15px;
    padding: 7px 13px;
}

body[data-page="diet"] .tl-sb-pill button {
    font-size: 16px;
}

body[data-page="diet"] .tl-sr-label {
    font-size: 11px;
}

body[data-page="diet"] .tl-sr-val {
    font-size: 12px;
}

@media (min-width: 600px) {
    body[data-page="diet"] .tl-sb-btn {
        font-size: 15px;
        padding: 8px 18px;
    }

    body[data-page="diet"] .tl-sb-stats {
        width: 240px;
    }
}
}

/* ── Padding bottom to prevent sticky bar covering content ── */
body[data-page="diet"] .app-content {
    padding-bottom: 175px;
}

@media (max-width: 599px) {
    body[data-page="diet"] .app-content {
        padding-bottom: 130px;
    }
}

/* =============================================
   PATIENT DRAWER
   ============================================= */
.hero-edit-btn {
    margin-left: auto;
    flex-shrink: 0;
    background: rgba(255, 255, 255, .12);
    border: 1.5px solid rgba(255, 255, 255, .25);
    color: #fff;
    font-size: 17px;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .18s;
}

.hero-edit-btn:hover {
    background: rgba(255, 255, 255, .22);
}

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s ease;
}

.drawer-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

.patient-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    background: var(--surface);
    box-shadow: -4px 0 24px rgba(0, 0, 0, .18);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}

.patient-drawer.is-open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 16px;
    border-bottom: 1px solid var(--border);
    background: #0d1b2e;
    flex-shrink: 0;
}

.drawer-title {
    font-family: 'Prompt', 'Sarabun', sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.drawer-close {
    background: rgba(255, 255, 255, .1);
    border: none;
    color: #fff;
    font-size: 22px;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drawer-close:hover {
    background: rgba(255, 255, 255, .2);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

.drawer-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    background: var(--surface-2);
    flex-shrink: 0;
}

.drawer-footer .btn {
    flex: 1;
}

/* Mobile: full-width drawer from bottom on small screens */
@media (max-width: 480px) {
    .patient-drawer {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }

    .patient-drawer.is-open {
        transform: translateY(0);
    }

    .drawer-header {
        border-radius: 16px 16px 0 0;
    }
}

/* =============================================
   UTILITIES & TOAST
   ============================================= */
.is-hidden {
    display: none !important;
}

.span-full {
    grid-column: 1 / -1;
}

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

.stack-card {
    margin-bottom: 10px;
}

.stack-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.flex-fill {
    flex: 1;
}

.muted-text {
    color: var(--text-3);
    font-weight: 400;
}

.tiny-pill {
    font-size: 10px;
    padding: 1px 7px;
}

.meta-line {
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: 10px;
}

.bar-caption {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-3);
    margin-bottom: 12px;
}

.ckd-note {
    font-size: 12px;
}

.guide-disclaimer {
    margin-top: 12px;
    font-size: 12px;
}

.app-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #0f172a;
    color: #fff;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-family: 'Sarabun', sans-serif;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 9999;
    white-space: nowrap;
}

.app-toast--show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 540px) {

    .vital-grid,
    .form-grid,
    .ckd-grid,
    .lab-result-grid,
    .brief-grid,
    .symptom-grid,
    .quota-grid {
        grid-template-columns: 1fr;
    }

    .ckd-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .app-header {
        padding: 0 16px;
    }

    .app-header__badge {
        display: none;
    }

    .nav-tab {
        padding: 12px 14px;
    }
}

@media (max-width: 380px) {
    .ckd-grid {
        grid-template-columns: 1fr 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}