/* =====================================================
   Alert-EXP - Expiration Alert System
   Warm light theme: "kitchen label" — cream paper, ink text, one herb-green accent
   Text colors are checked for WCAG AA contrast on --bg-primary and --bg-card
   ===================================================== */

/* =====================================================
   CSS Variables (Design Tokens)
   ===================================================== */
:root {
    color-scheme: light;             /* native controls (date picker, scrollbars) match */

    /* Colors — contrast ratios are against #fffaf0 */
    --bg-primary: #fffaf0;           /* page: cream paper */
    --bg-secondary: #f6eedf;         /* sunken areas: sidebar */
    --bg-card: #ffffff;
    --bg-card-hover: #ffffff;
    --bg-glass: #f6eedf;             /* secondary buttons, progress track */
    --bg-glass-hover: #efe5d2;
    --bg-input: #ffffff;
    --bg-sidebar: #f6eedf;
    --overlay: rgba(43, 38, 34, 0.45);

    --text-primary: #2b2622;         /* ink, 14.4:1 */
    --text-secondary: #6b6158;       /* 5.8:1 */
    --text-muted: #766b5f;           /* 5.0:1 */
    --text-on-accent: #ffffff;

    --accent: #2f6b4f;               /* herb green, 6.1:1 */
    --accent-hover: #255a42;
    --accent-glow: #e3eee6;          /* tint: active nav item, focus ring */

    --green: #336d2e;                /* safe, 6.0:1 */
    --green-bg: #e5f1df;
    --green-bg-hover: #d7eacd;
    --green-border: #c9e0c0;
    --yellow: #866300;               /* ≤ 7 days, 5.3:1 */
    --yellow-bg: #fbf0c9;
    --orange: #a14d00;               /* ≤ 3 days, 5.6:1 */
    --orange-bg: #fdebd6;
    --red: #b42318;                  /* expired, 6.3:1 */
    --red-bg: #fde8e4;
    --red-bg-hover: #fbd9d2;
    --red-border: #f3c7bf;
    --blue: #2f5d8a;
    --blue-bg: #e4ecf5;
    --purple: var(--accent);         /* legacy name: keeps old two-stop gradients single-color */

    --border: #e8dcc6;               /* decorative dividers */
    --border-hover: #d9cbb2;
    --border-strong: #968873;        /* form controls, 3.3:1 (WCAG non-text) */

    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-xs: 4px;

    /* Typography */
    --font-sans: 'IBM Plex Sans Thai Looped', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

    /* Shadows — warm ink, kept subtle */
    --shadow-sm: 0 1px 2px rgba(43, 38, 34, 0.06);
    --shadow-md: 0 2px 8px rgba(43, 38, 34, 0.08);
    --shadow-lg: 0 8px 24px rgba(43, 38, 34, 0.12);
    --shadow-glow: none;

    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* =====================================================
   Layout
   ===================================================== */
/* No z-index here: a z-index would create a stacking context that traps
   .sidebar (z 100) below .sidebar-overlay (z 99, a sibling outside this box),
   so on mobile every tap on the open menu landed on the overlay and closed it. */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* =====================================================
   Sidebar
   ===================================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo-img {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: block;
}

.sidebar-logo-text h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-logo-text p {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0; top: 0;
    width: 3px;
    height: 100%;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
    transform: scaleY(0);
    transition: var(--transition);
}

.nav-item:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
}

.nav-item.active::before {
    transform: scaleY(1);
}

.nav-item-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item-badge {
    margin-left: auto;
    background: var(--red);
    color: var(--text-on-accent);
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font-mono);
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

.lang-toggle {
    display: flex;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    overflow: hidden;
}

.lang-btn {
    flex: 1;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
}

.lang-btn.active {
    background: var(--accent);
    color: var(--text-on-accent);
}

/* =====================================================
   Main Content
   ===================================================== */
/* Bottom padding reserves room for the fixed .btn-fab (56px + 28px offset + gap),
   so the last buttons on a page can always scroll clear of it */
