/* ==========================================================================
   Document Management System — application stylesheet

   Every brand-dependent value is a CSS custom property injected at runtime by
   App\Core\Branding::cssVariables(). Nothing here hard-codes a client colour,
   so rebranding is a settings change, not a code change.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
    /* Brand tokens (overridden at runtime — these are safe fallbacks). */
    --brand-primary: #2563eb;
    --brand-primary-hover: #1d4ed8;
    --brand-primary-active: #1e40af;
    --brand-primary-soft: rgba(37, 99, 235, .10);
    --brand-primary-softer: rgba(37, 99, 235, .05);
    --brand-primary-ring: rgba(37, 99, 235, .35);
    --brand-on-primary: #ffffff;
    --brand-accent: #0ea5e9;
    --brand-accent-soft: rgba(14, 165, 233, .12);
    --sidebar-bg: #0f172a;
    --sidebar-bg-hover: #1e293b;
    --sidebar-bg-active: rgba(37, 99, 235, .25);
    --sidebar-text: #e2e8f0;
    --sidebar-text-muted: rgba(226, 232, 240, .62);
    --sidebar-border: rgba(226, 232, 240, .12);
    --login-bg: #0f172a;
    --login-bg-accent: #1e293b;

    /* Surfaces */
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --surface-3: #f3f4f6;
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    /* Text */
    --text: #111827;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;

    /* Status */
    --success: #16a34a;
    --success-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --info: #0284c7;
    --info-soft: #e0f2fe;

    /* Shape */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08), 0 2px 4px rgba(16, 24, 40, .04);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12), 0 4px 8px rgba(16, 24, 40, .05);

    --sidebar-width: 250px;
    --topbar-height: 62px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
            Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #172033;
    --surface-3: #1f2a3d;
    --border: #253145;
    --border-strong: #33415c;

    --text: #e8ecf3;
    --text-muted: #9aa7bd;
    --text-subtle: #6b7a94;

    --success-soft: rgba(22, 163, 74, .16);
    --danger-soft: rgba(220, 38, 38, .16);
    --warning-soft: rgba(217, 119, 6, .16);
    --info-soft: rgba(2, 132, 199, .16);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .45);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
}

/* --------------------------------------------------------------------------
   2. Reset & base
   -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* The `hidden` attribute is only `display: none` in the UA stylesheet, so any
   author-level display rule silently beats it. Several components below set
   one (.modal-backdrop is grid, .bulk-bar and .alert are flex), which would
   leave them permanently on screen and make `element.hidden = true` in JS do
   nothing. Restore the attribute's meaning for every element. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .93rem; }
p  { margin: 0 0 .75rem; }

a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

code, pre, .mono { font-family: var(--font-mono); font-size: .86em; }

.icon { width: 18px; height: 18px; flex: none; }
.icon-sm { width: 15px; height: 15px; flex: none; }

.skip-link {
    position: absolute; left: -999px; top: 0; z-index: 200;
    background: var(--brand-primary); color: var(--brand-on-primary);
    padding: .6rem 1rem; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   3. App shell
   -------------------------------------------------------------------------- */

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

.sidebar {
    width: var(--sidebar-width);
    flex: none;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 60;
}

.sidebar__brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.brand { display: flex; align-items: center; gap: .6rem; color: inherit; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand__logo { max-height: 34px; max-width: 170px; object-fit: contain; }
.brand__name { font-weight: 700; font-size: 1.02rem; letter-spacing: -.02em; white-space: nowrap; }

.brand__mark {
    width: 34px; height: 34px; flex: none;
    display: grid; place-items: center;
    border-radius: 9px;
    background: var(--brand-primary);
    color: var(--brand-on-primary);
    font-weight: 700; font-size: .84rem; letter-spacing: .02em;
}
.brand__mark--lg { width: 62px; height: 62px; border-radius: 16px; font-size: 1.5rem; }

.sidebar__close { display: none; background: none; border: 0; color: inherit; font-size: 1.6rem; cursor: pointer; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: .85rem .6rem; }

.sidebar__section {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
    color: var(--sidebar-text-muted);
    padding: 1.1rem .75rem .4rem;
    font-weight: 700;
}

.nav-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .58rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
    margin-bottom: 1px;
    transition: background .12s ease;
}
.nav-item:hover { background: var(--sidebar-bg-hover); text-decoration: none; }
.nav-item.is-active { background: var(--sidebar-bg-active); font-weight: 620; }
.nav-item.is-active::before {
    content: ''; position: absolute; left: 0; width: 3px; height: 22px;
    background: var(--brand-primary); border-radius: 0 3px 3px 0;
}
.nav-item { position: relative; }

