/* ==========================================================================
   GoneFinder Design Tokens — single source of truth (civic blue)
   --------------------------------------------------------------------------
   Every page loads this file, and every other stylesheet reads from it.

   Cascade, registry (index.html):
       styles.css        base + legacy palette
       gf-app.css        merged legacy component layers
   ->  design-tokens.css THIS FILE
       gf-ui.css         token-native UI layer, edited day to day

   Cascade, document pages (help / privacy / terms / security / use policy):
   ->  design-tokens.css THIS FILE
       gf-page.css

   Cascade, sign-in and dashboards:
       admin-styles.css  (+ styles.css on login.html)
   ->  design-tokens.css THIS FILE

   gf-ui.css and gf-page.css deliberately sit after this file: they consume the
   tokens and are allowed to override the legacy component rules underneath.
   Nothing above is deleted; this file supplies the values they resolve to.

   Themes:
   - Light is the default (:root).
   - Dark applies automatically via prefers-color-scheme when the page has
     no explicit [data-theme] attribute, and explicitly via [data-theme="dark"]
     (set on <html> by the theme toggles). [data-theme="light"] always stays light.
   ========================================================================== */

:root {
    /* ----- Brand: one deep civic blue (USWDS-derived) ----- */
    --primary-50:  #eff6fb;
    --primary-100: #d9e8f6;
    --primary-200: #aacdec;
    --primary-300: #73b3e7;
    --primary-400: #2378c3;
    --primary-600: #005ea2;   /* white text = 6.7:1, passes AA */
    --primary-700: #1a4480;
    --primary-800: #162e51;

    /* Legacy trust palette -> same blue */
    --trust-50:  #eff6fb;
    --trust-100: #d9e8f6;
    --trust-200: #aacdec;
    --trust-600: #005ea2;
    --trust-700: #1a4480;

    /* professional-theme.css raw refs — repaired to AA-safe values */
    --gov-blue-60: #005ea2;
    --gov-blue-70: #1a4480;
    --gov-green-60: #15803d;  /* was #00a91c: white text failed at 2.9:1 */
    --gov-green-70: #166534;
    --gov-orange-60: #b45309; /* was #fa9441: white text failed */

    /* ----- Status semantics (the ONLY red/green in the UI) ----- */
    --success-600: #15803d;   /* white = 5.0:1 (NOT #16a34a which fails) */
    --success-700: #166534;
    --error-600:   #dc2626;   /* white = 4.8:1 */
    --error-700:   #b91c1c;
    --warning-600: #b45309;

    /* Solid badge fills: constant across themes (sit on photos/maps) */
    --gf-solid-stolen:    #dc2626;
    --gf-solid-recovered: #15803d;

    /* Soft badge pairs (text on tint — all AA) */
    --gf-danger-soft-bg:  #fee2e2;  --gf-danger-soft-fg:  #991b1b;
    --gf-success-soft-bg: #dcfce7;  --gf-success-soft-fg: #166534;
    --gf-warning-soft-bg: #fef3c7;  --gf-warning-soft-fg: #92400e;
    --gf-info-soft-bg:    #e0f2fe;  --gf-info-soft-fg:    #075985;

    /* ----- Action color for filled buttons (AA in BOTH themes) ----- */
    --gf-action:        #005ea2;
    --gf-action-hover:  #1a4480;
    --gf-action-active: #162e51;

    /* ----- Surfaces & text (slate neutrals, single ramp) ----- */
    --gf-bg-page: #f1f5f9;    /* flat — replaces the orange body gradient */
    --bg-primary:   #ffffff;  /* surface */
    --bg-secondary: #f8fafc;  /* subtle  */
    --bg-tertiary:  #f1f5f9;
    --text-primary:   #0f172a;
    --text-secondary: #334155;
    --text-muted:     #475569; /* 7.5:1 on white */
    --border-primary:   #e2e8f0;
    --border-secondary: #cbd5e1;

    /* ----- Type ----- */
    /* One stack everywhere. admin-styles.css declares --font-sans without
       Inter, which left login.html and the dashboards on a different face
       to the registry; redefining it here repairs that for every page. */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --gf-font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Courier New', monospace;

    /* ----- Spacing (4px grid — names match legacy) ----- */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* ----- Radius scale ----- */
    --gf-radius-sm: 6px;    /* chips, small badges */
    --gf-radius-md: 8px;    /* buttons, inputs */
    --gf-radius-lg: 12px;   /* cards, popups */
    --gf-radius-xl: 16px;   /* modals, map frame */
    --gf-radius-full: 999px;

    /* ----- Elevation ----- */
    --gf-shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06);
    --gf-shadow-2: 0 2px 8px -2px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
    --gf-shadow-3: 0 16px 40px -12px rgba(15, 23, 42, 0.22);
    --gf-ring: 0 0 0 3px rgba(0, 94, 162, 0.30);

    /* ----- Z scale (for new components; legacy left untouched) ----- */
    --gf-z-nav: 1000;
    --gf-z-dropdown: 1200;
    --gf-z-overlay: 2000;
    --gf-z-modal: 2010;
    --gf-z-toast: 2100;

    /* ----- Motion ----- */
    --gf-ease: cubic-bezier(0.2, 0.6, 0.3, 1);
    --gf-dur-fast: 120ms;
    --gf-dur-normal: 200ms;
}