.main-content {
    flex: 1;
    min-width: 0;   /* a flex item won't shrink below its widest child: the filter tabs would widen the page past a phone screen instead of scrolling */
    margin-left: var(--sidebar-width);
    padding: 32px 32px 112px;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h2 {
    font-size: 26px;
    font-weight: 600;   /* no negative letter-spacing: it crowds Thai vowels and tone marks */
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* =====================================================
   Cards
   ===================================================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

/* =====================================================
   Stats Grid
   ===================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 3px;
    background: var(--stat-color, var(--accent));
}

.stat-card-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

/* Monospace, tabular digits: counts line up and read like a printed label */
.stat-card-value {
    font-family: var(--font-mono);
    font-size: 32px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-card-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* =====================================================
   Item List
   ===================================================== */
.items-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-box::before {
    content: '🔍';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
}

.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.filter-tab {
    padding: 6px 14px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-xs);
    font-size: 13px;
    transition: var(--transition);
    white-space: nowrap;
}

.filter-tab.active {
    background: var(--accent);
    color: var(--text-on-accent);
}

.filter-tab:hover:not(.active) {
    background: var(--bg-glass-hover);
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.item-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.item-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

/* Category colors are user/seed data (often bright) — show them as a dot, keep text in ink */
.item-card-category {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-glass);
    color: var(--text-secondary);
}

.item-card-category::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cat-color, var(--accent));
    flex-shrink: 0;
}

.item-card-name {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
}

.item-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.item-card-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Expiry progress bar */
.expiry-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-glass);
    border-radius: 3px;
    margin-bottom: 10px;
    overflow: hidden;
}

.expiry-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.8s ease;
}

.item-card-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.item-card-buttons {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

/* Storage filter next to the status tabs */
.items-storage {
    width: auto;
    min-width: 140px;
}

/* "Opened" dialog: day presets */
.opened-item-name {
    font-weight: 600;
    margin-bottom: 12px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.chip {
    padding: 6px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-on-accent);
}

.opened-note {
    margin: -8px 0 16px;
}

/* =====================================================
   Shopping list
   ===================================================== */
.shop-card {
    max-width: 640px;
}

.shop-add {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.shop-add .form-input {
    flex: 1;
    min-width: 0;
}

.shop-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.shop-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.shop-row:last-child {
    border-bottom: none;
}

.shop-check {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.shop-check input {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.shop-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.shop-name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.shop-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.shop-row.is-bought .shop-meta {
    display: none;   /* room for "into the fridge"; the form gets category and storage anyway */
}

.shop-row.is-bought .shop-name {
    text-decoration: line-through;
    color: var(--text-muted);
    font-weight: 400;
}

.shop-remove,
.month-nav .btn-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--bg-glass);
    color: var(--text-secondary);
    cursor: pointer;
}

.shop-empty {
    padding: 24px 8px;
}

.shop-bought-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 20px;
    font-weight: 600;
}

/* =====================================================
   Monthly statistics
   ===================================================== */
.stats-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.month-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.month-nav .btn-icon {
    font-size: 20px;
}

.month-nav .btn-icon:disabled {
    opacity: 0.35;
    cursor: default;
}

.month-nav-label {
    min-width: 130px;
    text-align: center;
    font-weight: 600;
}

.stats-compare {
    font-weight: 600;
    margin: -12px 0 8px;
}

.stats-price-hint {
    margin: 0 0 16px;
}

.stats-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin: 16px 0 20px;
}

.stats-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.stats-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.stats-list li:last-child {
    border-bottom: none;
}

.stats-list-value {
    color: var(--text-secondary);
    white-space: nowrap;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-expired { background: var(--red-bg); color: var(--red); }
.status-today { background: var(--red-bg); color: var(--red); }
.status-urgent { background: var(--orange-bg); color: var(--orange); }
.status-warning { background: var(--yellow-bg); color: var(--yellow); }
.status-safe { background: var(--green-bg); color: var(--green); }

.item-card-actions {
    display: flex;
    gap: 6px;
}

.item-card-actions .btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--bg-glass);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.item-card-actions .btn-icon:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* =====================================================
   Buttons
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

