/*
 * theme.css
 *
 * Shared SafeForest design overlay. Conservative on purpose: only touches
 * typography, spacing, soft shadows, focus rings, scrollbars, transitions,
 * and reusable design tokens. Does NOT redefine widths/heights/positions
 * of existing layout-critical elements, so it can be added on top of any
 * page without disturbing the inline-styled markup.
 *
 * Sizing units — the SafeForest dashboards target desktops only (FHD↔4K)
 * and rely on viewport-relative sizing so layouts scale fluidly. This file
 * follows the same rule: every spacing/radius/shadow/focus-ring value is
 * expressed in em (font-size relative), vw (viewport-width relative), or
 * % (parent relative). The only place `px` survives is as the universal
 * fallback unit for the pill border-radius (9999px ≡ "as round as it
 * gets") and for hairline 1-pixel borders, where sub-pixel values would
 * disappear on standard-DPR displays.
 *
 * Loaded *after* every other stylesheet on the page so its rules win. The
 * dark-mode stylesheet (newpaineldarkmode.css) is loaded after this and
 * overrides our --sf-* tokens for dark mode automatically.
 *
 * To remove: run scripts/revert_theme.ps1 (or .sh) to strip the <link>
 * tag from each template (templates were backed up to
 * templates/.theme-backup/ before the tag was added).
 */

/* ─── Design tokens (light mode defaults) ───────────────────────────── */
:root {
    /* Color palette */
    --sf-accent: #5d8aa8;
    --sf-accent-strong: #4a7795;
    --sf-accent-soft: rgba(93, 138, 168, 0.15);
    --sf-fg: #1a202c;
    --sf-fg-muted: #4a5568;
    --sf-fg-subtle: #718096;
    --sf-bg: #f5f7fa;
    --sf-surface: #ffffff;
    --sf-surface-2: #f8fafc;
    --sf-border: rgba(15, 23, 42, 0.10);
    --sf-border-strong: rgba(15, 23, 42, 0.18);
    --sf-success: #16a34a;
    --sf-warn: #d97706;
    --sf-danger: #dc2626;

    /* Spacing scale — em-based so they ride along with the inherited
     * vw font-size that pages set globally. Use them via var() in new
     * components; existing pages are unaffected. */
    --sf-space-1: 0.25em;
    --sf-space-2: 0.5em;
    --sf-space-3: 0.75em;
    --sf-space-4: 1em;
    --sf-space-5: 1.5em;
    --sf-space-6: 2em;
    --sf-space-7: 3em;

    /* Typography scale */
    --sf-font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    --sf-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --sf-line-tight: 1.25;
    --sf-line-normal: 1.5;
    --sf-line-relaxed: 1.7;
    --sf-weight-regular: 400;
    --sf-weight-medium: 500;
    --sf-weight-semibold: 600;
    --sf-weight-bold: 700;

    /* Radii — em-relative so corners scale with the element font-size. */
    --sf-radius-sm: 0.4em;
    --sf-radius-md: 0.65em;
    --sf-radius-lg: 0.9em;
    --sf-radius-pill: 9999px;     /* sentinel "max radius" — must stay px */

    /* Shadows — offsets/blurs in em so they scale with font-size and the
     * inherited vw sizing the project uses page-wide. */
    --sf-shadow-xs: 0 0.07em 0.15em rgba(15, 23, 42, 0.06);
    --sf-shadow-sm: 0 0.07em 0.22em rgba(15, 23, 42, 0.08), 0 0.07em 0.15em rgba(15, 23, 42, 0.04);
    --sf-shadow-md: 0 0.30em 0.90em rgba(15, 23, 42, 0.10), 0 0.15em 0.30em rgba(15, 23, 42, 0.06);
    --sf-shadow-lg: 0 0.85em 2.00em rgba(15, 23, 42, 0.14), 0 0.30em 0.55em rgba(15, 23, 42, 0.06);
    --sf-shadow-focus: 0 0 0 0.22em rgba(93, 138, 168, 0.35);

    /* Transitions */
    --sf-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --sf-dur-fast: 120ms;
    --sf-dur-base: 200ms;
    --sf-dur-slow: 320ms;
}

/* When dark mode is active (newpaineldarkmode.css enables this stylesheet)
 * we want our tokens to flip too. newpaineldarkmode.css loads *after* this
 * file, so it can override our --sf-* tokens via :root rules. We expose a
 * dark fallback here using prefers-color-scheme so a page that loads this
 * file *without* the dark mode stylesheet still picks up dark theming when
 * the OS prefers it. */
@media (prefers-color-scheme: dark) {
    :root {
        --sf-fg: #e6edf3;
        --sf-fg-muted: #a3aab4;
        --sf-fg-subtle: #768292;
        --sf-bg: #0f172a;
        --sf-surface: #1a2332;
        --sf-surface-2: #222e3c;
        --sf-border: rgba(148, 163, 184, 0.18);
        --sf-border-strong: rgba(148, 163, 184, 0.30);
    }
}