/* --------------------------------------------------------------------------
   Dark theme values (shared by the automatic and the explicit paths)
   -------------------------------------------------------------------------- */
[data-theme="dark"] {
    --primary-50:  #12253c;
    --primary-100: #173156;
    --primary-200: #1e3e6d;
    --primary-300: #2e5288;
    --primary-400: #4f97d1;
    --primary-600: #73b3e7;  /* accent/link on dark bg = 7.9:1 */
    --primary-700: #a4cdf0;
    --primary-800: #d3e4f5;

    --trust-50:  #12253c;
    --trust-100: #173156;
    --trust-200: #1e3e6d;
    --trust-600: #73b3e7;
    --trust-700: #a4cdf0;

    --success-600: #4ade80;
    --success-700: #86efac;
    --error-600:   #f87171;
    --error-700:   #fca5a5;
    --warning-600: #fbbf24;

    --gf-danger-soft-bg:  #450a0a;  --gf-danger-soft-fg:  #fecaca;
    --gf-success-soft-bg: #052e16;  --gf-success-soft-fg: #bbf7d0;
    --gf-warning-soft-bg: #451a03;  --gf-warning-soft-fg: #fde68a;
    --gf-info-soft-bg:    #082f49;  --gf-info-soft-fg:    #bae6fd;

    --gf-bg-page: #0b1220;
    --bg-primary:   #111a2e;
    --bg-secondary: #1e293b;
    --bg-tertiary:  #334155;
    --text-primary:   #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted:     #94a3b8;
    --border-primary:   #28344a;
    --border-secondary: #3b4a63;

    --gf-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.40);
    --gf-shadow-2: 0 2px 8px -2px rgba(0, 0, 0, 0.55);
    --gf-shadow-3: 0 16px 40px -12px rgba(0, 0, 0, 0.70);
    --gf-ring: 0 0 0 3px rgba(115, 179, 231, 0.40);
}