/* Busy state set by withBusyButton() while a request is in flight */
.btn:disabled,
.btn-icon:disabled {
    opacity: 0.6;
    cursor: progress;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-on-accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-glass);
    border: 1px solid var(--border-hover);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid var(--red-border);
}

.btn-danger:hover {
    background: var(--red-bg-hover);
}

.btn-success {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid var(--green-border);
}

.btn-success:hover {
    background: var(--green-bg-hover);
}

.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

.btn-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--text-primary);   /* ink, so it stands apart from green in-page buttons */
    color: var(--bg-primary);
    font-size: 24px;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-fab:hover {
    transform: scale(1.1) rotate(90deg);
}

/* Hidden on the add-item page, where it would only duplicate the form's own submit button */
.btn-fab.is-hidden {
    display: none;
}

/* =====================================================
   Modal
   ===================================================== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.95);
    transition: var(--transition);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--red-bg);
    color: var(--red);
    border-color: var(--red);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* =====================================================
   Forms
   ===================================================== */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);   /* form controls need 3:1 to be findable */
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6158' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);   /* minmax(0,…) lets inputs shrink instead of overflowing */
    gap: 12px;
}

/* Item photo: picker in the form, thumbnails in lists, full-size viewer */
.item-photo-field {
    display: flex;
    align-items: center;
    gap: 14px;
}

.item-photo-preview {
    flex: 0 0 auto;
    width: 88px;
    height: 88px;
    padding: 0;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    font-size: 28px;
    cursor: pointer;
    overflow: hidden;
}

.item-photo-preview img,
.item-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.item-photo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.item-photo-actions .btn[hidden] {
    display: none;
}

.item-card-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.item-card-title .item-card-name {
    margin-bottom: 0;
    min-width: 0;
}

.item-thumb {
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    overflow: hidden;
    cursor: zoom-in;
}

.dash-thumb {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.photo-viewer {
    max-width: min(92vw, 720px);
    max-height: 92vh;
    padding: 12px;
    border: none;
    border-radius: var(--radius);
    background: var(--bg-card);
    text-align: center;
}

.photo-viewer::backdrop {
    background: var(--overlay);
}

.photo-viewer img {
    display: block;
    max-width: 100%;
    max-height: calc(92vh - 110px);
    margin: 0 auto;
    border-radius: var(--radius-sm);
}

.photo-viewer p {
    margin: 10px 0;
    font-weight: 600;
}

/* Two-option segmented control (radio inputs): expiry vs best-before */
.seg-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.seg-toggle label {
    position: relative;
    cursor: pointer;
}

.seg-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.seg-toggle span {
    display: block;
    padding: 10px 8px;
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    background: var(--bg-input);
}

.seg-toggle label + label span {
    border-left: 1px solid var(--border-strong);
}

.seg-toggle input:checked + span {
    background: var(--accent);
    color: var(--text-on-accent);
    font-weight: 600;
}

.seg-toggle input:focus-visible + span {
    outline: 2px solid var(--text-primary);   /* visible on both the white and the green option */
    outline-offset: -4px;
}

/* Notification settings: first alert as years / months / days, three boxes on one row even on phones */
.alert-ymd {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.alert-ymd-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-secondary);
}

.alert-ymd-box .form-input {
    text-align: center;
    font-size: 16px;   /* 16px stops iOS zooming in on focus */
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* iOS Safari keeps a native intrinsic width on date inputs and collapses them when empty */
input[type="date"].form-input {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    min-width: 0;
    min-height: 42px;
}

input[type="date"].form-input::-webkit-date-and-time-value {
    text-align: left;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Scanner action buttons in form */
.scan-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
}

.scan-actions .btn {
    flex: 1;
}

/* =====================================================
   Scanner & OCR
   ===================================================== */
.scanner-wrapper,
.ocr-wrapper {
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 16px;
}

.scanner-viewport {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--text-primary);
}

