/* ==========================================================================
   Theme tokens + app shell.
   Dark by default; a light theme could be added later by redefining these
   variables under another selector.
   ========================================================================== */
:root {
    color-scheme: dark;

    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --surface-3: #262b36;
    --border: #2a2f3a;
    --border-strong: #3a4150;

    --text: #e6e8ee;
    --text-muted: #9aa3b2;
    --text-faint: #6b7385;

    --accent: #22d3ee;
    --accent-hover: #67e8f9;
    --accent-soft: rgba(34, 211, 238, 0.12);
    --accent-ring: rgba(34, 211, 238, 0.35);
    --on-accent: #041318;

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.13);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.13);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.13);
    --info: #818cf8;
    --info-soft: rgba(129, 140, 248, 0.14);

    --radius: 10px;
    --radius-sm: 7px;
    --radius-lg: 14px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.22);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);

    --sidebar-w: 244px;
    --sidebar-w-collapsed: 72px;
    --topbar-h: 62px;

    /* DENSITY, IN ONE PLACE. Every control, card and form gap reads these, so
       "a bit tighter" or "a bit roomier" is a change here and nowhere else.
       Set 2026-11-14 to "moderately tighter": 34px controls (was 38), 16px card
       padding (was 20). A phone gets taller controls back — see the block at
       the bottom of this file — because a finger is not a mouse pointer. */
    --control-h: 34px;
    --control-pad-x: 10px;
    --control-font: 14px;
    --card-pad: 16px;
    --card-gap: 16px;
    --field-gap-y: 12px;
    --field-gap-x: 16px;

    /* How wide a field is allowed to get, by what it holds. A date or a dollar
       amount never needed 400px; it only had it because nothing said no. */
    --cap-number: 150px;
    --cap-date: 160px;
    --cap-tel: 200px;
    --cap-short: 110px;
    --cap-select: 320px;
    --cap-text: 460px;

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;

    /* Older markup still references these names */
    --color-bg: var(--bg);
    --color-surface: var(--surface);
    --color-border: var(--border);
    --color-text: var(--text);
    --color-text-muted: var(--text-muted);
    --color-primary: var(--accent);
    --color-primary-dark: var(--accent-hover);
    --color-danger: var(--danger);
    --color-success: var(--success);
    /* Used by .range-notice and the calendar, and never defined — so both
       always fell back to grey. */
    --color-warning: var(--warning);
}

html, body { background: var(--bg); }
body {
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    font-feature-settings: 'cv11', 'ss01';
    line-height: 1.5;
}
::selection { background: var(--accent-soft); color: var(--accent-hover); }
.icon { width: 18px; height: 18px; flex-shrink: 0; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #141720 0%, #11141a 100%);
    border-right: 1px solid var(--border);
    transition: width .2s ease;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: var(--topbar-h);
    /* Narrow side padding: for a wide logo the sidebar's own width is the
       binding constraint, not the height cap, so every pixel here is a pixel
       the logo cannot use. */
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    /* Not `overflow: hidden` — that cropped a logo taller than the top bar
       instead of letting the row grow to fit it. */
    overflow-x: hidden;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent) 0%, #818cf8 100%);
    color: var(--on-accent);
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(34, 211, 238, 0.25);
}
.brand-mark .icon { width: 19px; height: 19px; }
/* A real uploaded logo replaces the generated mark entirely. It needs far more
   room than the top bar gives, so the brand row is allowed to grow past it —
   the sidebar is its own column, so nothing else shifts. */
.brand-logo {
    max-width: 100%;
    max-height: 168px;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; line-height: 1.2; }
.brand-text small { font-weight: 500; font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }

.app-nav { flex: 1; overflow-y: auto; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
    margin: 18px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    white-space: nowrap;
}
.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link.active::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}

/* Pending-count pill, e.g. how many drafts are waiting. */
.nav-count {
    margin-left: auto;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}
/* Collapsed to icons there's no room for a pill, so it becomes a dot. */
body.sidebar-collapsed .nav-count {
    position: absolute;
    top: 4px;
    right: 4px;
    margin: 0;
    min-width: 8px;
    height: 8px;
    padding: 0;
    font-size: 0;
    background: var(--accent);
}

.sidebar-collapse {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px;
    padding: 9px 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-faint);
    white-space: nowrap;
    cursor: pointer;
}
.sidebar-collapse:hover { background: var(--surface-2); color: var(--text); }
.sidebar-collapse .icon { transition: transform .2s; }

body.sidebar-collapsed .app-sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .brand-name,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-group-label { display: none; }
body.sidebar-collapsed .nav-link,
body.sidebar-collapsed .sidebar-collapse { justify-content: center; padding: 10px; }
body.sidebar-collapsed .sidebar-collapse .icon { transform: rotate(180deg); }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 10px 0; }
/* Collapsed to an icon rail there is only ~44px of width, so the logo stays
   small there whatever its expanded size. */
body.sidebar-collapsed .brand-logo { max-height: 30px; }

.sidebar-backdrop { display: none; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: var(--topbar-h);
    padding: 0 28px;
    background: rgba(15, 17, 21, 0.82);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.sidebar-toggle {
    display: none;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }
.topbar-spacer { flex: 1; }

.company-switch-form select { height: 34px; min-width: 150px; }
.company-name { font-weight: 600; color: var(--text); }
.user-name { color: var(--text-muted); font-size: 13px; }

.app-content { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 24px 28px; }

/* Auth / no-shell pages (login, set password, installer) */
.app-content-plain {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* ---------- Tenant portal shell ----------
   The portal now uses the app shell above — the same sidebar, topbar and
   content column the admin side uses, so there is one layout to maintain and
   one set of responsive rules. What remains here is the signed-OUT chrome: the
   login, set-password and forgot-password screens, which have no sidebar
   because there is nobody to show a menu to yet. */
.portal-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.portal-brand img { max-height: 34px; width: auto; display: block; }

/* ---------- Responsive shell ---------- */
@media (max-width: 960px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform .22s ease;
        width: var(--sidebar-w) !important;
        box-shadow: var(--shadow-lg);
    }
    body.sidebar-open .app-sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 35; }
    body.sidebar-collapsed .brand-text,
    body.sidebar-collapsed .brand-name,
    body.sidebar-collapsed .nav-label,
    body.sidebar-collapsed .nav-group-label { display: revert; }
    /* The drawer is full width on mobile, so the pill fits again. */
    body.sidebar-collapsed .nav-count {
        position: static;
        margin-left: auto;
        min-width: 20px;
        height: auto;
        padding: 1px 6px;
        font-size: 11px;
        background: var(--accent-soft);
    }
    body.sidebar-collapsed .nav-link { justify-content: flex-start; padding: 9px 12px; }
    body.sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding: 10px 18px; }
    .sidebar-collapse { display: none; }
    .sidebar-toggle { display: inline-grid; }
    .app-topbar { padding: 0 16px; gap: 10px; }
    .app-content { padding: 20px 16px; }
}
@media (max-width: 640px) {
    .hide-sm { display: none !important; }

    /* A PHONE GETS ITS TAP TARGETS BACK. 40px is about the smallest thing a
       thumb hits first time. The 16px text is not a style choice: iOS zooms
       the whole page into any field whose text is smaller than 16px the moment
       it is tapped, and leaves it zoomed — that was every field in the app. */
    :root {
        --control-h: 40px;
        --control-font: 16px;
        --card-pad: 14px;
        --card-gap: 12px;
        --field-gap-y: 10px;
        --field-gap-x: 10px;
    }
    .app-content { padding: 14px 12px; }
}