/* Automatic dark for OS preference when the page hasn't set a theme yet
   (explicit [data-theme="light"] always wins and stays light). */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) {
        --primary-50:  #12253c;
        --primary-100: #173156;
        --primary-200: #1e3e6d;
        --primary-300: #2e5288;
        --primary-400: #4f97d1;
        --primary-600: #73b3e7;
        --primary-700: #a4cdf0;
        --primary-800: #d3e4f5;

        --trust-50:  #12253c;
        --trust-100: #173156;
        --trust-200: #1e3e6d;
        --trust-600: #73b3e7;
        --trust-700: #a4cdf0;

        --success-600: #4ade80;
        --success-700: #86efac;
        --error-600:   #f87171;
        --error-700:   #fca5a5;
        --warning-600: #fbbf24;

        --gf-danger-soft-bg:  #450a0a;  --gf-danger-soft-fg:  #fecaca;
        --gf-success-soft-bg: #052e16;  --gf-success-soft-fg: #bbf7d0;
        --gf-warning-soft-bg: #451a03;  --gf-warning-soft-fg: #fde68a;
        --gf-info-soft-bg:    #082f49;  --gf-info-soft-fg:    #bae6fd;

        --gf-bg-page: #0b1220;
        --bg-primary:   #111a2e;
        --bg-secondary: #1e293b;
        --bg-tertiary:  #334155;
        --text-primary:   #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted:     #94a3b8;
        --border-primary:   #28344a;
        --border-secondary: #3b4a63;

        --gf-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.40);
        --gf-shadow-2: 0 2px 8px -2px rgba(0, 0, 0, 0.55);
        --gf-shadow-3: 0 16px 40px -12px rgba(0, 0, 0, 0.70);
        --gf-ring: 0 0 0 3px rgba(115, 179, 231, 0.40);
    }
}

/* ==========================================================================
   Base repairs
   ========================================================================== */

/* Kill the orange (and dark-slate) body gradients without editing styles.css */
body {
    background: var(--gf-bg-page) !important;
}

/* The fixed navbar paints over this banner, leaving dead space. Hide it. */
.security-banner {
    display: none !important;
}

/* Consistent, visible keyboard focus everywhere */
:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

/* Complete reduced-motion coverage on every page */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   Hero — fixes the invisible light-mode headline
   (white background-clip text was kept while the hero went light)
   ========================================================================== */
.hero {
    min-height: auto;
    padding: var(--space-12) var(--space-6) var(--space-8);
    color: var(--text-primary);
    background: linear-gradient(180deg, var(--bg-primary) 0%, var(--gf-bg-page) 100%);
    border-bottom: 1px solid var(--border-primary);
}

.hero::before {
    display: none; /* floating-dot animation */
}

.hero-title,
[data-theme="dark"] .hero-title {
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    -webkit-text-fill-color: currentColor;
    color: var(--text-primary);
    text-shadow: none;
    font-weight: 700;
    font-size: clamp(1.875rem, 4vw, 2.75rem);
}

.hero-title::after {
    display: none; /* white underline flourish, invisible on light */
}

.hero-gradient,
[data-theme="dark"] .hero-gradient {
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    -webkit-text-fill-color: currentColor;
    color: var(--primary-600);
    text-shadow: none;
}

.hero-subtitle {
    color: var(--text-secondary);
    opacity: 1;
    text-shadow: none;
    font-size: 1.125rem;
}

/* Quiet, honest trust line */
.trust-indicators {
    gap: var(--space-3);
}

.trust-badge {
    background: transparent !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-secondary) !important;
    box-shadow: none !important;
    font-weight: 500;
    font-size: 0.8125rem;
}

.trust-badge i {
    color: var(--success-600) !important;
}

@media (max-width: 640px) {
    .hero {
        padding: var(--space-8) var(--space-4) var(--space-6);
    }
}

/* ==========================================================================
   Buttons — one calm system
   ========================================================================== */
.btn {
    border-radius: var(--gf-radius-md);
    font-weight: 600;
}