.scanner-viewport video {
    display: block;
    width: 100%;
    height: clamp(320px, 55vh, 520px);   /* tall enough for the zoom slider and corner buttons */
    object-fit: cover;
    transform-origin: center;
    transition: transform 0.15s ease;    /* digital zoom (scanner.js) */
    touch-action: none;                  /* pinch zooms the camera, not the page */
}

/* Round buttons over the preview: close (top-left), torch (top-right), switch camera (bottom-right) */
.scanner-ctrl {
    position: absolute;
    z-index: 1;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 250, 240, 0.35);
    background: rgba(43, 38, 34, 0.6);
    color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.scanner-ctrl[hidden] {
    display: none;
}

.scanner-close { top: 12px; left: 12px; }
.scanner-torch { top: 12px; right: 12px; }
.scanner-switch { bottom: 12px; right: 12px; }

.scanner-torch[aria-pressed="true"] {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Vertical zoom slider (left edge): a horizontal range rotated -90°, so max is at the top */
.scanner-zoom {
    position: absolute;
    z-index: 1;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    padding: 8px 0 10px;
    border-radius: 22px;
    background: rgba(43, 38, 34, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.scanner-zoom[hidden] {
    display: none;
}

.scanner-zoom-value {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--bg-primary);
}

.scanner-zoom-track {
    position: relative;
    width: 44px;
    height: 150px;
}

.scanner-zoom-slider {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 150px;
    height: 44px;   /* the rotated width = touch target */
    margin: 0;
    transform: translate(-50%, -50%) rotate(-90deg);
    accent-color: var(--bg-primary);
    cursor: pointer;
}

/* Aiming guide only — decoding uses the whole middle band of the frame, so it needn't be filled.
   Kept small on purpose: a big box pulls people inside the camera's minimum focus distance. */
.scanner-aim {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 60%;
    aspect-ratio: 2.2;
    transform: translate(-50%, -50%);
    border: 3px solid rgba(255, 250, 240, 0.9);
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(43, 38, 34, 0.35);
    pointer-events: none;
}

/* Expiry-date scanner: a wide, short box for a line or two of printed text */
.scanner-aim--text {
    width: 80%;
    aspect-ratio: 3.5;
}

.scanner-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-glass);
    font-size: 13px;
    color: var(--text-secondary);
}

.scanner-actions {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
    background: var(--bg-glass);
}

.scanner-actions .btn {
    flex: 1;
}

.scanner-pulse[hidden] {
    display: none;
}

.scanner-pulse {
    width: 10px;
    height: 10px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

.ocr-input-area {
    padding: 24px;
    text-align: center;
}

.ocr-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.ocr-upload-label:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.ocr-upload-icon { font-size: 40px; }
.ocr-upload-hint { font-size: 12px; color: var(--text-muted); }

.ocr-file-input { display: none; }

.ocr-preview {
    padding: 0 16px;
}

.ocr-preview-img {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.ocr-progress {
    padding: 16px;
}

.ocr-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.ocr-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

#ocr-progress-text {
    font-size: 12px;
    color: var(--text-secondary);
}

.ocr-result {
    padding: 16px;
}

.ocr-result-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

.ocr-dates-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.ocr-date-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-glass);
    border-radius: var(--radius-xs);
}

.ocr-date-icon { font-size: 18px; }
.ocr-date-label { font-size: 12px; color: var(--text-secondary); }
.ocr-date-value { font-weight: 600; font-size: 14px; flex: 1; }

.ocr-date-type {
    padding: 4px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-size: 12px;
}

.ocr-no-result {
    text-align: center;
    color: var(--text-muted);
    padding: 16px;
}

/* =====================================================
   Category Cards
   ===================================================== */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}

.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease;
    cursor: pointer;
}

.category-card:hover {
    border-color: var(--border-hover);
}

.category-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.category-info h4 {
    font-size: 15px;
    font-weight: 600;
}

.category-info p {
    font-size: 12px;
    color: var(--text-secondary);
}

.category-badge {
    margin-left: auto;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-glass);
    color: var(--text-secondary);
}

