/*
 * assets/css/main.css
 *
 * Base stylesheet shared by all portals. Portal-specific overrides
 * (if any) should live in assets/css/admin.css, portal.css, tech.css
 * and be loaded IN ADDITION to this file -- not as a replacement.
 * The goal: no more inline <style> blocks or copy-pasted CSS per page.
 *
 * THEMING: every color below is a CSS variable. The actual values here
 * are static fallbacks only (used if a page forgets to include the
 * brand style block, or before it runs). On real pages,
 * Branding::styleBlock() (see app/classes/Branding.php) is injected in
 * <head> AFTER this file and overrides these per-customer, computed
 * from one BRAND_PRIMARY hex value in .env. [data-theme="dark"] /
 * [data-theme="light"] on <html> (set by theme-init, before first
 * paint) picks which set applies.
 */

:root {
    --color-bg: #0f172a;
    --color-surface: #1a2337;
    --color-surface-2: #212c44;
    --color-border: #303b54;
    --color-text: #eef0f4;
    --color-muted: #9aa4b8;
    --color-accent: #2563eb;
    --color-accent-hover: #4f7ff0;
    --color-accent-contrast: #ffffff;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 12px 32px rgba(0, 0, 0, 0.28);
    --radius: 10px;
}

[data-theme="light"] {
    --color-bg: #f1f5f9;
    --color-surface: #ffffff;
    --color-surface-2: #eef1f8;
    --color-border: #dde1ea;
    --color-text: #0f172a;
    --color-muted: #64748b;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4fc4;
    --color-accent-contrast: #ffffff;
    --shadow-card: 0 1px 2px rgba(20, 24, 40, 0.05), 0 12px 32px rgba(20, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html {
    /* Stop iOS Safari auto-bumping text size in landscape/zoomed states,
       which otherwise fights with the fixed rem sizing used throughout. */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    transition: background-color 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--color-accent); }

h1, h2, h3 { font-weight: 600; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.btn {
    display: inline-block;
    min-height: 44px;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, filter 0.15s ease, transform 0.05s ease;
}

.btn:hover { background: var(--color-accent-hover); }
.btn:active { transform: translateY(1px); }

.btn-block { display: block; width: 100%; }

.auth-subtext {
    font-size: 0.85rem;
    color: var(--color-muted);
    margin: -0.5rem 0 1rem;
}

.btn-link {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--color-muted);
    font-size: 0.85rem;
    text-decoration: underline;
    cursor: pointer;
    padding: 0.4rem 0;
}
.btn-link:hover { color: var(--color-text); }

.field { margin-bottom: 1rem; }

.field label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--color-muted);
}

.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="time"],
.field input[type="tel"],
.field input[type="search"],
.field select,
.field textarea {
    width: 100%;
    /* 16px minimum is deliberate, not just "1rem happens to be 16" —
       iOS Safari auto-zooms the page on focus for any input below 16px,
       which is jarring on a login form. Don't let this drift smaller. */
    font-size: max(1rem, 16px);
    padding: 0.7rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea {
    resize: vertical;
    min-height: 4.5em;
}

/* File inputs aren't included in the shared selector list above since
   the browser's native "Choose File" button can't be restyled with
   ordinary properties -- it's a pseudo-element the browser renders
   inside the input, so it needs its own rule targeting that button
   specifically (::file-selector-button is the standard name; the
   -webkit- one is the same thing for older Safari/Chrome). */
.field input[type="file"] {
    width: 100%;
    display: flex;
    align-items: center;
    min-height: 2.9rem;
    padding: 0.4rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-muted);
    font-family: inherit;
    font-size: 0.85rem;
}
.field input[type="file"]::file-selector-button,
.field input[type="file"]::-webkit-file-upload-button {
    margin-right: 0.75rem;
    min-height: 2rem;
    padding: 0 1rem;
    border: 0;
    border-radius: 6px;
    background: var(--color-accent);
    color: var(--color-accent-contrast, #fff);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}
.field input[type="file"]:hover::file-selector-button,
.field input[type="file"]:hover::-webkit-file-upload-button {
    background: var(--color-accent-hover);
}
.field input[type="file"]:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 25%, transparent);
}

