/**
 * DEKS Unified Design System — Peregrine GeoServices palette, light register.
 *
 * THE ONE TOKEN SOURCE. Every DEKS page links this file from
 * /shared/static/css/deks.css, which both the container and each module mount
 * (deks_ui.mount_shared_static). Nine modules used to paste a copy of the token
 * block into their own <style>; those copies are gone. Change a value here and
 * it changes everywhere — that is the entire point.
 *
 * PALETTE: Peregrine GeoServices brand kit
 * (Peregrine_GeoServices_Brand_Kit.pptx), transcribed verbatim below. The
 * company brand is the platform's brand. Source of truth and the derived
 * light-band values: peregrine-geoservices-site/docs/style-decision.md.
 *
 *   Basalt        #191C1D   authority, depth        -> ink
 *   Survey White  #F3F1EA   clarity, space         -> the page ground
 *   Mineral Blue  #1769A8   information, direction -> interactive primary
 *   Field Green   #58A85D   growth, environment    -> success / live data
 *   Signal Ochre  #E7A640   attention, signal      -> the scarce accent
 *   Iron Grey     #777B78   structure, support     -> rules, quiet labels
 *
 * TWO DELIBERATE DEPARTURES FROM THE KIT, both recorded in
 * docs/specs/design-system-unification.md:
 *
 * 1. The kit's page is DARK (Basalt ground). DEKS is light — the owner retired
 *    light-text-on-dark on 2026-09-16 — so this applies the kit's own light
 *    band, which it defines for long-form reading, as the whole register.
 * 2. The kit makes Signal Ochre the button colour, "nothing else, deliberately".
 *    That holds for a page with two CTAs. An app has hundreds of buttons, and
 *    in DEKS amber already means *attention* and marks the FID gate — so
 *    Mineral Blue is the interactive primary and ochre stays scarce.
 *
 * CONTRAST IS MEASURED, NOT ASSUMED. Every value used for text below carries
 * its WCAG ratio against Survey White. The kit's own warning holds: raw Signal
 * Ochre (1.87:1) and raw Iron Grey (3.80:1) are NOT body text — use the text
 * variants.
 *
 * Not yet applied from the kit, because each is a change of shape rather than
 * colour: radius 2px ("effectively square"), the Archivo display face, and the
 * IBM Plex Mono annotation layer. Tracked in the spec.
 */

/* ============================================================================
   Brand layer — the kit's six, verbatim. Nothing below invents a colour.
   ============================================================================ */