.btn:hover,
.btn:focus {
    transform: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary,
.btn-primary:focus,
[data-theme="dark"] .btn-primary {
    background: var(--gf-action);
    border-color: var(--gf-action);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled),
[data-theme="dark"] .btn-primary:hover:not(:disabled) {
    background: var(--gf-action-hover);
    border-color: var(--gf-action-hover);
    color: #ffffff;
    transform: none;
    box-shadow: var(--gf-shadow-1);
}

.btn-secondary,
[data-theme="dark"] .btn-secondary {
    background: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    color: var(--text-secondary);
}

.btn-secondary:hover:not(:disabled),
[data-theme="dark"] .btn-secondary:hover:not(:disabled) {
    background: var(--bg-secondary);
    border-color: var(--border-secondary);
    color: var(--text-primary);
    transform: none;
}

/* Counter the legacy dark-mode per-button !important text patches, which
   assumed light-orange fills. Filled buttons are #005ea2 in both themes now. */
[data-theme="dark"] .solve-case-btn,
[data-theme="dark"] .solve-case-btn:hover:not(:disabled),
[data-theme="dark"] .solve-case-btn i {
    color: #ffffff !important;
}

[data-theme="dark"] #reset-form-btn,
[data-theme="dark"] #reset-form-btn:hover:not(:disabled),
[data-theme="dark"] #reset-form-btn i,
[data-theme="dark"] #reset-map-filter,
[data-theme="dark"] #reset-map-filter:hover:not(:disabled),
[data-theme="dark"] #reset-map-filter i {
    color: var(--text-primary) !important;
}

/* ==========================================================================
   Inputs — one shape, no jitter
   ========================================================================== */
.form-input,
.form-select,
.form-textarea,
input[type="text"],
input[type="email"],
input[type="date"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
select,
textarea {
    border-radius: var(--gf-radius-md);
}

input:focus,
select:focus,
textarea:focus {
    transform: none !important;
}

/* Prevent iOS zoom on the map date inputs */
@media (max-width: 640px) {
    input[type="date"],
    .date-input {
        font-size: 16px;
    }
}

/* ==========================================================================
   Item cards — calm surface + the (previously missing) status badge
   ========================================================================== */
.item-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--gf-radius-lg);
    box-shadow: var(--gf-shadow-1);
}

.item-card:hover {
    transform: none;
    box-shadow: var(--gf-shadow-2);
    border-color: var(--primary-200);
}

.item-card:hover .serial-number {
    animation: none;
    background: var(--primary-100);
}

.item-card.status-recovered,
[data-theme="dark"] .item-card.status-recovered {
    border: 1px solid var(--success-600);
    background: var(--bg-primary);
}

.item-image-container {
    position: relative;
}

/* Solid status badge overlaid on the card photo (rendered by script.js) */
.item-card-status {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: var(--gf-radius-sm);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #ffffff;
    background: var(--gf-solid-stolen);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.35);
    pointer-events: none;
}

.item-card-status i {
    font-size: 10px;
}

.item-card-status--recovered {
    background: var(--gf-solid-recovered);
}

.item-card-status--stolen {
    background: var(--gf-solid-stolen);
}

/* One mono stack for identifiers */
.item-card .serial-number span,
.item-detail-value.serial-number span {
    font-family: var(--gf-font-mono);
}

/* ==========================================================================
   Status badges & chips — AA solid fills everywhere
   (#16a34a and orange fills failed contrast with white text)
   ========================================================================== */
.status-badge.stolen,
[data-theme="dark"] .status-badge.stolen {
    background: var(--gf-solid-stolen);
    box-shadow: none;
}

.status-badge.recovered,
[data-theme="dark"] .status-badge.recovered {
    background: var(--gf-solid-recovered);
    box-shadow: none;
}

.status-stolen {
    background: var(--gf-solid-stolen);
    color: #ffffff;
}

.status-recovered {
    background: var(--gf-solid-recovered);
    color: #ffffff;
}

/* ==========================================================================
   End-of-list + loading chrome (replaces the gutted "celebration" block)
   ========================================================================== */
.all-items-loaded {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-muted);
}

.all-items-loaded .end-state-icon {
    font-size: 1.5rem;
    color: var(--success-600);
    margin-bottom: var(--space-2);
}

.all-items-loaded .end-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.all-items-loaded .end-state-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.items-loaded-counter {
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: 1px solid var(--border-primary);
    box-shadow: none;
}

