/* =========================================================================
   DMS design tokens
   ========================================================================= */
:root {
    /* neutrals */
    --gray-0: #ffffff;
    --gray-25: #fbfcfd;
    --gray-50: #f5f7fa;
    --gray-100: #eef1f5;
    --gray-200: #e2e7ee;
    --gray-300: #cfd6e0;
    --gray-400: #9aa5b4;
    --gray-500: #6b7686;
    --gray-600: #4d5766;
    --gray-700: #363e4b;
    --gray-800: #1f2530;
    --gray-900: #121720;

    /* brand */
    --brand-50: #eef4ff;
    --brand-100: #dce8ff;
    --brand-200: #b9d0ff;
    --brand-500: #2f6bea;
    --brand-600: #2257cc;
    --brand-700: #1b46a6;

    /* semantic */
    --green-50: #ecfdf3;  --green-600: #067647;  --green-200: #abefc6;
    --amber-50: #fffaeb;  --amber-600: #b54708;  --amber-200: #fedf89;
    --red-50: #fef3f2;    --red-600: #c4320a;    --red-200: #fecdca;  --red-700: #a3250a;
    --blue-50: #eff8ff;   --blue-600: #175cd3;   --blue-200: #b2ddff;

    /* spacing (4px base) */
    --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
    --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

    /* type */
    --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px;
    --fs-xl: 20px; --fs-2xl: 24px; --fs-3xl: 30px;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(18, 23, 32, .06);
    --shadow: 0 1px 3px rgba(18, 23, 32, .08), 0 4px 16px rgba(18, 23, 32, .05);
    --shadow-lg: 0 12px 48px rgba(18, 23, 32, .18);
    --ring: 0 0 0 3px rgba(47, 107, 234, .28);

    --sidebar-w: 296px;
    --tree-row: 28px;
    --topbar-h: 60px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs-md);
    line-height: 1.5;
    color: var(--gray-800);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
}
img, iframe { max-width: 100%; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-700); text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; color: var(--gray-900); line-height: 1.25; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: none; box-shadow: var(--ring); }
.sr-only {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }
.muted { color: var(--gray-500); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =========================================================================
   App shell
   ========================================================================= */
.shell { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: var(--sidebar-w);
    display: flex; flex-direction: column;
    background: var(--gray-900);
    color: var(--gray-300);
    padding: var(--s-4) var(--s-3);
    transition: transform .22s ease;
}
.brand {
    display: flex; align-items: center; gap: var(--s-3);
    padding: var(--s-2) var(--s-2) var(--s-5);
    color: #fff;
}
.brand:hover { text-decoration: none; color: #fff; }
.brand-mark {
    display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: var(--radius);
    background: linear-gradient(135deg, var(--brand-500), #6c8cff);
    color: #fff; font-weight: 700; font-size: var(--fs-sm); letter-spacing: .02em;
}
.brand strong { display: block; font-size: var(--fs-lg); line-height: 1.2; }
.brand-text > span { display: block; font-size: var(--fs-xs); color: var(--gray-400); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
    margin: var(--s-5) var(--s-3) var(--s-2);
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
    color: var(--gray-500);
}
.nav a {
    display: flex; align-items: center; gap: var(--s-3);
    padding: 9px var(--s-3);
    border-radius: var(--radius-sm);
    color: var(--gray-300);
    font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(47,107,234,.22); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .count {
    margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px;
    background: rgba(255,255,255,.1); color: #fff; font-size: 11px; line-height: 20px; text-align: center;
}
.nav .count.warn { background: #b54708; }

.sidebar-foot {
    margin-top: auto; padding: var(--s-3);
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: var(--s-3);
}
.avatar {
    width: 32px; height: 32px; border-radius: 50%; flex: none;
    display: grid; place-items: center;
    background: var(--gray-700); color: #fff; font-size: var(--fs-sm); font-weight: 600;
    text-transform: uppercase;
}
.sidebar-foot .who { min-width: 0; flex: 1; }
.sidebar-foot .who strong { display: block; color: #fff; font-size: var(--fs-sm); font-weight: 500; }
.sidebar-foot .who span { display: block; color: var(--gray-400); font-size: var(--fs-xs); }
.icon-link {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm);
    color: var(--gray-400);
}
.icon-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.icon-link svg { width: 18px; height: 18px; }

.topbar {
    display: none;
    position: sticky; top: 0; z-index: 50;
    height: var(--topbar-h);
    align-items: center; gap: var(--s-3);
    padding: 0 var(--s-4);
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--gray-200);
}
.topbar .brand { padding: 0; color: var(--gray-900); }
.topbar .brand strong { color: var(--gray-900); }
.menu-btn {
    display: grid; place-items: center; width: 40px; height: 40px;
    border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
    background: #fff; cursor: pointer;
}
.menu-btn svg { width: 20px; height: 20px; }
.scrim { position: fixed; inset: 0; z-index: 55; background: rgba(18,23,32,.45); }

.main { margin-left: var(--sidebar-w); min-width: 0; }
.page { max-width: 1480px; margin: 0 auto; padding: var(--s-8) var(--s-8) var(--s-12); }

.page-head {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
    gap: var(--s-4); margin-bottom: var(--s-6);
}
.page-head h1 { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -.01em; }
.page-head p { margin-top: var(--s-1); color: var(--gray-500); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.crumbs { display: flex; gap: var(--s-2); align-items: center; font-size: var(--fs-sm); color: var(--gray-500); margin-bottom: var(--s-2); }
.crumbs a { color: var(--gray-500); }

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    body.nav-open .sidebar { transform: none; }
    .topbar { display: flex; }
    .main { margin-left: 0; }
    .page { padding: var(--s-5) var(--s-4) var(--s-10); }
}

/* =========================================================================
   Buttons, inputs, badges
   ========================================================================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    height: 38px; padding: 0 var(--s-4);
    border: 1px solid transparent; border-radius: var(--radius-sm);
    font-size: var(--fs-md); font-weight: 550; line-height: 1;
    cursor: pointer; white-space: nowrap; text-decoration: none;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--brand-500); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-secondary { background: #fff; border-color: var(--gray-300); color: var(--gray-700); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--gray-50); color: var(--gray-900); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-900); }
.btn-danger { background: #fff; border-color: var(--red-200); color: var(--red-600); }
.btn-danger:hover { background: var(--red-50); color: var(--red-700); }
.btn-danger-solid { background: var(--red-600); color: #fff; }
.btn-danger-solid:hover { background: var(--red-700); color: #fff; }
.btn-success { background: var(--green-600); color: #fff; }
.btn-success:hover { background: #05603a; color: #fff; }
.btn-sm { height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn-lg { height: 44px; padding: 0 var(--s-5); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-icon { width: 30px; padding: 0; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 550; color: var(--gray-700); }
.field .hint { font-size: var(--fs-xs); color: var(--gray-500); }
.field .error, .errorlist { color: var(--red-600); font-size: var(--fs-xs); margin: 0; padding: 0; list-style: none; }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=file]), .field select, .field textarea {
    width: 100%; height: 38px; padding: 0 var(--s-3);
    background: #fff; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
    color: var(--gray-900); font-size: var(--fs-md);
    transition: border-color .15s, box-shadow .15s;
}
textarea.input, .field textarea { height: auto; padding: var(--s-2) var(--s-3); line-height: 1.5; resize: vertical; }
.input::placeholder, .field input::placeholder { color: var(--gray-400); }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--brand-500); box-shadow: var(--ring);
}
.input-lg { height: 46px; font-size: var(--fs-lg); padding: 0 var(--s-4); }
.field.has-error .input, .field.has-error input { border-color: var(--red-600); }
select.input { padding-right: 32px; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7686' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }
.input-icon .input { padding-left: 34px; }
.check { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-md); color: var(--gray-700); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand-500); }

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    height: 22px; padding: 0 8px; border-radius: 999px;
    font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
    border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-COMPLETED { background: var(--green-50); color: var(--green-600); border-color: var(--green-200); }
.badge-REVIEW { background: var(--amber-50); color: var(--amber-600); border-color: var(--amber-200); }
.badge-PENDING, .badge-PROCESSING { background: var(--blue-50); color: var(--blue-600); border-color: var(--blue-200); }
.badge-FAILED { background: var(--red-50); color: var(--red-600); border-color: var(--red-200); }
.badge-PROCESSING::before { animation: pulse 1.2s infinite; }
.badge-type { background: var(--gray-100); color: var(--gray-600); border-color: var(--gray-200); }
@keyframes pulse { 50% { opacity: .25; } }

.conf { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--gray-500); }
.conf-bar { width: 44px; height: 5px; border-radius: 3px; background: var(--gray-200); overflow: hidden; }
.conf-bar i { display: block; height: 100%; background: var(--green-600); }
.conf-bar i.mid { background: #dc8a06; }
.conf-bar i.low { background: var(--red-600); }

/* =========================================================================
   Cards, alerts, stats
   ========================================================================= */
.card {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-head {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3);
    padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--gray-100);
}
.card-head h2, .card-head h3 { font-size: var(--fs-lg); font-weight: 600; }
.card-body { padding: var(--s-5); }
.card + .card { margin-top: var(--s-5); }

.alert {
    display: flex; gap: var(--s-3); align-items: flex-start;
    padding: var(--s-3) var(--s-4); border-radius: var(--radius); border: 1px solid;
    margin-bottom: var(--s-5); font-size: var(--fs-md);
}
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert strong { font-weight: 600; }
.alert code { background: rgba(0,0,0,.06); padding: 1px 6px; border-radius: 4px; }
.alert-warn { background: var(--amber-50); border-color: var(--amber-200); color: #7a2e0e; }
.alert-error { background: var(--red-50); border-color: var(--red-200); color: var(--red-700); }
.alert-info { background: var(--blue-50); border-color: var(--blue-200); color: #194185; }

.stats {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s-4);
    margin-bottom: var(--s-6);
}
.stat {
    position: relative; display: block;
    padding: var(--s-4) var(--s-5);
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius-lg);
    color: inherit; box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.stat:hover { text-decoration: none; border-color: var(--gray-300); box-shadow: var(--shadow); color: inherit; }
.stat.active { border-color: var(--brand-500); box-shadow: 0 0 0 1px var(--brand-500), var(--shadow); }
.stat-label { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--gray-500); font-weight: 500; }
.stat-dot { width: 8px; height: 8px; border-radius: 50%; }
.stat-value { margin-top: var(--s-2); font-size: var(--fs-3xl); font-weight: 650; color: var(--gray-900); letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-sub { margin-top: var(--s-1); font-size: var(--fs-xs); color: var(--gray-500); }
@media (max-width: 1280px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
    .stat { padding: var(--s-3) var(--s-4); }
    .stat-value { font-size: var(--fs-2xl); }
}

/* =========================================================================
   Dashboard table (jQuery DataTables, server-side)
   ========================================================================= */
.toolbar {
    display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center;
    padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--gray-100);
}
.toolbar .grow { flex: 1 1 260px; min-width: 200px; }
.toolbar .input { height: 36px; }
.toolbar select.input { width: auto; min-width: 170px; }
.toolbar .date-range { display: flex; align-items: center; gap: var(--s-2); }
.toolbar .date-range .input { width: 150px; }
@media (max-width: 720px) {
    .toolbar { padding: var(--s-3) var(--s-4); }
    .toolbar select.input, .toolbar .date-range { width: 100%; flex: 1 1 100%; }
    .toolbar .date-range { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
    .toolbar .date-range .input { width: 100%; min-width: 0; }
}

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100% !important; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
table.data thead th {
    position: sticky; top: 0;
    padding: 10px var(--s-4); text-align: left; white-space: nowrap;
    background: var(--gray-25); color: var(--gray-500);
    font-size: var(--fs-xs); font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
    border-bottom: 1px solid var(--gray-200);
}
table.data tbody td {
    padding: 12px var(--s-4); vertical-align: middle;
    border-bottom: 1px solid var(--gray-100); color: var(--gray-700);
}
table.data tbody tr:hover td { background: var(--gray-25); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.col-file { min-width: 210px; max-width: 280px; }
table.data td.col-name { min-width: 150px; max-width: 240px; }
table.data td.col-ref { min-width: 140px; max-width: 220px; }
table.data td.col-actions, table.data th.col-actions {
    position: sticky; right: 0; z-index: 1;
    text-align: right; white-space: nowrap; width: 1%;
    background: #fff; box-shadow: -8px 0 12px -10px rgba(18,23,32,.25);
}
table.data th.col-actions { background: var(--gray-25); z-index: 2; }
table.data tbody tr:hover td.col-actions { background: var(--gray-25); }
.cell-file { display: flex; gap: var(--s-3); align-items: center; min-width: 0; }
.file-icon {
    flex: none; width: 34px; height: 34px; border-radius: var(--radius-sm);
    display: grid; place-items: center;
    background: var(--brand-50); color: var(--brand-600); font-size: 10px; font-weight: 700;
}
.cell-file .meta { min-width: 0; }
.cell-file a { display: block; color: var(--gray-900); font-weight: 550; }
.cell-file .sub { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; align-items: center; }
.code { font-family: var(--mono); font-size: 13px; color: var(--gray-900); }
.empty-dash { color: var(--gray-300); }
.row-actions { display: inline-flex; gap: 6px; }

/* DataTables chrome */
.dt-container { font-size: var(--fs-md); }
.dt-container .dt-layout-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); }
.dt-container .dt-layout-row.dt-layout-table { display: block; }
.dt-container .dt-layout-row:last-child { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--gray-100); }
.dt-container .dt-layout-cell { display: flex; align-items: center; gap: var(--s-3); }
.dt-info { color: var(--gray-500); font-size: var(--fs-sm); }
.dt-length { display: flex; align-items: center; gap: var(--s-2); color: var(--gray-500); font-size: var(--fs-sm); }
.dt-length select { height: 32px; padding: 0 28px 0 10px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); background: #fff; }
.dt-paging nav { display: flex; gap: 4px; flex-wrap: wrap; }
.dt-paging .dt-paging-button {
    min-width: 32px; height: 32px; padding: 0 10px;
    border: 1px solid var(--gray-200); border-radius: var(--radius-sm); background: #fff;
    color: var(--gray-700); cursor: pointer; font-size: var(--fs-sm);
}
.dt-paging .dt-paging-button:hover:not(.disabled):not(.current) { background: var(--gray-50); }
.dt-paging .dt-paging-button.current { background: var(--brand-500); border-color: var(--brand-500); color: #fff; }
.dt-paging .dt-paging-button.disabled { opacity: .45; cursor: default; }
.dt-paging .ellipsis { padding: 0 6px; color: var(--gray-400); align-self: center; }
table.dataTable thead th.dt-orderable-asc, table.dataTable thead th.dt-orderable-desc { cursor: pointer; }
table.dataTable thead .dt-column-order { display: inline-block; width: 12px; margin-left: 4px; position: relative; top: 1px; }
table.dataTable thead .dt-column-order::before { content: "↕"; color: var(--gray-300); font-size: 11px; }
table.dataTable thead th.dt-ordering-asc .dt-column-order::before { content: "↑"; color: var(--brand-600); }
table.dataTable thead th.dt-ordering-desc .dt-column-order::before { content: "↓"; color: var(--brand-600); }
table.dataTable thead th .dt-column-header { display: inline-flex; align-items: center; }
.dt-processing {
    position: absolute; top: 56px; left: 50%; transform: translateX(-50%); z-index: 5;
    padding: 8px 14px; border-radius: 999px; background: var(--gray-900); color: #fff; font-size: var(--fs-sm);
    box-shadow: var(--shadow);
}
.dt-processing > div:not(:first-child) { display: none; }
.dt-empty { padding: var(--s-10) var(--s-4) !important; text-align: center; color: var(--gray-500); }
@media (max-width: 720px) {
    .dt-container .dt-layout-row:last-child { justify-content: center; padding: var(--s-3); }
    .dt-container .dt-layout-cell { flex: 1 1 100%; justify-content: center; }
}

/* Mobile: stacked cards instead of a wide table */
@media (max-width: 760px) {
    table.data.stack thead { display: none; }
    table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
    table.data.stack tbody tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--gray-200); }
    table.data.stack tbody td { padding: 3px 0; border: 0; max-width: none !important; min-width: 0 !important; }
    table.data.stack tbody tr:hover td { background: transparent; }
    table.data.stack td[data-label]:not(.col-file):not(.col-actions)::before {
        content: attr(data-label); display: inline-block; width: 108px; color: var(--gray-500); font-size: var(--fs-xs);
    }
    table.data.stack td.col-file { margin-bottom: var(--s-2); }
    table.data.stack td > .truncate { display: inline-block !important; max-width: calc(100% - 112px); vertical-align: bottom; }
    table.data.stack td.col-actions { position: static; box-shadow: none; background: transparent; text-align: left; margin-top: var(--s-2); }
    table.data.stack td.dt-empty::before { display: none; }
}

/* =========================================================================
   Modal
   ========================================================================= */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 5vh var(--s-4); overflow-y: auto; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(18,23,32,.5); animation: fade .15s ease; }