:root {
    --basalt: #191c1d;
    --survey-white: #f3f1ea;
    --mineral-blue: #1769a8;
    --field-green: #58a85d;
    --signal-ochre: #e7a640;
    --iron-grey: #777b78;

    /* ------------------------------------------------------------------
       Applied roles. The --deks-* names are unchanged from the blue/grey
       system they replace, because ~200 var(--deks-*) references across the
       modules read them; only the values moved.
       ------------------------------------------------------------------ */

    /* Interactive — Mineral Blue. 600 is the kit value (5.13:1 on Survey
       White, 5.80:1 on white), so it is legible as text, not only as a fill. */
    --deks-primary: #1769a8;
    --deks-primary-dark: #155c92;   /* 6.24:1 — hover, active, link-on-light */
    --deks-primary-hover: #155c92;
    --deks-primary-light: #eaf1f7;  /* tint for active rows and panels */

    /* Status. Each is the TEXT-legible value, because the badge/alert pattern
       paints these on their own light tint. */
    --deks-success: #2f7a34;        /* 4.70:1 — kit's Field Green text value */
    --deks-success-light: #e9f4ea;
    --deks-warning: #8a5a12;        /* 5.23:1 — kit's Signal Ochre text value */
    --deks-warning-light: #fcf3e6;
    --deks-error: #dc2626;          /* 4.83:1 — outside the kit; it has no red */
    --deks-error-light: #fef2f2;
    --deks-info: #1769a8;           /* information is Mineral Blue's own role */
    --deks-info-light: #eaf1f7;

    /* The scarce accent. Ochre FILLS at full strength with Basalt ink on top;
       ochre WORDS use --deks-accent-text. Never small ochre text on light. */
    --deks-accent: #e7a640;
    --deks-accent-ink: #191c1d;
    --deks-accent-dim: #b8791f;     /* hover on a light band */
    --deks-accent-text: #8a5a12;    /* 5.23:1 */

    /* Neutrals, warm — Survey White through Basalt rather than a cool grey
       ramp, so panels sit in the brand's own light band. */
    --deks-gray-50: #f3f1ea;        /* Survey White — the page ground */
    --deks-gray-100: #eae7de;       /* sunken panel, hover fill */
    --deks-gray-200: #dad6cb;       /* hairline on Survey White */
    --deks-gray-300: #c0c2c0;       /* control borders, disabled edges */
    --deks-gray-400: #8f9390;       /* placeholder, decorative only */
    --deks-gray-500: #777b78;       /* Iron Grey — 3.80:1, NOT body text */
    --deks-gray-600: #5c605e;       /* 5.65:1 — the muted text value */
    --deks-gray-700: #494b4c;       /* secondary text */
    --deks-gray-800: #313435;
    --deks-gray-900: #191c1d;       /* Basalt — body ink, 15.17:1 */

    /* Surfaces. Cards stay white against the Survey White ground: an app runs
       dense tables and needs the extra separation a marketing page does not. */
    --deks-surface: #ffffff;
    --deks-surface-sunken: #eae7de;

    /* Layout */
    --deks-sidebar-width: 16rem;
    --deks-header-height: 4rem;

    /* Motion — the kit's 180ms. */
    --deks-transition-fast: 180ms cubic-bezier(.2, .7, .3, 1);
    --deks-transition-normal: 180ms cubic-bezier(.2, .7, .3, 1);
}

/* ============================================================================
   HTMX Indicators
   ============================================================================ */

.htmx-indicator {
    opacity: 0;
    transition: opacity var(--deks-transition-normal);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.htmx-swapping {
    opacity: 0;
    transition: opacity 100ms ease-out;
}

/* ============================================================================
   Navigation Links (Sidebar)
   ============================================================================ */

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    color: var(--deks-gray-700);
    border-radius: 0.5rem;
    transition: background-color var(--deks-transition-fast),
                color var(--deks-transition-fast);
    text-decoration: none;
}

.nav-link:hover {
    background-color: var(--deks-gray-100);
}

.nav-link.active {
    background-color: var(--deks-primary-light);
    color: var(--deks-primary-dark);
    font-weight: 500;
}

.nav-link svg {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

/* Section headers in sidebar */
.nav-section {
    padding: 1rem 1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--deks-gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    transition: all var(--deks-transition-fast);
    cursor: pointer;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--deks-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--deks-primary-dark);
}

.btn-secondary {
    background-color: var(--deks-gray-100);
    color: var(--deks-gray-700);
    border: 1px solid var(--deks-gray-300);
}

.btn-secondary:hover {
    background-color: var(--deks-gray-200);
}

/* The kit's accent button: ochre fill, Basalt ink. Scarce by instruction —
   one per view, for the action the page exists to get. */
.btn-accent {
    background-color: var(--deks-accent);
    color: var(--deks-accent-ink);
    font-weight: 600;
}

.btn-accent:hover {
    background-color: var(--deks-accent-dim);
}

.btn-success {
    background-color: var(--field-green);
    color: var(--basalt);
}

.btn-success:hover {
    background-color: #48884d;
}

.btn-danger {
    background-color: var(--deks-error);
    color: white;
}

.btn-danger:hover {
    background-color: #b91c1c;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* ============================================================================
   Cards
   ============================================================================ */

.card {
    background-color: var(--deks-surface);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgb(25 28 29 / 0.08), 0 1px 2px -1px rgb(25 28 29 / 0.08);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--deks-gray-200);
    font-weight: 600;
    color: var(--deks-gray-900);
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--deks-gray-200);
    background-color: var(--deks-gray-50);
}