.scroll-progress-bar {
    background: var(--primary-600);
}

/* ==========================================================================
   Map — first-class treatment (clusters on brand, dark tiles)
   ========================================================================== */
.main-map {
    border: 1px solid var(--border-primary);
    border-radius: var(--gf-radius-xl);
    box-shadow: var(--gf-shadow-1);
}

@media (min-width: 769px) {
    .main-map {
        height: clamp(400px, 62vh, 680px);
    }
}

@media (max-width: 768px) {
    .main-map {
        height: 52vh;
        min-height: 320px;
    }
}

/* Brand the marker clusters (default plugin CSS ships lime/yellow/orange) */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(0, 94, 162, 0.25) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background-color: var(--gf-action) !important;
    color: #ffffff !important;
    font-family: 'Inter', -apple-system, sans-serif !important;
    font-weight: 600 !important;
}

/* Legend swatches use the same two status colors as everything else */
.legend-marker.stolen {
    background: var(--gf-solid-stolen);
}

.legend-marker.recovered {
    background: var(--gf-solid-recovered);
}

/* Dark map tiles (standard no-API filter trick) */
[data-theme="dark"] .leaflet-tile {
    filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7);
}

[data-theme="dark"] .leaflet-container {
    background: var(--gf-bg-page);
}

/* ==========================================================================
   Toasts — clear of the mobile nav, inside safe areas
   ========================================================================== */
.toast-container {
    max-width: min(400px, calc(100vw - 32px));
}

@media (max-width: 768px) {
    .toast-container {
        top: auto !important;
        bottom: calc(var(--space-4) + env(safe-area-inset-bottom)) !important;
        right: var(--space-4) !important;
        left: var(--space-4) !important;
        max-width: none;
    }
}

/* ==========================================================================
   Admin & superadmin dashboards — unified with the app
   ========================================================================== */

/* Tables were overflow:hidden and crushed on small screens: scroll instead */
.table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .table-container .table {
        min-width: 640px;
    }
}

.table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Superadmin: retire the purple third palette; keep touch targets sane */
.superadmin-header,
[data-theme="dark"] .superadmin-header {
    background: linear-gradient(135deg, var(--gf-action-active) 0%, var(--gf-action) 100%);
    color: #ffffff;
}

.btn-sm {
    min-height: 36px;
}

.edit-item-btn {
    background: var(--gf-action) !important;
    color: #ffffff !important;
}

.edit-item-btn:hover {
    background: var(--gf-action-hover) !important;
    transform: none !important;
    box-shadow: var(--gf-shadow-1) !important;
}

.delete-item-btn {
    background: var(--gf-solid-stolen) !important;
    color: #ffffff !important;
}

.delete-item-btn:hover {
    background: #b91c1c !important;
    transform: none !important;
    box-shadow: var(--gf-shadow-1) !important;
}

.audit-entry {
    border-left-color: var(--primary-600) !important;
}

.selected-count {
    background: var(--gf-action) !important;
}

/* ==========================================================================
   Push-notification toggle (injected into the navbar when logged in)
   ========================================================================== */
.push-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border-primary);
    border-radius: var(--gf-radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--gf-dur-fast) var(--gf-ease),
                color var(--gf-dur-fast) var(--gf-ease),
                border-color var(--gf-dur-fast) var(--gf-ease);
}

.push-toggle-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.push-toggle-btn[aria-pressed="true"] {
    color: var(--primary-600);
    border-color: var(--primary-200);
    background: var(--primary-50);
}

.push-toggle-btn[disabled] {
    opacity: 0.6;
    cursor: wait;
}

@media (max-width: 768px) {
    .push-toggle-btn .push-label {
        display: none;
    }

    .push-toggle-btn {
        min-width: 40px;
        justify-content: center;
        padding: 8px;
    }
}

/* Screen-reader-only helper (used by the injected search label) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