/* ─── Global reset / smoothing (additive only) ──────────────────────── */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--sf-font-sans);
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Headings — leave global font-size and color to per-page CSS, just
 * normalise weight + spacing so Hx elements look intentional. */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--sf-font-sans);
    font-weight: var(--sf-weight-semibold);
    line-height: var(--sf-line-tight);
    letter-spacing: -0.01em;
}

/* Code-like content */
code, kbd, pre, samp {
    font-family: var(--sf-font-mono);
    font-size: 0.9em;
}

/* Links */
a {
    color: var(--sf-accent);
    text-decoration: none;
    transition: color var(--sf-dur-fast) var(--sf-ease);
}
a:hover { color: var(--sf-accent-strong); text-decoration: underline; }
a:focus-visible {
    outline: none;
    box-shadow: var(--sf-shadow-focus);
    border-radius: var(--sf-radius-sm);
}

/* ─── Form controls — gentle polish, no width/position changes ────── */
input:not([type="range"]):not([type="color"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
    transition: border-color var(--sf-dur-fast) var(--sf-ease),
                box-shadow   var(--sf-dur-fast) var(--sf-ease),
                background-color var(--sf-dur-fast) var(--sf-ease);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
    outline: none;
    box-shadow: var(--sf-shadow-focus);
}

/* ─── Buttons — universal smooth hover/active without forcing colors ─ */
button,
.btn,
input[type="button"],
input[type="submit"],
input[type="reset"] {
    transition: transform   var(--sf-dur-fast) var(--sf-ease),
                box-shadow  var(--sf-dur-base) var(--sf-ease),
                background-color var(--sf-dur-fast) var(--sf-ease),
                color       var(--sf-dur-fast) var(--sf-ease),
                opacity     var(--sf-dur-fast) var(--sf-ease);
    will-change: transform;
}
button:hover,
.btn:hover,
input[type="button"]:hover,
input[type="submit"]:hover,
input[type="reset"]:hover { transform: translateY(-0.07em); }
button:active,
.btn:active,
input[type="button"]:active,
input[type="submit"]:active,
input[type="reset"]:active { transform: translateY(0); }
button:disabled,
.btn:disabled,
input[type="button"]:disabled,
input[type="submit"]:disabled,
input[type="reset"]:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* Smart UI buttons — match the rest of the system */
smart-button {
    transition: transform   var(--sf-dur-fast) var(--sf-ease),
                box-shadow  var(--sf-dur-base) var(--sf-ease),
                background-color var(--sf-dur-fast) var(--sf-ease) !important;
}
smart-button:hover { transform: translateY(-0.07em); }

/* ─── Bootstrap card polish (only when .card is used) ───────────────── */
.card {
    border: 1px solid var(--sf-border);
    border-radius: var(--sf-radius-md);
    box-shadow: var(--sf-shadow-sm);
    transition: box-shadow var(--sf-dur-base) var(--sf-ease);
}
.card:hover { box-shadow: var(--sf-shadow-md); }

/* ─── Tables — readable rows, soft separators ───────────────────────── */
table {
    border-collapse: separate;
    border-spacing: 0;
}
table th {
    font-weight: var(--sf-weight-semibold);
    letter-spacing: 0.02em;
    text-transform: none;
}

/* ─── Modals — soft backdrop + lifted panel ─────────────────────────── */
.modal-content {
    border: 1px solid var(--sf-border);
    border-radius: var(--sf-radius-lg);
    box-shadow: var(--sf-shadow-lg);
}
.modal-backdrop.show { opacity: 0.45; }

/* ─── Scrollbars — subtle, modern, theme-aware ──────────────────────── */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(127, 127, 127, 0.45) transparent;
}
*::-webkit-scrollbar { width: 0.6vw; height: 0.6vw; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background-color: rgba(127, 127, 127, 0.45);
    border-radius: var(--sf-radius-pill);
    border: 0.15em solid transparent;
    background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: rgba(127, 127, 127, 0.65); }

/* ─── Selection ─────────────────────────────────────────────────────── */
::selection { background: var(--sf-accent-soft); color: inherit; }

/* ─── Reduced motion respect ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ─── Optional reusable utility classes (pages can opt in) ──────────── */
.sf-card {
    background: var(--sf-surface);
    color: var(--sf-fg);
    border: 1px solid var(--sf-border);
    border-radius: var(--sf-radius-lg);
    box-shadow: var(--sf-shadow-sm);
    padding: var(--sf-space-5);
}
.sf-card:hover { box-shadow: var(--sf-shadow-md); }

.sf-stack-2 > * + * { margin-top: var(--sf-space-2); }
.sf-stack-3 > * + * { margin-top: var(--sf-space-3); }
.sf-stack-4 > * + * { margin-top: var(--sf-space-4); }
.sf-stack-5 > * + * { margin-top: var(--sf-space-5); }

.sf-muted   { color: var(--sf-fg-muted) !important; }
.sf-subtle  { color: var(--sf-fg-subtle) !important; }

/* Subtle background gradient helper — opt in via .sf-bg-gradient */
.sf-bg-gradient {
    background-image:
        radial-gradient(circle at 0% 0%, var(--sf-accent-soft) 0%, transparent 35%),
        radial-gradient(circle at 100% 0%, rgba(0, 0, 0, 0.04) 0%, transparent 40%);
}