.sidebar__footer { padding: .9rem 1rem; border-top: 1px solid var(--sidebar-border); font-size: .8rem; }
.sidebar__support { display: flex; flex-direction: column; gap: .1rem; color: var(--sidebar-text-muted); }
.sidebar__support a { color: var(--sidebar-text); }
.sidebar__meta { margin: .5rem 0 0; color: var(--sidebar-text-muted); font-size: .72rem; }

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

.topbar {
    height: var(--topbar-height);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
}

.topbar__menu { display: none; background: none; border: 0; color: var(--text); cursor: pointer; padding: .4rem; }
.topbar__actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }

.content { flex: 1; padding: 1.5rem; max-width: 1500px; width: 100%; }

.app-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .82rem;
}

.sidebar-scrim {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 55;
}

/* --------------------------------------------------------------------------
   4. Search box & dropdowns
   -------------------------------------------------------------------------- */

.search-box { position: relative; flex: 1; max-width: 520px; }
.search-box > .icon {
    position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
    color: var(--text-subtle); pointer-events: none;
}
.search-box input {
    width: 100%;
    padding: .5rem .8rem .5rem 2.3rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-size: .9rem;
    font-family: inherit;
}
.search-box input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-ring);
    background: var(--surface);
}

.search-box__results {
    position: absolute; top: calc(100% + .4rem); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 70;
    max-height: 60vh; overflow-y: auto;
}
.search-box__results a {
    display: flex; align-items: center; gap: .65rem;
    padding: .55rem .8rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
.search-box__results a:last-child { border-bottom: 0; }
.search-box__results a:hover, .search-box__results a.is-active {
    background: var(--brand-primary-soft); text-decoration: none;
}
.search-box__results .muted { font-size: .76rem; }
.search-box__empty { padding: .8rem; color: var(--text-muted); font-size: .85rem; }

.icon-btn {
    position: relative;
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }

.badge {
    position: absolute; top: 2px; right: 2px;
    min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 999px;
    background: var(--danger); color: #fff;
    font-size: .64rem; font-weight: 700;
    display: grid; place-items: center;
}

.dropdown { position: relative; }

.user-chip {
    display: flex; align-items: center; gap: .55rem;
    padding: .3rem .5rem .3rem .3rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: none; cursor: pointer;
    color: var(--text);
    font-family: inherit;
}
.user-chip:hover { background: var(--surface-3); }
.user-chip__text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.user-chip__text strong { font-size: .84rem; font-weight: 600; }
.user-chip__text small { font-size: .7rem; color: var(--text-muted); }

.avatar {
    width: 32px; height: 32px; flex: none;
    border-radius: 50%;
    display: grid; place-items: center;
    color: #fff; font-size: .74rem; font-weight: 700;
    letter-spacing: .02em;
}
.avatar--sm { width: 26px; height: 26px; font-size: .64rem; }
.avatar--lg { width: 64px; height: 64px; font-size: 1.3rem; }

.dropdown__menu {
    position: absolute; right: 0; top: calc(100% + .45rem);
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: .3rem;
    z-index: 80;
}
.dropdown__menu a,
.dropdown__menu button {
    display: flex; align-items: center; gap: .6rem;
    width: 100%;
    padding: .5rem .6rem;
    border: 0; border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit; font-size: .87rem;
    text-align: left; cursor: pointer;
}
.dropdown__menu a:hover, .dropdown__menu button:hover {
    background: var(--surface-3); text-decoration: none;
}
.dropdown__menu form { margin: 0; }
.dropdown__divider { height: 1px; background: var(--border); margin: .3rem 0; }

/* --------------------------------------------------------------------------
   5. Buttons & forms
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .52rem .95rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit; font-size: .87rem; font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: .55; pointer-events: none; }

.btn--primary {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: var(--brand-on-primary);
}
.btn--primary:hover { background: var(--brand-primary-hover); border-color: var(--brand-primary-hover); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn--ghost { background: none; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }

.btn--sm { padding: .34rem .62rem; font-size: .8rem; }
.btn--lg { padding: .68rem 1.3rem; font-size: .95rem; }
.btn--block { width: 100%; }

.btn-group { display: inline-flex; gap: .4rem; flex-wrap: wrap; }

.field { margin-bottom: 1rem; }
.field--inline { display: flex; align-items: center; gap: .6rem; }

label, .label {
    display: block;
    font-size: .82rem; font-weight: 600;
    margin-bottom: .3rem;
    color: var(--text);
}
.label--muted { color: var(--text-muted); font-weight: 500; }

.hint { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }
.error-text { font-size: .78rem; color: var(--danger); margin-top: .3rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="number"], input[type="date"], input[type="url"], input[type="tel"],
select, textarea {
    width: 100%;
    padding: .52rem .7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit; font-size: .88rem;
}
textarea { min-height: 96px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-ring);
}
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); }

input[type="color"] {
    width: 46px; height: 34px; padding: 2px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); cursor: pointer;
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-primary); width: 15px; height: 15px; }

.checkbox {
    display: flex; align-items: flex-start; gap: .55rem;
    font-size: .87rem; font-weight: 500; margin-bottom: .55rem;
    cursor: pointer;
}
.checkbox input { margin-top: .18rem; }
.checkbox span { font-weight: 500; }
.checkbox small { display: block; color: var(--text-muted); font-weight: 400; font-size: .78rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 1rem; }
.form-actions {
    display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
    padding-top: 1rem; margin-top: .5rem; border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   6. Cards, panels, tables
   -------------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card__header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .95rem 1.15rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.card__header h2, .card__header h3 { margin: 0; }
.card__body { padding: 1.15rem; }
.card__body--flush { padding: 0; }
.card__footer {
    padding: .8rem 1.15rem; border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-head__text h1 { margin-bottom: .15rem; }
.page-head__text p { color: var(--text-muted); margin: 0; font-size: .88rem; }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 330px; align-items: start; }

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

table.data { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data th {
    text-align: left;
    padding: .6rem .9rem;
    font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); font-weight: 700;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}
table.data th a { color: inherit; display: inline-flex; align-items: center; gap: .25rem; }
table.data td { padding: .65rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .nowrap { white-space: nowrap; }
table.data .right { text-align: right; }
table.data .actions { white-space: nowrap; text-align: right; }

.empty-state { padding: 3rem 1.5rem; text-align: center; color: var(--text-muted); }
.empty-state .icon { width: 42px; height: 42px; color: var(--text-subtle); margin-bottom: .6rem; }
.empty-state h3 { color: var(--text); margin-bottom: .3rem; }
.empty-state p { max-width: 420px; margin: 0 auto .9rem; font-size: .88rem; }

/* --------------------------------------------------------------------------
   7. Chips, badges, alerts
   -------------------------------------------------------------------------- */

.chip {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .13rem .5rem;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: .74rem; font-weight: 600;
    white-space: nowrap;
}
.chip--primary { background: var(--brand-primary-soft); color: var(--brand-primary); }
.chip--success { background: var(--success-soft); color: var(--success); }
.chip--danger  { background: var(--danger-soft);  color: var(--danger); }
.chip--warning { background: var(--warning-soft); color: var(--warning); }
.chip--info    { background: var(--info-soft);    color: var(--info); }
.chip--dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tag-chip {
    display: inline-flex; align-items: center;
    padding: .1rem .45rem;
    border-radius: var(--radius-sm);
    background: var(--brand-accent-soft);
    color: var(--brand-accent);
    font-size: .72rem; font-weight: 600;
}
a.tag-chip:hover { text-decoration: none; filter: brightness(.94); }

.alert {
    display: flex; align-items: flex-start; gap: .6rem;
    padding: .7rem .9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .88rem;
}
.alert .icon { margin-top: 1px; }
.alert__close {
    margin-left: auto; background: none; border: 0; cursor: pointer;
    color: inherit; opacity: .6; font-size: 1.15rem; line-height: 1; padding: 0 .2rem;
}
.alert__close:hover { opacity: 1; }
.alert.is-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert.is-error   { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.alert.is-info    { background: var(--info-soft);    border-color: var(--info);    color: var(--info); }
.alert.is-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: .8rem; }
.strong { font-weight: 650; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------------------
   8. Stats
   -------------------------------------------------------------------------- */

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.05rem 1.15rem;
    box-shadow: var(--shadow-sm);
    display: flex; align-items: flex-start; gap: .9rem;
}
.stat__icon {
    width: 40px; height: 40px; flex: none;
    border-radius: var(--radius);
    display: grid; place-items: center;
    background: var(--brand-primary-soft);
    color: var(--brand-primary);
}
.stat__value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat__label { font-size: .78rem; color: var(--text-muted); font-weight: 550; }
.stat__sub { font-size: .74rem; color: var(--text-subtle); margin-top: .1rem; }

/* Sparkline / bar chart built from divs — no charting library required. */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.bars__bar {
    flex: 1;
    min-height: 2px;
    background: var(--brand-primary);
    border-radius: 2px 2px 0 0;
    opacity: .82;
    transition: opacity .12s ease;
}
.bars__bar:hover { opacity: 1; }

.meter { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter__fill { height: 100%; background: var(--brand-primary); border-radius: 999px; }

/* --------------------------------------------------------------------------
   9. Breadcrumb, toolbar, file browser
   -------------------------------------------------------------------------- */

.breadcrumb {
    display: flex; align-items: center; gap: .25rem;
    flex-wrap: wrap;
    font-size: .85rem;
    margin-bottom: .85rem;
    color: var(--text-muted);
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--brand-primary); }
.breadcrumb__sep { color: var(--text-subtle); }
.breadcrumb__current { color: var(--text); font-weight: 600; }

.toolbar {
    display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    padding: .7rem .9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
}
.toolbar__spacer { margin-left: auto; }

.view-toggle { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.view-toggle a {
    padding: .35rem .55rem; color: var(--text-muted); display: grid; place-items: center;
    background: var(--surface);
}
.view-toggle a.is-active { background: var(--brand-primary); color: var(--brand-on-primary); }
.view-toggle a:hover { text-decoration: none; }

.file-icon {
    width: 34px; height: 34px; flex: none;
    border-radius: var(--radius-sm);
    display: grid; place-items: center;
    color: #fff;
    font-size: .6rem; font-weight: 800; letter-spacing: .02em;
    text-transform: uppercase;
}
.file-icon--lg { width: 52px; height: 52px; font-size: .8rem; border-radius: var(--radius); }
.file-icon--xl { width: 76px; height: 76px; font-size: 1.05rem; border-radius: var(--radius-lg); }

.item-row { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.item-row__text { min-width: 0; }
.item-row__title { font-weight: 600; color: var(--text); display: block; }
.item-row__title:hover { color: var(--brand-primary); }
.item-row__meta { font-size: .76rem; color: var(--text-muted); }

.folder-tile {
    display: flex; align-items: center; gap: .7rem;
    padding: .75rem .9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color .12s ease, box-shadow .12s ease;
}
.folder-tile:hover {
    border-color: var(--brand-primary);
    box-shadow: var(--shadow-md);
    text-decoration: none;
}
.folder-tile .icon { color: var(--brand-primary); width: 22px; height: 22px; }
.folder-tile__name { font-weight: 600; display: block; }
.folder-tile__meta { font-size: .75rem; color: var(--text-muted); }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: .9rem; }

.doc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex; flex-direction: column;
    transition: border-color .12s ease, box-shadow .12s ease;
}
.doc-card:hover { border-color: var(--brand-primary); box-shadow: var(--shadow-md); }
.doc-card__thumb {
    height: 122px;
    display: grid; place-items: center;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}
.doc-card__thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-card__body { padding: .6rem .7rem; flex: 1; }
.doc-card__title {
    font-size: .84rem; font-weight: 600; color: var(--text);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.3;
}
.doc-card__title:hover { color: var(--brand-primary); text-decoration: none; }
.doc-card__meta { font-size: .72rem; color: var(--text-muted); margin-top: .25rem; }

.bulk-bar {
    display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
    padding: .6rem .9rem;
    background: var(--brand-primary-soft);
    border: 1px solid var(--brand-primary);
    border-radius: var(--radius);
    margin-bottom: .9rem;
    font-size: .87rem;
}

/* --------------------------------------------------------------------------
   10. Document detail
   -------------------------------------------------------------------------- */

.preview-frame {
    width: 100%; height: 640px;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface-3);
}
.preview-image {
    display: block; max-width: 100%; max-height: 640px;
    margin: 0 auto; border-radius: var(--radius);
}
.preview-text {
    max-height: 560px; overflow: auto;
    padding: 1rem 1.15rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: .82rem;
    white-space: pre-wrap;
    word-break: break-word;
}
.preview-none { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }

