/* ==========================================================================
   Dagamis theme layer: semantic tokens, light / dark / system, and contrast
   fixes. Loaded last on every themed page (injected by includes/security_boot.php).
   The palette itself lives in style.css (:root and :root[data-theme="dark"]);
   these tokens are names for what a color is FOR, so new code can use them.
   ========================================================================== */

:root {
    color-scheme: light;

    /* Semantic tokens (light) */
    --bg:              var(--cream);
    --bg-elevated:     var(--surface-2);
    --surface-hover:   #F7F1E8;
    --text:            var(--ink);
    --accent:          var(--brown-dark);
    --accent-contrast: #FFFFFF;
    --accent-hover:    var(--brown-mid);
    --shadow:          var(--shadow-sm);
    --overlay:         rgba(42, 30, 20, 0.55);
    --focus-ring:      var(--focus);
    --divider:         var(--border);
    --placeholder:     #8A7A6C;
    --selection-bg:    rgba(122, 90, 58, 0.22);
    --scrollbar-thumb: rgba(43, 31, 23, 0.28);
    --scrollbar-track: transparent;
    --badge-bg:        linear-gradient(180deg, #DC2626, #C62828);
    --badge-text:      #FFFFFF;
    --muted-btn-bg:    #7E6449;
    --chrome-text-muted: rgba(255, 255, 255, 0.62);
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg:              var(--cream);
    --bg-elevated:     var(--surface-2);
    --surface-hover:   #2A2019;
    --text:            var(--ink);
    --accent:          var(--gold);
    --accent-contrast: #1E1712;
    --accent-hover:    #E6DCCB;
    --overlay:         rgba(0, 0, 0, 0.62);
    --placeholder:     #9C8B78;
    --selection-bg:    rgba(217, 207, 188, 0.30);
    --scrollbar-thumb: rgba(240, 230, 214, 0.22);
    --badge-bg:        linear-gradient(180deg, #D42B2B, #B91C1C);
    --muted-btn-bg:    #7E6449;
    --chrome-text-muted: rgba(240, 230, 214, 0.62);
}

/* Native controls, scrollbars, selection, placeholders */
html { scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); }
::selection { background: var(--selection-bg); color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--placeholder); opacity: 1; }
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.85); }

/* Smooth change between themes: background and color only, and only while switching */
html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
    transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease, fill 180ms ease, stroke 180ms ease !important;
}
@media (prefers-reduced-motion: reduce) {
    html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after { transition: none !important; }
}

/* ---- Contrast fixes (both modes) ------------------------------------- */

/* Red count badges: white on #F25555 / #EF4444 was 3.4:1 */
.nav-count,
.notif-badge,
.notif-badge:not(.notif-btn .notif-badge),
.needs-bar-num,
.stat-chip-alert { background: var(--badge-bg); color: var(--badge-text); }

/* Footer fine print on the walnut footer was 4.0:1 */
.footer-copy,
.footer-logo-copy small { color: var(--chrome-text-muted); }