.modal-dialog {
    position: relative; width: 100%; max-width: 880px;
    background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    animation: rise .18s ease;
}
.modal-dialog.sm { max-width: 440px; }
.modal-head { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--gray-100); }
.modal-head h3 { font-size: var(--fs-xl); font-weight: 600; word-break: break-word; }
.modal-head .sub { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); align-items: center; }
.modal-close { margin-left: auto; flex: none; }
.modal-body { padding: var(--s-5) var(--s-6); }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--gray-100); background: var(--gray-25); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal-body p { color: var(--gray-600); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 640px) {
    .modal { padding: 0; align-items: flex-end; }
    .modal-dialog { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; overflow-y: auto; }
    .modal-head, .modal-body, .modal-foot { padding-left: var(--s-4); padding-right: var(--s-4); }
    .modal-foot .btn { flex: 1; }
}

.section-title { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--gray-500); margin: var(--s-6) 0 var(--s-3); }
.section-title:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s-6); margin: 0; }
.kv > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: var(--s-3); padding: 9px 0; border-bottom: 1px solid var(--gray-100); }
.kv dt { color: var(--gray-500); font-size: var(--fs-sm); }
.kv dd { margin: 0; color: var(--gray-900); font-weight: 500; word-break: break-word; }
.kv.single { grid-template-columns: 1fr; }
@media (max-width: 640px) {
    .kv { grid-template-columns: 1fr; }
    .kv > div { grid-template-columns: 120px minmax(0, 1fr); }
}
.primary-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s-3); }
.primary-grid .pill { padding: var(--s-3); border-radius: var(--radius); background: var(--gray-50); border: 1px solid var(--gray-100); min-width: 0; }
.primary-grid .pill span { display: block; font-size: var(--fs-xs); color: var(--gray-500); }
.primary-grid .pill strong { display: block; margin-top: 2px; color: var(--gray-900); font-weight: 600; word-break: break-word; }
@media (max-width: 860px) { .primary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.mini-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.mini-table th { text-align: left; padding: 8px 10px; background: var(--gray-50); color: var(--gray-500); font-weight: 600; font-size: var(--fs-xs); white-space: nowrap; border-bottom: 1px solid var(--gray-200); }
.mini-table td { padding: 8px 10px; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); vertical-align: top; }
.mini-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); }