.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; overflow-x: auto; }
.tabs a, .tabs button {
    padding: .6rem .9rem;
    border: 0; border-bottom: 2px solid transparent;
    background: none; color: var(--text-muted);
    font: inherit; font-size: .87rem; font-weight: 600;
    cursor: pointer; white-space: nowrap;
}
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs .is-active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

.detail-list { display: grid; gap: .55rem; font-size: .86rem; }
.detail-list > div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: .6rem; }
.detail-list dt, .detail-list .dt { color: var(--text-muted); font-weight: 550; }
.detail-list dd, .detail-list .dd { margin: 0; word-break: break-word; }

.version-row { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.version-row:last-child { border-bottom: 0; }
.version-badge {
    width: 40px; height: 40px; flex: none;
    display: grid; place-items: center;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    font-size: .78rem; font-weight: 700;
}
.version-badge.is-current { background: var(--brand-primary); color: var(--brand-on-primary); }

.comment { display: flex; gap: .75rem; padding: .8rem 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment__body { min-width: 0; flex: 1; }
.comment__head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.comment__author { font-weight: 650; font-size: .87rem; }
.comment__time { font-size: .75rem; color: var(--text-subtle); }
.comment__text { font-size: .88rem; white-space: pre-wrap; word-break: break-word; margin: .2rem 0 0; }
.comment__replies { margin-left: 2.4rem; border-left: 2px solid var(--border); padding-left: .9rem; }

.timeline { position: relative; padding-left: 1.4rem; }
.timeline::before {
    content: ''; position: absolute; left: 5px; top: .4rem; bottom: .4rem;
    width: 2px; background: var(--border);
}
.timeline__item { position: relative; padding: .45rem 0; font-size: .84rem; }
.timeline__item::before {
    content: ''; position: absolute; left: -1.4rem; top: .8rem;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--brand-primary); border: 2px solid var(--surface);
}

/* --------------------------------------------------------------------------
   11. Uploader
   -------------------------------------------------------------------------- */

.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 2.4rem 1.5rem;
    text-align: center;
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.is-dragover {
    border-color: var(--brand-primary);
    background: var(--brand-primary-softer);
}
.dropzone .icon { width: 40px; height: 40px; color: var(--brand-primary); margin-bottom: .5rem; }
.dropzone h3 { margin-bottom: .2rem; }
.dropzone p { color: var(--text-muted); font-size: .86rem; margin: 0; }

.upload-list { margin-top: 1rem; display: grid; gap: .5rem; }
.upload-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .6rem .8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .85rem;
}
.upload-item__bar { flex: 1; height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.upload-item__fill { height: 100%; width: 0; background: var(--brand-primary); transition: width .2s ease; }
.upload-item.is-done .upload-item__fill { background: var(--success); }
.upload-item.is-error { border-color: var(--danger); }
.upload-item.is-error .upload-item__fill { background: var(--danger); }
.upload-item__status { font-size: .76rem; color: var(--text-muted); min-width: 62px; text-align: right; }

/* --------------------------------------------------------------------------
   12. Auth & public pages
   -------------------------------------------------------------------------- */

.auth-body { margin: 0; }
.auth-layout { display: grid; grid-template-columns: 1.05fr .95fr; min-height: 100vh; }

.auth-hero {
    background: var(--login-bg);
    background-image: linear-gradient(135deg, var(--login-bg), var(--login-bg-accent));
    background-size: cover; background-position: center;
    color: #fff;
    padding: 3rem;
    display: flex; flex-direction: column; justify-content: center;
    position: relative;
}
.auth-hero__inner { max-width: 460px; }
.auth-hero__logo { max-height: 62px; max-width: 260px; margin-bottom: 1.6rem; }
.auth-hero h1 { font-size: 2rem; margin-top: 1.2rem; color: #fff; }
.auth-hero__tagline { color: rgba(255, 255, 255, .78); font-size: 1rem; }
.auth-hero__points { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; gap: .75rem; }
.auth-hero__points li {
    display: flex; align-items: center; gap: .65rem;
    color: rgba(255, 255, 255, .88); font-size: .9rem;
}
.auth-hero__points .icon { color: var(--brand-accent); }
.auth-hero__footer {
    position: absolute; bottom: 2rem; left: 3rem;
    color: rgba(255, 255, 255, .55); font-size: .8rem; margin: 0;
}

.auth-panel { display: grid; place-items: center; padding: 2.5rem 1.5rem; background: var(--bg); }
.auth-panel__inner { width: 100%; max-width: 380px; }
.auth-panel h2 { font-size: 1.45rem; }
.auth-panel .muted { margin-bottom: 1.6rem; }

.public-body { margin: 0; background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
.public-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .9rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.public-header__brand { display: flex; align-items: center; gap: .6rem; font-weight: 650; }
.public-header__brand img { max-height: 34px; max-width: 180px; object-fit: contain; }
.public-header__note { display: flex; align-items: center; gap: .35rem; color: var(--text-muted); font-size: .82rem; }
.public-main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 1.75rem 1.25rem; }
.public-footer {
    padding: 1.25rem 1.5rem; text-align: center;
    color: var(--text-muted); font-size: .8rem;
    border-top: 1px solid var(--border);
}
.public-footer p { margin: .15rem 0; }

.blank-body { margin: 0; display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.blank-shell { width: 100%; max-width: 560px; padding: 2rem 1.5rem; text-align: center; }

.error-code {
    font-size: 4.5rem; font-weight: 800; line-height: 1;
    color: var(--brand-primary); letter-spacing: -.04em;
}

/* --------------------------------------------------------------------------
   13. Misc
   -------------------------------------------------------------------------- */

.pagination { display: flex; gap: .25rem; align-items: center; justify-content: center; margin-top: 1.2rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 34px; height: 34px; padding: 0 .5rem;
    display: grid; place-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text); font-size: .84rem;
}
.pagination a:hover { border-color: var(--brand-primary); text-decoration: none; }
.pagination .is-active { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--brand-on-primary); }
.pagination .is-disabled { opacity: .45; pointer-events: none; }

.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15, 23, 42, .55);
    display: grid; place-items: center;
    padding: 1.25rem;
}
.modal {
    width: 100%; max-width: 520px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 90vh; overflow-y: auto;
}
.modal__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.15rem; border-bottom: 1px solid var(--border);
}
.modal__header h3 { margin: 0; }
.modal__body { padding: 1.15rem; }
.modal__footer {
    display: flex; gap: .5rem; justify-content: flex-end;
    padding: .9rem 1.15rem; border-top: 1px solid var(--border);
}
.modal__close { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); line-height: 1; }