/* ============================================================================
   Status Badges
   ============================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

.badge-success {
    background-color: var(--deks-success-light);
    color: var(--deks-success);
}

.badge-warning {
    background-color: var(--deks-warning-light);
    color: var(--deks-warning);
}

.badge-error {
    background-color: var(--deks-error-light);
    color: var(--deks-error);
}

.badge-info {
    background-color: var(--deks-info-light);
    color: var(--deks-info);
}

.badge-neutral {
    background-color: var(--deks-gray-100);
    color: var(--deks-gray-700);
}

/* ============================================================================
   Tables
   ============================================================================ */

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table thead {
    background-color: var(--deks-gray-50);
}

.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--deks-gray-700);
    border-bottom: 1px solid var(--deks-gray-200);
    white-space: nowrap;
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--deks-gray-200);
    color: var(--deks-gray-900);
}

.data-table tbody tr:hover {
    background-color: var(--deks-gray-50);
}

/* ============================================================================
   Forms
   ============================================================================ */

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--deks-gray-700);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--deks-gray-300);
    border-radius: 0.375rem;
    background-color: var(--deks-surface);
    color: var(--deks-gray-900);
    transition: border-color var(--deks-transition-fast),
                box-shadow var(--deks-transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--deks-primary);
    box-shadow: 0 0 0 3px rgb(23 105 168 / 0.15);
}

.form-input::placeholder {
    color: var(--deks-gray-400);
}

.form-help {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--deks-gray-600);
}

.form-error {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--deks-error);
}

/* ============================================================================
   Alerts / Notifications
   ============================================================================ */

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: var(--deks-success-light);
    border-color: var(--field-green);
    color: #285f2c;
}

.alert-warning {
    background-color: var(--deks-warning-light);
    border-color: var(--deks-accent);
    color: var(--deks-accent-text);
}

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

.alert-info {
    background-color: var(--deks-info-light);
    border-color: var(--deks-primary);
    color: var(--deks-primary-dark);
}

/* ============================================================================
   Stats Cards (Dashboard)
   ============================================================================ */

.stat-card {
    background-color: var(--deks-surface);
    border-radius: 0.5rem;
    padding: 1.5rem;
    border: 1px solid var(--deks-gray-200);
}

.stat-card .stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card .stat-icon svg {
    width: 1.5rem;
    height: 1.5rem;
}

.stat-card .stat-label {
    font-size: 0.875rem;
    color: var(--deks-gray-600);
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--deks-gray-900);
    font-variant-numeric: tabular-nums;
}

/* ============================================================================
   Modal / Dialog
   ============================================================================ */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgb(25 28 29 / 0.5);
    z-index: 40;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--deks-surface);
    border-radius: 0.5rem;
    box-shadow: 0 25px 50px -12px rgb(25 28 29 / 0.25);
    max-width: 32rem;
    width: 90%;
    max-height: 90vh;
    overflow: auto;
    z-index: 50;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--deks-gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--deks-gray-900);
}

.modal-close {
    color: var(--deks-gray-500);
    padding: 0.25rem;
    border-radius: 0.25rem;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--deks-gray-700);
    background-color: var(--deks-gray-100);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--deks-gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============================================================================
   Loading Spinner
   ============================================================================ */

.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--deks-gray-200);
    border-top-color: var(--deks-primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.spinner-sm {
    width: 1rem;
    height: 1rem;
}

.spinner-lg {
    width: 2rem;
    height: 2rem;
    border-width: 3px;
}

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

/* ============================================================================
   Utility Classes
   ============================================================================ */

.text-primary { color: var(--deks-primary); }
.text-success { color: var(--deks-success); }
.text-warning { color: var(--deks-warning); }
.text-error { color: var(--deks-error); }
.text-info { color: var(--deks-info); }
.text-muted { color: var(--deks-gray-600); }
.text-accent { color: var(--deks-accent-text); }

.bg-primary { background-color: var(--deks-primary); }
.bg-success { background-color: var(--deks-success); }
.bg-warning { background-color: var(--deks-warning); }
.bg-error { background-color: var(--deks-error); }
.bg-info { background-color: var(--deks-info); }
.bg-accent { background-color: var(--deks-accent); }

/* Scrollbar styling */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: var(--deks-gray-100);
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--deks-gray-300);
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--deks-gray-400);
}