.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--gray-100), var(--gray-200), var(--gray-100)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.skeleton + .skeleton { margin-top: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* =========================================================================
   Upload
   ========================================================================= */
.upload-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s-6); align-items: start; }
@media (max-width: 1024px) { .upload-grid { grid-template-columns: 1fr; } }
.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
    gap: var(--s-2); min-height: 240px; padding: var(--s-8) var(--s-5);
    border: 2px dashed var(--gray-300); border-radius: var(--radius-lg);
    background: var(--gray-25); cursor: pointer;
    transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand-500); background: var(--brand-50); }
.dropzone:focus-within { box-shadow: var(--ring); }
.dropzone-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-100); color: var(--brand-600); margin-bottom: var(--s-2); }
.dropzone-icon svg { width: 24px; height: 24px; }
.dropzone h3 { font-size: var(--fs-lg); font-weight: 600; }
.dropzone p { color: var(--gray-500); font-size: var(--fs-sm); }

.file-list { list-style: none; margin: 0; padding: 0; }
.file-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--gray-100); }
.file-item:last-child { border-bottom: 0; }
.file-item .name-input { height: 32px; font-size: var(--fs-sm); }
.file-item .info { display: flex; gap: var(--s-2); align-items: center; margin-top: 4px; font-size: var(--fs-xs); color: var(--gray-500); }
.file-item .state-ok { color: var(--green-600); font-weight: 600; }
.file-item .state-err { color: var(--red-600); font-weight: 600; }
.progress { height: 8px; border-radius: 999px; background: var(--gray-100); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--brand-500); transition: width .2s; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-4); }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: var(--s-3); }
.steps .num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); font-weight: 600; font-size: var(--fs-sm); }
.steps strong { display: block; font-size: var(--fs-md); color: var(--gray-900); }
.steps span { font-size: var(--fs-sm); color: var(--gray-500); }