.copy-field { display: flex; gap: .4rem; }
.copy-field input { font-family: var(--font-mono); font-size: .8rem; }

.health-item {
    display: flex; align-items: flex-start; gap: .6rem;
    padding: .6rem 0; border-bottom: 1px solid var(--border); font-size: .86rem;
}
.health-item:last-child { border-bottom: 0; }
.health-item__dot {
    width: 9px; height: 9px; border-radius: 50%; margin-top: .42rem; flex: none;
    background: var(--success);
}
.health-item.is-fail .health-item__dot { background: var(--danger); }
.health-item.is-warn .health-item__dot { background: var(--warning); }
.health-item__detail { color: var(--text-muted); font-size: .78rem; word-break: break-all; }

.swatch-row { display: flex; align-items: center; gap: .6rem; }
.swatch-preview {
    height: 46px; border-radius: var(--radius-sm);
    display: grid; place-items: center;
    font-size: .78rem; font-weight: 650;
}

.tag-cloud { display: flex; flex-wrap: wrap; gap: .35rem; }

.stack { display: grid; gap: 1rem; }
.stack--sm { gap: .5rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }

/* --------------------------------------------------------------------------
   14. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1100px) {
    .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .auth-layout { grid-template-columns: 1fr; }
    .auth-hero { padding: 2rem 1.5rem; min-height: auto; }
    .auth-hero__points { display: none; }
    .auth-hero__footer { position: static; margin-top: 1.25rem; }
    .auth-hero h1 { font-size: 1.5rem; }
}

@media (max-width: 820px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar__close { display: block; }
    .topbar__menu { display: block; }
    .user-chip__text { display: none; }
    .content { padding: 1rem; }
    .detail-list > div { grid-template-columns: 1fr; gap: .1rem; }
    .detail-list dt, .detail-list .dt { font-size: .78rem; }
}

@media (max-width: 560px) {
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head__actions .btn { flex: 1; }
    .doc-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .preview-frame { height: 420px; }
}

@media print {
    .sidebar, .topbar, .toolbar, .page-head__actions, .app-footer, .tabs { display: none !important; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
    body { background: #fff; }
}