/* Truncate text */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Screen reader only */
.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;
}

/* ============================================================================
   Contextual Help Widget
   ============================================================================ */

.deks-help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 4px;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    color: var(--deks-gray-600);
    background: var(--deks-gray-100);
    border: 1px solid var(--deks-gray-300);
    border-radius: 50%;
    cursor: pointer;
    vertical-align: middle;
    transition: all var(--deks-transition-fast);
    flex-shrink: 0;
}

.deks-help-icon:hover {
    color: var(--deks-primary);
    border-color: var(--deks-primary);
    background: var(--deks-primary-light);
}

.deks-help-popover {
    position: absolute;
    z-index: 9999;
    max-width: 300px;
    min-width: 200px;
    background: var(--deks-surface);
    border: 1px solid var(--deks-gray-200);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgb(25 28 29 / 0.12), 0 1px 4px rgb(25 28 29 / 0.08);
    opacity: 0;
    transition: opacity var(--deks-transition-fast);
    pointer-events: none;
}

.deks-help-popover.deks-help-popover-visible {
    opacity: 1;
    pointer-events: auto;
}

.deks-help-popover-title {
    padding: 8px 12px 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--deks-primary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.deks-help-popover-body {
    padding: 4px 12px 8px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--deks-gray-700);
}

.deks-help-popover-footer {
    padding: 6px 12px 8px;
    border-top: 1px solid var(--deks-gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.deks-help-popover-see-also {
    font-size: 11px;
    color: var(--deks-gray-600);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deks-help-popover-link {
    font-size: 11px;
    color: var(--deks-primary);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.deks-help-popover-link:hover {
    text-decoration: underline;
}

/* ============================================================================
   Mobile Responsive Overrides
   ============================================================================ */

/* Minimum touch targets on mobile (44px per WCAG) */
@media (max-width: 767px) {
    .nav-link {
        min-height: 44px;
        padding: 0.625rem 1rem;
    }
    .btn, button, a.btn {
        min-height: 44px;
    }
    .btn-sm {
        min-height: 36px;
        padding: 0.375rem 0.75rem;
    }
}

/* Hide scrollbar but allow scroll on admin nav */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Admin nav scroll fade hint */
@media (max-width: 767px) {
    .admin-scroll-fade {
        position: relative;
    }
    .admin-scroll-fade::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 2rem;
        background: linear-gradient(to right, transparent, var(--deks-surface));
        pointer-events: none;
    }
}

/* Bottom nav safe area for notched phones */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Activity glow — pulsing ring for running tasks */
@keyframes activity-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgb(23 105 168 / 0.5); }
    50% { box-shadow: 0 0 0 6px rgb(23 105 168 / 0); }
}
@keyframes activity-dot-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.85); }
}
.activity-glow {
    animation: activity-pulse 2s ease-in-out infinite;
}
.activity-dot {
    animation: activity-dot-pulse 1.5s ease-in-out infinite;
}

/* ============================================================================
   Skeleton loading placeholders
   ============================================================================ */

@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(90deg,
        var(--deks-gray-100) 25%,
        var(--deks-gray-200) 50%,
        var(--deks-gray-100) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 0.375rem;
}
.skeleton-text {
    height: 0.875rem;
    margin-bottom: 0.5rem;
}
.skeleton-text:last-child {
    width: 60%;
}
.skeleton-heading {
    height: 1.25rem;
    width: 40%;
    margin-bottom: 0.75rem;
}
.skeleton-card {
    height: 5rem;
    border-radius: 0.75rem;
}
.skeleton-circle {
    border-radius: 9999px;
}