/* Muted brown button: white on #B89A78 was 2.7:1 */
.add-btn--muted { background: var(--muted-btn-bg); color: #FFFFFF; }
.add-btn--muted:hover { background: var(--brown-mid); }

/* "For your info" counts were faded to 2.9:1 */
.staff-attention-item.is-fyi .staff-attention-count { opacity: 1; }

/* POS "From" label and the audit stat on its dark card */
.product-price-col .price-from { opacity: 1; color: var(--text-muted); }
.today-stat-num { color: var(--gold); }

/* ---- Dark mode: leftovers that were hard-coded light ------------------ */

:root[data-theme="dark"] .shop-v2 .card-badge { color: var(--on-gold); }
:root[data-theme="dark"] .rp-later { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
:root[data-theme="dark"] .rp-later:hover { background: var(--surface-hover); }

/* Receipt status pills, when shown in staff lists (receipt pages themselves stay light) */
:root[data-theme="dark"] .rcp-status--unpaid     { background: var(--danger-bg); color: var(--danger-ink); }
:root[data-theme="dark"] .rcp-status--deposit    { background: var(--warn-bg);   color: var(--warn-ink); }
:root[data-theme="dark"] .rcp-status--fully_paid { background: var(--ok-bg);     color: var(--ok-ink); }

/* Cream call-to-action buttons on the dark navbar / hero keep enough contrast */
:root[data-theme="dark"] :is(nav.navbar .btn-signup, .vh-card-btn, .bs-btn:not(.is-ghost), .vh-arrow.is-next) { color: #2B1F17; }

/* ---- Theme switch ---------------------------------------------------- */

.theme-switch { position: relative; display: inline-flex; }
.theme-switch .theme-toggle .icon { width: 18px; height: 18px; }
.theme-menu {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 1000;
    min-width: 168px; padding: 6px; margin: 0; list-style: none;
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.theme-menu[hidden] { display: none; }
.theme-switch--float { position: fixed; left: 18px; bottom: 18px; z-index: 900; }
.theme-switch--float .theme-toggle--float { position: static; }
.theme-switch--float .theme-menu { top: auto; bottom: calc(100% + 8px); left: 0; right: auto; }
.theme-option {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 10px; border: 0; border-radius: 8px; background: transparent;
    color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer;
}
.theme-option .icon { width: 17px; height: 17px; flex-shrink: 0; color: var(--text-muted); }
.theme-option:hover { background: var(--surface-hover); }
.theme-option[aria-checked="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.theme-option[aria-checked="true"] .icon { color: currentColor; }
.theme-option:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 1px; }

/* Sidebar: Light / Dark / System as one segmented row, same place as the old toggle */
.theme-seg {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
    margin: 4px 0 6px; padding: 3px; border-radius: 10px;
    background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.theme-seg .theme-option {
    justify-content: center; gap: 6px; padding: 7px 4px; font-size: 12px; color: var(--text-muted);
}
.theme-seg .theme-option .icon { width: 15px; height: 15px; }
.theme-seg .theme-option[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-xs); }

/* Soft status fills used by inline styles (payment check box, checkout notes) */
:root { --ok-bg-soft: #ECFDF5; --warn-bg-soft: #EEE8DB; --warn-line-strong: #FCD34D; --note-bg: #FEF9C3; --note-line: #D9CFBC; }
:root[data-theme="dark"] { --ok-bg-soft: var(--ok-bg); --warn-bg-soft: var(--warn-bg); --warn-line-strong: var(--warn-line); --note-bg: var(--warn-bg); --note-line: var(--warn-line); }

/* Page-level styles that hard-code light fills or borders */
:root[data-theme="dark"] :is(.btn-activate, .btn-restock, .btn-mini-restock):hover { background: rgba(16, 185, 129, 0.28); }
:root[data-theme="dark"] .confirmed-icon { background: var(--ok-bg); }
:root[data-theme="dark"] .feed-dot { border-color: var(--surface); }
:root[data-theme="dark"] :is(.settings-warn, .cd-bal--now .cd-bal-head) { border-color: var(--border); }
:root[data-theme="dark"] :is(.quote-panel, .stock-choice, .inq-chip-action, .order-card.is-new, .new-pill, .pay-scan.is-warn, .callout-warn, .confirm-sheet-chip.is-stock) { border-color: var(--warn-line); }
:root[data-theme="dark"] :is(.callout-stock) { border-color: rgba(251, 146, 60, 0.38); }
:root[data-theme="dark"] :is(#qtyStockNote.is-alert, .confirm-sheet-chip.is-mto, .confirm-sheet-step.is-done) { border-color: var(--border); }
:root[data-theme="dark"] .dl-tab--today { border-color: var(--ok-line); }
:root[data-theme="dark"] .pref-schedule-card.is-required { border-color: var(--warn-line); }

/* Worker task list: completed cards were faded below 4.5:1; keep them quieter with color, not opacity */
.task-card.completed { opacity: 1; }
.task-card.completed :is(.task-card-sub, .task-specs-label, .tc-steps li) { color: var(--text-muted); }
.tc-due small { opacity: 1; }
.tc-steps li.done span { color: #FFFFFF; }

/* ---------- Phone helpers (2026-11-03 review) ---------- */

/* Sideways-scrolling tab rows: fade the edge that still has more tabs. */
@media (max-width: 760px) {
    .tab-bar.has-more-right, .status-tabs.has-more-right {
        -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
                mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
    }
    .tab-bar.has-more-left.has-more-right, .status-tabs.has-more-left.has-more-right {
        -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent);
                mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent);
    }
    .tab-bar.has-more-left:not(.has-more-right), .status-tabs.has-more-left:not(.has-more-right) {
        -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px);
                mask-image: linear-gradient(90deg, transparent, #000 36px);
    }
}

/* Online Orders on phones: compact cards, "Details" opens the rest (assets/js/order-cards.js). */
.oc-compact-bar { display: none; }
@media (max-width: 640px) {
    .oc-compact-on .oc-compact-bar {
        display: flex; align-items: center; justify-content: space-between; gap: 10px;
        padding: 10px 18px; border-top: 1px solid var(--divider, var(--border));
    }
    .oc-compact-sum { font-weight: 700; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .oc-compact-toggle {
        flex: 0 0 auto; min-height: 36px; padding: 6px 14px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 700;
        border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
    }
    .oc-compact-toggle:hover { background: var(--surface-hover); }
    .oc-compact-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
    .oc-compact-on :is(.order-card, .ocard)[data-compact]:not(.oc-open) > :is(.order-card-body, .ocard-body) { display: none; }
}

/* Sign-out dialogs: "Stay signed in" reads clearly in light and dark mode */
.customer-logout-cancel,
.staff-logout-actions .btn-cancel {
    background: var(--bg-elevated) !important;
    color: var(--text) !important;
    border: 1px solid var(--divider) !important;
    font-weight: 600;
    opacity: 1 !important;
}
.customer-logout-cancel:hover,
.staff-logout-actions .btn-cancel:hover {
    background: var(--surface-hover) !important;
}

/* Signing out: the page fades to the background color before the login page loads,
   so the old customer or staff screen does not flash on the way out. */
html.is-signing-out body > * {
    opacity: 0;
    transition: opacity 0.22s ease;
}
html.is-signing-out { cursor: progress; }
@media (prefers-reduced-motion: reduce) {
    html.is-signing-out body > * { transition: none; }
}

/* Staff sidebar: hide / show on wide screens, in the style of the Claude app.
   One plain icon button stays top-left in both states; a hint with the shortcut
   appears on hover or keyboard focus. Colors come from the theme tokens, so it
   matches light, dark and system mode. (Button and Ctrl+B: staff-nav.js) */
.staff-nav-collapse { display: none; }
@media (min-width: 769px) {
    .staff-nav-collapse {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 20px;
        left: 14px;
        z-index: 2300;
        width: 34px;
        height: 34px;
        padding: 0;
        border: 0;
        border-radius: 9px;
        background: transparent;
        color: var(--text-muted);
        cursor: pointer;
        transition: background 0.15s ease, color 0.15s ease;
    }
    .staff-nav-collapse:hover {
        background: color-mix(in srgb, var(--text) 8%, transparent);
        color: var(--text);
    }
    .staff-nav-collapse:active { background: color-mix(in srgb, var(--text) 12%, transparent); }
    .staff-nav-collapse:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; color: var(--text); }
    .staff-nav-collapse svg { display: block; }
    /* Stay above the page-loading placeholder (z-index 3500) while a slow page loads */
    html.dg-loading .staff-nav-collapse { z-index: 3600; }

    /* Hint below the button: "Hide sidebar  Ctrl+B" */
    .staff-nav-tip {
        position: absolute;
        top: calc(100% + 6px);
        left: 0;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 5px 8px;
        border-radius: 7px;
        background: var(--ink);
        color: var(--cream);
        font: 500 12px/1.2 'Inter', sans-serif;
        white-space: nowrap;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
        opacity: 0;
        transform: translateY(-3px);
        pointer-events: none;
        transition: opacity 0.12s ease, transform 0.12s ease;
    }
    .staff-nav-tip kbd {
        font: 500 11px/1 'Inter', sans-serif;
        color: inherit;
        opacity: 0.65;
        background: none;
        border: 0;
        padding: 0;
    }
    .staff-nav-collapse:hover .staff-nav-tip,
    .staff-nav-collapse:focus-visible .staff-nav-tip {
        opacity: 1;
        transform: none;
        transition-delay: 0.35s;
    }

    /* Room for the button in front of the logo */
    .sidebar-logo { padding-left: 54px !important; }

    /* Like the Claude app: the logo row, the search and the account area stay put;
       only the menu list in the middle scrolls. */
    aside.sidebar { overflow: hidden; }
    aside.sidebar .sidebar-logo,
    aside.sidebar .sidebar-search,
    aside.sidebar .sidebar-foot { flex: none; }
    aside.sidebar .sidebar-nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
        padding-bottom: 8px;
    }
    aside.sidebar .sidebar-nav,
    aside.sidebar .sidebar-search,
    aside.sidebar .sidebar-foot,
    aside.sidebar .sidebar-logo > :not(.sidebar-logo-mark) {
        transition: opacity 0.18s ease 0.1s;
    }
    .main-content {
        transition: margin-left 0.3s cubic-bezier(0.22, 1, 0.36, 1), padding-left 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    }

    /* Hidden, like the Claude app: the sidebar slides away completely and only
       the sidebar icon stays in the top-left corner, on the page background. */
    aside.sidebar { transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0s; }
    html.staff-nav-hidden aside.sidebar {
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0.3s;
    }
    html.staff-nav-hidden .main-content { margin-left: 0 !important; padding-left: 64px; }
}
@media (min-width: 769px) and (prefers-reduced-motion: reduce) {
    .sidebar, .main-content, .staff-nav-collapse, .staff-nav-tip { transition: none !important; }
}
@media print { .staff-nav-collapse { display: none !important; } }

/* Admin menu sections as dropdowns (staff-nav.js) */
aside.sidebar .sidebar-nav .nav-group[role="button"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 10px 12px 4px;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
}
aside.sidebar .sidebar-nav .nav-group[role="button"]:first-child { margin-top: 4px; }
aside.sidebar .sidebar-nav .nav-group[role="button"]:hover {
    background: color-mix(in srgb, var(--text) 5%, transparent);
    color: var(--text);
}
aside.sidebar .sidebar-nav .nav-group[role="button"]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
aside.sidebar .sidebar-nav .nav-group-chevron {
    flex: none;
    opacity: 0.7;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
aside.sidebar .sidebar-nav .nav-group.is-folded .nav-group-chevron { transform: rotate(-90deg); }
aside.sidebar .sidebar-nav .nav-group.has-waiting::after {
    content: "";
    width: 7px;
    height: 7px;
    margin-left: auto;
    border-radius: 50%;
    background: var(--badge-bg);
    order: 1;
}
aside.sidebar .sidebar-nav .nav-group.has-waiting .nav-group-chevron { order: 2; }
aside.sidebar .sidebar-nav a.nav-folded { display: none; }
aside.sidebar .sidebar-nav.is-searching a.nav-folded:not([hidden]) { display: flex; }
aside.sidebar .sidebar-nav a.nav-unfolding { animation: dagamis-nav-unfold 0.24s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes dagamis-nav-unfold {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    aside.sidebar .sidebar-nav a.nav-unfolding { animation: none; }
    aside.sidebar .sidebar-nav .nav-group-chevron { transition: none; }
}

/* Page changes: keep the sidebar button pinned on top, exactly where it is. Without
   this, the sidebar's cross-page snapshot is drawn over it and it seems to reload. */
@supports (view-transition-name: none) {
    .staff-nav-collapse { view-transition-name: dagamis-nav-toggle; }
    ::view-transition-group(dagamis-nav-toggle) {
        animation: none !important;
        z-index: 1002;
    }
    ::view-transition-old(dagamis-nav-toggle) { display: none; }
    ::view-transition-new(dagamis-nav-toggle) { animation: none !important; opacity: 1 !important; }
}

/* ---------- Text alignment (2026-11-03) ----------
   1. Wide screens: every block on a staff page starts at the same left edge.
      Before, notes and pagers kept their own margins (so they sat further left)
      and tab rows were centered while everything else was left-aligned. */
@media (min-width: 1700px) {
    html body .main-content > * {
        margin-left: max(0px, calc((100% - var(--content-max)) / 2));
        margin-right: max(0px, calc((100% - var(--content-max)) / 2));
    }
}
/* 2. Label / value rows: line the text up on one baseline, even when the value is bigger (totals). */
.info-row, .ocard-row { align-items: baseline; }
.info-row .icon-text, .ocard-row .icon-text { display: inline-flex; align-items: center; align-self: center; }
/* 3. Contact details read as a list: values sit next to their labels instead of far right,
      where they looked like they belonged to the next column. Money stays right-aligned. */
.info-list-left .info-row, .info-list-left .ocard-row { justify-content: flex-start; gap: 12px; }
.info-list-left .info-row > span:first-child, .info-list-left .ocard-row > span:first-child { flex: 0 0 116px; }
.info-list-left .info-row > span:last-child, .info-list-left .ocard-row > span:last-child { text-align: left !important; max-width: none !important; min-width: 0; font-size: 13px !important; }
/* 4. Search boxes wide enough for their hint text. */
@media (min-width: 769px) { .toolbar > .search-input { flex: 1 1 320px; max-width: 520px; } }
.staff-split-note { background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn-ink) 22%, transparent); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; margin-top: 0; margin-bottom: 16px; font-size: 13px; line-height: 1.5; }
.toolbar .search-input { min-width: min(100%, 260px); }
/* A hint that still does not fit ends in "…" instead of being cut mid-letter. */
input[placeholder] { text-overflow: ellipsis; }
/* Notes with bold words or links inside: keep the sentence as normal flowing text
   (as a flex box every bold word became its own block with gaps around it). */
.role-note { display: block; position: relative; padding-left: 38px; }
.role-note > .icon:first-child { position: absolute; left: 14px; top: 12px; margin: 0; }
/* Page titles: the short description sits under the title, not far away on the right. */
.page-header:has(> h1 + p):not(:has(> a, > button, > form, > div)),
.inq-head { display: block; }
.page-header:has(> h1 + p):not(:has(> a, > button, > form, > div)) > p,
.inq-head > p { margin-top: 6px; }
/* Audit log on a phone: the event-type tiles form an even grid instead of ragged rows. */
@media (max-width: 600px) {
    .summary-strip { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .summary-strip .sum-chip { min-width: 0; }
}
/* Filter rows: dropdowns a little narrower so the Search button stays on the same row. */
@media (min-width: 769px) { .toolbar .filter-select { min-width: 150px; } .toolbar-left > form { flex: 1 1 auto; min-width: 0; } }