/* =========================================================================
   Detail / review
   ========================================================================= */
.split { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: var(--s-6); align-items: start; }
.split.review { grid-template-columns: minmax(0, 1fr) minmax(380px, .9fr); }
@media (max-width: 1100px) { .split, .split.review { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: var(--s-6); }
@media (max-width: 1100px) { .sticky { position: static; } }
.preview-frame { display: block; width: 100%; height: calc(100vh - 170px); min-height: 520px; border: 0; background: var(--gray-100); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.preview-img { display: block; width: 100%; height: auto; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@media (max-width: 1100px) { .preview-frame { height: 70vh; min-height: 420px; } }
.preview-empty { padding: var(--s-12) var(--s-5); text-align: center; color: var(--gray-500); }

.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--gray-200); padding: 0 var(--s-5); overflow-x: auto; }
.tab { padding: var(--s-3) var(--s-3); border: 0; border-bottom: 2px solid transparent; background: none; color: var(--gray-500); font-weight: 550; cursor: pointer; white-space: nowrap; margin-bottom: -1px; }
.tab:hover { color: var(--gray-900); }
.tab.active { color: var(--brand-600); border-bottom-color: var(--brand-500); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
pre.text-block { margin: 0; padding: var(--s-4); max-height: 560px; overflow: auto; background: var(--gray-900); color: #e6ebf2; border-radius: var(--radius); font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.field .conf-note { font-size: 11px; font-weight: 500; }
.conf-note.low { color: var(--red-600); }
.conf-note.mid { color: var(--amber-600); }
.conf-note.ok { color: var(--green-600); }
.extra-row { display: grid; grid-template-columns: minmax(0, 190px) minmax(0, 1fr) 34px; gap: var(--s-2); align-items: center; margin-bottom: var(--s-2); }
.extra-row .input { height: 34px; font-size: var(--fs-sm); }
@media (max-width: 560px) { .extra-row { grid-template-columns: minmax(0, 1fr) 34px; } .extra-row .label-input { grid-column: 1 / -1; } }
.action-bar {
    position: sticky; bottom: 0; z-index: 10;
    display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: flex-end; align-items: center;
    padding: var(--s-3) var(--s-5); background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
    border-top: 1px solid var(--gray-200); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.action-bar .left { margin-right: auto; }
@media (max-width: 560px) { .action-bar .btn { flex: 1 1 auto; } .action-bar .left { flex: 1 1 100%; } }

/* =========================================================================
   Search
   ========================================================================= */
.search-form { display: grid; gap: var(--s-4); }
.search-row { display: flex; gap: var(--s-3); }
.search-row .input-icon { flex: 1; }
.search-row .input-icon svg { left: 14px; width: 18px; height: 18px; }
.search-row .input-icon .input { padding-left: 42px; }
.filters-row { display: flex; flex-wrap: wrap; gap: var(--s-3) var(--s-5); align-items: center; }
.filters-row .dates { display: flex; gap: var(--s-2); align-items: center; }
.filters-row .dates .input, .filters-row select.input { height: 34px; width: auto; }
@media (max-width: 640px) {
    .search-row { flex-direction: column; }
    .filters-row .dates, .filters-row select.input { width: 100%; }
    .filters-row .dates .input { flex: 1; }
}
.result { display: block; padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--gray-100); color: inherit; }
.result:last-child { border-bottom: 0; }
.result:hover { background: var(--gray-25); text-decoration: none; color: inherit; }
.result-top { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-3); align-items: center; }
.result-top strong { color: var(--gray-900); font-weight: 600; }
.result-keys { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); margin-top: 6px; font-size: var(--fs-sm); color: var(--gray-600); }
.result-keys b { color: var(--gray-500); font-weight: 500; }
.snippets { margin: var(--s-2) 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.snippets li { font-size: var(--fs-sm); color: var(--gray-600); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snippets .where { display: inline-block; min-width: 76px; color: var(--gray-400); font-size: var(--fs-xs); }
mark { background: #fff1a8; color: inherit; padding: 0 2px; border-radius: 3px; }
.pager { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: space-between; align-items: center; padding: var(--s-3) var(--s-5); border-top: 1px solid var(--gray-100); }
.empty { padding: var(--s-12) var(--s-5); text-align: center; color: var(--gray-500); }
.empty h3 { color: var(--gray-900); font-size: var(--fs-lg); margin-bottom: var(--s-1); }

/* =========================================================================
   Login
   ========================================================================= */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side {
    display: flex; flex-direction: column; justify-content: space-between;
    padding: var(--s-12); color: #cdd5e1;
    background: radial-gradient(1200px 600px at 10% 0%, #23386b 0%, var(--gray-900) 60%);
}
.auth-side .brand { padding: 0; }
.auth-side h2 { color: #fff; font-size: var(--fs-3xl); font-weight: 650; letter-spacing: -.02em; max-width: 440px; }
.auth-side p { margin-top: var(--s-3); max-width: 440px; }
.auth-points { list-style: none; padding: 0; margin: var(--s-8) 0 0; display: grid; gap: var(--s-3); }
.auth-points li { display: flex; gap: var(--s-3); align-items: center; }
.auth-points svg { width: 18px; height: 18px; color: #7ea3ff; flex: none; }
.auth-main { display: grid; place-items: center; padding: var(--s-8) var(--s-5); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: var(--fs-2xl); font-weight: 650; }
.auth-card > p { color: var(--gray-500); margin: var(--s-1) 0 var(--s-6); }
.auth-card form { display: grid; gap: var(--s-4); }
@media (max-width: 900px) {
    .auth { grid-template-columns: 1fr; }
    .auth-side { display: none; }
}

/* toastr tweaks */
#toast-container > div { border-radius: var(--radius); box-shadow: var(--shadow-lg); opacity: 1; font-family: var(--font); }
#toast-container > .toast-success { background-color: var(--green-600); }
#toast-container > .toast-error { background-color: var(--red-600); }
#toast-container > .toast-info { background-color: var(--brand-600); }
#toast-container > .toast-warning { background-color: var(--amber-600); }

/* Bordered dashboard grid */
#documents-table { border-collapse: collapse; border: 1px solid var(--gray-200); }
#documents-table thead th,
#documents-table tbody td { border: 1px solid var(--gray-200); }
#documents-table thead th { border-bottom-color: var(--gray-300); }
#documents-table tbody tr:last-child td { border-bottom: 1px solid var(--gray-200); }
#documents-table .file-link { display: block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--gray-900); font-weight: 550; }
#documents-table td.col-actions, #documents-table th.col-actions { position: static; box-shadow: none; background: transparent; text-align: center; }
#documents-table th.col-actions { background: var(--gray-25); }
@media (min-width: 761px) {
    #documents-table { table-layout: fixed; min-width: 1000px; }
    #documents-table th:nth-child(1) { width: 17%; }
    #documents-table th:nth-child(2) { width: 11%; }
    #documents-table th:nth-child(3) { width: 10%; }
    #documents-table th:nth-child(4) { width: 9%; }
    #documents-table th:nth-child(5) { width: 18%; }
    #documents-table th:nth-child(6) { width: 17%; }
    #documents-table th:nth-child(7) { width: 18%; }
    #documents-table th, #documents-table td { padding-left: 10px; padding-right: 10px; overflow: hidden; text-overflow: ellipsis; }
    #documents-table td.col-file, #documents-table td.col-name, #documents-table td.col-ref { min-width: 0; max-width: none; }
    #documents-table .file-link { max-width: 100%; }
    #documents-table thead th { white-space: normal; overflow: visible; line-height: 1.3; }
    #documents-table td.nowrap { text-overflow: clip; }
}
.table-wrap:has(#documents-table) { padding: var(--s-4) var(--s-5); }
@media (max-width: 760px) {
    #documents-table.stack tbody tr { border: 1px solid var(--gray-200); border-radius: var(--radius); margin-bottom: var(--s-3); }
    #documents-table.stack tbody td { border: 0; border-bottom: 1px solid var(--gray-100); padding: 6px 0; }
    #documents-table.stack tbody td:last-child { border-bottom: 0; }
    #documents-table.stack { border: 0; }
    .table-wrap:has(#documents-table) { padding: var(--s-3); }
    #documents-table .file-link { max-width: none; white-space: normal; word-break: break-word; }
}

/* =========================================================================
   Search options: segmented match type + ON/OFF switches
   ========================================================================= */
.search-options { display: flex; flex-wrap: wrap; gap: var(--s-4) var(--s-8); align-items: flex-start; }
.option-group { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: var(--s-2); }
.option-group legend { padding: 0; margin-bottom: var(--s-2); }
.option-group .hint { font-size: var(--fs-xs); color: var(--gray-500); max-width: 380px; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--gray-100); border: 1px solid var(--gray-200); border-radius: var(--radius); }
.segment { position: relative; cursor: pointer; }
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment span { display: block; padding: 7px 14px; border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 550; color: var(--gray-600); white-space: nowrap; transition: background .15s, color .15s, box-shadow .15s; }
.segment:hover span { color: var(--gray-900); }
.segment input:checked + span { background: #fff; color: var(--brand-600); box-shadow: var(--shadow-sm); }
.segment input:focus-visible + span { box-shadow: var(--ring); }

.switch-list { display: flex; flex-wrap: wrap; gap: var(--s-3) var(--s-6); }
.switch-row { display: inline-flex; align-items: center; gap: var(--s-3); font-weight: 550; color: var(--gray-700); cursor: pointer; user-select: none; }
.switch-row.is-disabled { opacity: .45; cursor: not-allowed; }
.switch { position: relative; display: inline-block; width: 74px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: inherit; z-index: 2; }
.switch-track {
    position: absolute; inset: 0; border-radius: 999px;
    background: linear-gradient(#ff2a1a, #e00000);
    border: 3px solid #d7d9dd;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.25);
    transition: background .2s;
}
.switch-track::before {
    content: "OFF"; position: absolute; top: 50%; right: 9px; transform: translateY(-50%);
    color: #fff; font-size: 13px; font-weight: 800; letter-spacing: .02em;
}
.switch-track::after {
    content: ""; position: absolute; top: 1px; left: 1px; width: 24px; height: 24px; border-radius: 50%;
    background: linear-gradient(#ffffff, #eceef1); border: 1px solid #c9ccd1;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
    transition: transform .2s ease;
}
.switch input:checked + .switch-track { background: linear-gradient(#4ad63a, #22b814); }
.switch input:checked + .switch-track::before { content: "ON"; right: auto; left: 10px; }
.switch input:checked + .switch-track::after { transform: translateX(42px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
@media (max-width: 640px) {
    .segmented { display: flex; width: 100%; }
    .segment { flex: 1; }
    .segment span { text-align: center; padding: 8px 6px; }
    .switch-list { flex-direction: column; }
}

/* =========================================================================
   File explorer — sidebar tree
   ========================================================================= */
.sidebar { position: fixed; }
.sidebar-resizer {
    position: absolute; top: 0; right: -2px; bottom: 0; width: 5px;
    cursor: col-resize; z-index: 61;
}
.sidebar-resizer:hover, body.resizing-sidebar .sidebar-resizer { background: rgba(47,107,234,.5); }
body.resizing-sidebar { cursor: col-resize; user-select: none; }
body.resizing-sidebar .sidebar { transition: none; }

.nav-tree {
    flex: 1;
    min-height: 0;              /* required or it will not scroll inside the flex column */
    overflow-y: auto;
    overflow-x: hidden;
    margin: var(--s-1) calc(var(--s-3) * -1) 0;
    padding: 0 var(--s-2) var(--s-3);
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.18) transparent;
}
.nav-tree::-webkit-scrollbar { width: 8px; }
.nav-tree::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 999px; }
.nav-tree::-webkit-scrollbar-track { background: transparent; }

.tree-node {
    position: relative;
    display: flex; align-items: center; gap: 6px;
    /* fixed line-height keeps the row exactly --tree-row tall, which is what
       the connector elbows are positioned against */
    line-height: 18px;
    padding: 5px var(--s-2) 5px 4px;
    border-radius: var(--radius-sm);
    color: var(--gray-300);
    font-size: var(--fs-sm);
    cursor: pointer;
    user-select: none;
}
.tree-node:hover { background: rgba(255,255,255,.06); color: #fff; }

/* The row you are looking at, and the trail of open folders leading to it. */
.tree-node.selected {
    background: var(--brand-500);
    color: #fff;
    font-weight: 550;
    box-shadow: 0 1px 6px rgba(47, 107, 234, .45);
}
.tree-node.selected:hover { background: var(--brand-500); }
.tree-node.selected .tree-icon,
.tree-node.selected .tree-twisty { color: #fff; }
.tree-node.selected .tree-twisty::before {
    border-color: rgba(255, 255, 255, .75);
    background-color: var(--brand-600);
}
.tree-node.on-path:not(.selected) { color: #fff; }
.tree-node.on-path:not(.selected) .tree-label { font-weight: 550; }
.tree-node:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--brand-500); }
.tree-node.is-empty { color: var(--gray-500); }
.tree-node.is-empty:hover { color: var(--gray-300); }

/* classic boxed [+] / [-] expander */
.tree-twisty {
    display: grid; place-items: center; flex: none;
    width: 18px; height: 18px; padding: 0;
    border: 0; background: none; color: var(--gray-300);
    cursor: pointer;
    position: relative; z-index: 1;      /* sits on top of the guide lines */
}
.tree-twisty::before {
    content: "";
    width: 11px; height: 11px;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 2px;
    background-color: var(--gray-900);
    /* the two strokes of the plus */
    background-image:
        linear-gradient(currentColor, currentColor),
        linear-gradient(currentColor, currentColor);
    background-size: 5px 1px, 1px 5px;
    background-position: center, center;
    background-repeat: no-repeat;
}
.tree-node[aria-expanded="true"] > .tree-twisty::before {
    /* expanded: drop the vertical stroke, leaving a minus */
    background-image: linear-gradient(currentColor, currentColor);
    background-size: 5px 1px;
}
.tree-twisty:hover { color: #fff; }
.tree-twisty:hover::before { border-color: rgba(255,255,255,.7); }
.tree-twisty.is-leaf { cursor: default; pointer-events: none; }
.tree-twisty.is-leaf::before { content: none; }

.tree-icon { display: grid; place-items: center; flex: none; width: 18px; height: 18px; color: var(--brand-200); }
.tree-icon svg { width: 16px; height: 16px; }
.tree-icon .ico-open { display: none; }
.tree-node[aria-expanded="true"] > .tree-icon .ico-closed { display: none; }
.tree-node[aria-expanded="true"] > .tree-icon .ico-open { display: block; }
.tree-node.is-empty .tree-icon { color: var(--gray-600); }

.tree-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-node .count {
    margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px;
    background: rgba(255,255,255,.1); color: var(--gray-300);
    font-size: 10px; line-height: 18px; text-align: center; flex: none;
}
.tree-node.selected .count { background: rgba(255,255,255,.2); color: #fff; }

/* Dotted connector lines. The vertical run sits on the whole branch, so it
   carries past a node's own expanded children; the elbow sits on the row.
   The last branch's run stops half a row down, ending in an L rather than a
   line dangling past the final item. Works at any depth. */
.tree-children {
    padding-left: 16px;
}
.tree-children > .tree-branch { position: relative; }
.tree-children > .tree-branch::before {
    content: "";
    position: absolute;
    left: 13px; top: 0; bottom: 0;
    border-left: 1px dotted rgba(255, 255, 255, .32);
}
.tree-children > .tree-branch:last-child::before {
    bottom: auto;
    height: calc(var(--tree-row) / 2);
}
.tree-children > .tree-branch > .tree-node::after {
    content: "";
    position: absolute;
    left: 13px; top: 50%;
    width: 14px;
    border-top: 1px dotted rgba(255, 255, 255, .32);
}

/* file rows */
.tree-node.is-file { color: var(--gray-400); }
.tree-node.is-file:hover { color: #fff; text-decoration: none; }
.tree-node.is-file.selected { color: #fff; }
.tree-node.is-file.selected .tree-file { background: rgba(255, 255, 255, .28); color: #fff; }
.tree-file {
    display: grid; place-items: center; flex: none;
    width: 18px; height: 18px;
    border-radius: 2px;
    background: rgba(255, 255, 255, .08);
    color: var(--gray-300);
    font-size: 8px; font-weight: 700; text-transform: uppercase;
    letter-spacing: -.02em;
}
.tree-node.is-file:hover .tree-file { background: rgba(255, 255, 255, .16); color: #fff; }
.tree-more { color: var(--gray-500); font-style: italic; }
.tree-more:hover { color: var(--brand-200); text-decoration: none; }
.tree-loading, .tree-empty { padding: var(--s-2) var(--s-3); color: var(--gray-500); }
.tree-empty a { color: var(--brand-200); }

/* =========================================================================
   File explorer — address bar and panes
   ========================================================================= */
.explorer { display: flex; flex-direction: column; gap: var(--s-4); }

.explorer-bar {
    display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap;
    padding: var(--s-2);
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.explorer-nav { display: flex; gap: 2px; flex: none; }
.explorer-btn {
    display: grid; place-items: center; width: 32px; height: 32px; flex: none;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: none; color: var(--gray-600); cursor: pointer;
}
.explorer-btn:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.explorer-btn svg { width: 17px; height: 17px; }
.explorer-btn[aria-pressed="true"] { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-700); }
.explorer-btn.is-disabled { opacity: .4; pointer-events: none; }

.explorer-address {
    display: flex; align-items: center; gap: var(--s-2);
    flex: 1 1 260px; min-width: 0;
    height: 34px; padding: 0 var(--s-2);
    background: var(--gray-25);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
}
.explorer-address:focus-within { border-color: var(--brand-500); box-shadow: var(--ring); }
.address-icon { display: grid; place-items: center; flex: none; color: var(--brand-600); }
.address-icon svg { width: 16px; height: 16px; }
.explorer-crumbs {
    display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0;
    overflow: hidden; white-space: nowrap; font-size: var(--fs-sm);
}
.explorer-crumbs a {
    padding: 2px 6px; border-radius: 4px;
    color: var(--gray-700); text-decoration: none;
}
.explorer-crumbs a:hover { background: var(--gray-100); color: var(--gray-900); }
.explorer-crumbs a:last-child { font-weight: 600; color: var(--gray-900); }
.explorer-crumbs .sep { color: var(--gray-400); flex: none; }
.address-input {
    flex: 1; min-width: 0; height: 100%;
    border: 0; background: none; outline: none;
    font-family: var(--font); font-size: var(--fs-sm); color: var(--gray-900);
}
.address-edit { width: 26px; height: 26px; }
.address-edit svg { width: 14px; height: 14px; }

.explorer-search { flex: 0 1 240px; min-width: 160px; }
.explorer-views { display: flex; gap: 2px; flex: none; }

.explorer-pane { overflow: hidden; }
.explorer-status { padding: 0 var(--s-1); }

/* icon view */
.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: var(--s-3);
    padding: var(--s-4);
}
.file-tile {
    display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
    padding: var(--s-4) var(--s-2);
    border: 1px solid transparent; border-radius: var(--radius);
    color: var(--gray-700); text-align: center;
}
.file-tile:hover { background: var(--brand-50); border-color: var(--brand-200); text-decoration: none; }
.file-tile .file-icon { width: 44px; height: 52px; font-size: 11px; }
.file-tile-name {
    font-size: var(--fs-sm); color: var(--gray-800); line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    word-break: break-word;
}
.file-tile-meta { font-size: var(--fs-xs); color: var(--gray-500); }
.empty-note { padding: var(--s-10) var(--s-4); text-align: center; grid-column: 1 / -1; }

/* right-click menu */
.ctx-menu {
    position: absolute; z-index: 80; min-width: 190px; padding: 5px;
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.ctx-menu button {
    display: block; width: 100%; padding: 7px var(--s-3);
    border: 0; border-radius: var(--radius-sm); background: none;
    font: inherit; font-size: var(--fs-sm); color: var(--gray-800);
    text-align: left; cursor: pointer;
}
.ctx-menu button:hover { background: var(--brand-50); color: var(--brand-700); }
.ctx-menu button.danger { color: var(--red-600); }
.ctx-menu button.danger:hover { background: var(--red-50); }
.ctx-sep { height: 1px; margin: 4px 0; background: var(--gray-100); }

@media (max-width: 860px) {
    .explorer-bar { gap: var(--s-2); }
    .explorer-address { flex-basis: 100%; order: 3; }
    .explorer-search { flex: 1 1 auto; }
}

/* file-type tints for the icon tiles */
.file-icon.pdf { background: var(--red-50); color: var(--red-600); }
.file-icon.doc { background: var(--blue-50); color: var(--blue-600); }
.file-icon.img { background: var(--green-50); color: var(--green-600); }
.file-icon.other { background: var(--gray-100); color: var(--gray-600); }

/* folder view — a folder shows its sub-folders, like Explorer */
.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
    gap: var(--s-3);
    padding: var(--s-4);
}
.folder-tile {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border: 1px solid var(--gray-200); border-radius: var(--radius);
    background: #fff; color: var(--gray-800);
    transition: background .15s ease, border-color .15s ease;
}
.folder-tile-icon { grid-row: 1 / span 2; }
.folder-tile-name { grid-column: 2; align-self: end; }
.folder-tile-meta { grid-column: 2; align-self: start; }
.folder-tile:hover {
    background: var(--brand-50); border-color: var(--brand-200);
    text-decoration: none;
}
.folder-tile-icon {
    display: grid; place-items: center; flex: none;
    width: 40px; height: 40px;
    color: var(--brand-500);
}
.folder-tile-icon svg { width: 30px; height: 30px; }
.folder-tile-name {
    font-weight: 550; font-size: var(--fs-md); line-height: 1.25;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.folder-tile-meta { font-size: var(--fs-xs); color: var(--gray-500); }