.field select {
    appearance: none;
    -webkit-appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-muted) 50%),
        linear-gradient(135deg, var(--color-muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) center, calc(100% - 12px) center;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 2rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 25%, transparent);
}

/* ---- Auth pages (admin/tech/portal login) ---- */

.auth-page {
    /* 100vh includes mobile browser chrome (address/tab bars), which
       shrinks/grows on scroll and can clip the card or leave a jumpy
       gap. svh/dvh track the *actual* visible viewport instead; vh
       stays as a fallback for older WebViews. */
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(1.5rem + env(safe-area-inset-top)) calc(1.25rem + env(safe-area-inset-right))
             calc(1.5rem + env(safe-area-inset-bottom)) calc(1.25rem + env(safe-area-inset-left));
    background:
        radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--color-accent) 16%, transparent), transparent 45%),
        radial-gradient(circle at 85% 90%, color-mix(in srgb, var(--color-accent) 10%, transparent), transparent 45%),
        var(--color-bg);
}

.auth-shell {
    width: 100%;
    max-width: 400px;
}

/* Small phones (SE/mini and similar ~360-390px wide): tighter card
   padding so content doesn't feel cramped against the edges, and a
   slightly smaller logo so it doesn't dominate a short viewport. */
@media (max-width: 380px) {
    .auth-card { padding: 1.5rem 1.25rem; }
    .brand-logo { max-height: 44px; }
}

/* Short viewports (landscape phones, or keyboard open on a small
   screen): drop the vertical centering so the card sticks to the top
   and the page scrolls normally instead of squeezing the form. */
@media (max-height: 560px) {
    .auth-page { align-items: flex-start; padding-top: calc(1.25rem + env(safe-area-inset-top)); }
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 1.5rem;
}

.brand-logo {
    max-height: 56px;
    max-width: 240px;
    width: auto;
    object-fit: contain;
}

.brand-logo--text {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--color-text);
}

.auth-tagline {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: var(--color-muted);
    font-style: italic;
}

.auth-card {
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 2rem 1.75rem;
}

.auth-card h1 {
    font-size: 1.25rem;
    margin: 0 0 1.35rem;
    text-align: center;
}

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.8rem;
    color: var(--color-muted);
}

.auth-footer-link {
    text-align: center;
    margin-top: 1.1rem;
    font-size: 0.9rem;
}

.auth-footer-link a {
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.auth-footer-link a:hover {
    color: var(--color-accent-hover);
}

.alert-error {
    background: color-mix(in srgb, #d9534f 15%, transparent);
    border: 1px solid #d9534f;
    color: #f5a6a3;
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

[data-theme="light"] .alert-error {
    color: #b3261e;
    background: color-mix(in srgb, #d9534f 10%, transparent);
}

.alert-error-compact {
    display: inline-block;
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
}

.alert-success {
    background: color-mix(in srgb, var(--status-ok, #22c55e) 15%, transparent);
    border: 1px solid var(--status-ok, #22c55e);
    color: var(--status-ok, #22c55e);
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* ---- Theme toggle ---- */

.theme-toggle {
    position: fixed;
    top: calc(0.75rem + env(safe-area-inset-top));
    right: calc(0.75rem + env(safe-area-inset-right));
    z-index: 60;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    box-shadow: var(--shadow-card);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover { border-color: var(--color-accent); }
.theme-toggle:active { transform: translateY(1px); }

.theme-toggle svg {
    width: 18px;
    height: 18px;
    display: block;
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ---- Accent color picker (sits left of the theme toggle) ---- */

.accent-picker {
    position: fixed;
    top: calc(0.75rem + env(safe-area-inset-top));
    right: calc(3.5rem + env(safe-area-inset-right));
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    box-shadow: var(--shadow-card);
}

.accent-swatch {
    width: 18px;
    height: 18px;
    padding: 0;
    border-radius: 999px;
    border: 2px solid transparent;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.accent-swatch:hover { border-color: var(--color-border); }
.accent-swatch[aria-pressed="true"] { border-color: var(--color-text); }