/* =====================================================
   Notification Log
   ===================================================== */
.notif-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notif-item {
    display: flex;
    flex-wrap: wrap;   /* a long status badge goes under the name instead of squeezing it */
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.notif-item:hover {
    background: var(--bg-glass-hover);
}

.notif-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.notif-icon.warning { background: var(--orange-bg); }
.notif-icon.expired { background: var(--red-bg); }
.notif-icon.summary { background: var(--blue-bg); }
.notif-icon.sent { background: var(--green-bg); }

.notif-content {
    flex: 1;
    min-width: 100px;   /* short badges ("3 days left") still fit beside the name on a 390px phone */
}

.notif-item > .status-badge {
    margin-left: auto;
}

.notif-message {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-time {
    font-size: 11px;
    color: var(--text-muted);
}

/* =====================================================
   Settings
   ===================================================== */
.settings-section {
    margin-bottom: 24px;
}

.settings-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-label {
    font-size: 14px;
}

.settings-value {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Toggle Switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0;
    right: 0; bottom: 0;
    background: var(--border-hover);   /* off-state track must stay visible on white cards */
    border-radius: 12px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: var(--text-on-accent);
}

/* =====================================================
   Toast Notifications
   ===================================================== */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    transform: translateX(120%);
    transition: var(--transition);
    min-width: 280px;
}

.toast-show { transform: translateX(0); }
.toast-hide { transform: translateX(120%); opacity: 0; }

.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-warning { border-left: 3px solid var(--yellow); }
.toast-info { border-left: 3px solid var(--blue); }

.toast-icon { font-size: 18px; }
.toast-message { flex: 1; }

.toast-action {
    flex-shrink: 0;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

/* =====================================================
   Empty State
   ===================================================== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state-text {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

/* =====================================================
   Loading Spinner
   ===================================================== */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 24px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    padding: 48px;
    color: var(--text-secondary);
}

/* =====================================================
   Animations
   ===================================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

/* =====================================================
   Scrollbar
   ===================================================== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =====================================================
   Mobile Hamburger
   ===================================================== */
.hamburger {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    z-index: 150;
    color: var(--text-primary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--overlay);
    z-index: 99;
}

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 768px) {
    .hamburger {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* The burger (fixed, z 150) stays on top of the open drawer as its close button —
       push the drawer header below it so the logo isn't covered */
    .sidebar-header {
        padding-top: 76px;
    }

    /* iOS zooms the page when focusing a field under 16px and doesn't zoom back,
       which makes inputs look like they spill out of their cards */
    .form-input,
    .form-select,
    .form-textarea,
    .search-box input {
        font-size: 16px;
    }

    .main-content {
        margin-left: 0;
        padding: 72px 16px 96px;   /* FAB here: 56px + 20px offset + gap */
    }

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

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

    .items-toolbar {
        flex-direction: column;
    }

    .filter-tabs,
    .items-storage {
        width: 100%;
        overflow-x: auto;
    }

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

    .btn-fab {
        bottom: 20px;
        right: 20px;
    }

    .modal {
        max-width: 100%;
        margin: 0 10px;
    }

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

@media (max-width: 480px) {
    /* Keep 2 columns on phones: 4 full-width cards pushed "expiring soon" below the fold */
    .stats-grid {
        gap: 10px;
        margin-bottom: 20px;
    }

    .stat-card {
        padding: 14px 16px;
    }

    .stat-card-icon {
        font-size: 22px;
        margin-bottom: 4px;
    }

    .stat-card-value {
        font-size: 26px;
    }

    .stat-card-label {
        font-size: 12px;
    }

    .page-header h2 {
        font-size: 20px;
    }

    .scan-actions {
        flex-direction: column;
    }
}

/* =====================================================
   Print Styles
   ===================================================== */
@media print {
    .sidebar, .hamburger, .btn-fab, .modal-overlay, #toast-container {
        display: none !important;
    }
    .main-content {
        margin-left: 0;
    }
    body {
        background: white;
        color: black;
    }
}
