/* ====================================================================
   Doxis — light enterprise UI
   Inspired by Linear, Stripe, Vercel (light mode)
   ==================================================================== */

:root {
    /* Neutrals (slate scale) */
    --bg-app: #F6F7F9;
    --bg-surface: #FFFFFF;
    --bg-surface-2: #F9FAFB;
    --bg-surface-3: #F3F4F6;
    --bg-hover: #F3F4F6;
    --bg-sidebar: #FFFFFF;

    --border: #E5E7EB;
    --border-strong: #D1D5DB;
    --border-focus: rgba(79, 70, 229, 0.25);

    --text-primary: #111827;
    --text-secondary: #4B5563;
    --text-tertiary: #6B7280;
    --text-quaternary: #9CA3AF;

    /* Accent (indigo) */
    --accent: #4F46E5;
    --accent-hover: #4338CA;
    --accent-muted: #EEF2FF;
    --accent-muted-text: #4338CA;

    --success: #059669;
    --success-muted: #D1FAE5;
    --success-muted-text: #065F46;

    --warning: #D97706;
    --warning-muted: #FEF3C7;
    --warning-muted-text: #92400E;

    --danger: #DC2626;
    --danger-muted: #FEE2E2;
    --danger-muted-text: #991B1B;

    /* File type tints */
    --pdf-bg: #FEE2E2;     --pdf-fg: #B91C1C;
    --excel-bg: #D1FAE5;   --excel-fg: #047857;
    --word-bg: #DBEAFE;    --word-fg: #1D4ED8;
    --image-bg: #FEF3C7;   --image-fg: #B45309;
    --text-bg: #E5E7EB;    --text-fg: #374151;
    --generic-bg: #EDE9FE; --generic-fg: #6D28D9;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 14px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
    --shadow-md: 0 1px 3px rgba(17, 24, 39, 0.06), 0 1px 2px rgba(17, 24, 39, 0.04);
    --shadow-lg: 0 10px 20px rgba(17, 24, 39, 0.08), 0 4px 6px rgba(17, 24, 39, 0.04);
    --shadow-drawer: -8px 0 40px rgba(17, 24, 39, 0.1);

    /* Fonts */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

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

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }
code { font-family: var(--font-mono); font-size: 12px; }

/* ====================================================================
   Layout shell
   ==================================================================== */

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 18px 12px;
    gap: 2px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}
.sidebar__logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: white;
    letter-spacing: -0.02em;
    box-shadow: 0 1px 3px rgba(79, 70, 229, 0.25);
}
.sidebar__name { font-weight: 600; font-size: 14px; color: var(--text-primary); line-height: 1.15; letter-spacing: -0.01em; }
.sidebar__name-sub { font-size: 11px; color: var(--text-tertiary); letter-spacing: 0.03em; text-transform: uppercase; margin-top: 2px; }

.sidebar__section-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-quaternary);
    padding: 12px 10px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13px;
    transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.is-active {
    background: var(--accent-muted);
    color: var(--accent-muted-text);
    font-weight: 600;
}
.nav-item.is-active svg { color: var(--accent); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-quaternary); }

.sidebar__footer {
    margin-top: auto;
    padding: 10px;
    font-size: 11px;
    color: var(--text-quaternary);
}

/* ====================================================================
   Main content
   ==================================================================== */

.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg-app); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 20px;
    min-height: 64px;
}
.topbar__title { font-size: 16px; font-weight: 600; color: var(--text-primary); letter-spacing: -0.01em; line-height: 1.25; }
.topbar__sub { font-size: 13px; color: var(--text-tertiary); margin-top: 2px; }
.topbar__actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.content { padding: 24px 28px 40px; max-width: 1400px; width: 100%; flex: 1; }

/* Flash messages (toasts) */
.toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: slide-in 0.18s ease-out;
}
.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--warning { border-left: 3px solid var(--warning); }
@keyframes slide-in { from { transform: translateX(8px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ====================================================================
   Buttons
   ==================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13px;
    line-height: 1.3;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    cursor: pointer;
    transition: all 0.12s;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--bg-surface-2); border-color: var(--text-quaternary); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--border-focus); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; background: var(--bg-surface-2); }

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 1px 2px rgba(79, 70, 229, 0.3);
}
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn--ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: transparent; }

.btn--sm { padding: 5px 9px; font-size: 12px; }
.btn--danger { color: var(--danger); border-color: var(--border-strong); background: var(--bg-surface); }
.btn--danger:hover:not(:disabled) { background: var(--danger-muted); border-color: var(--danger); color: var(--danger-muted-text); }
.btn--icon { padding: 6px; width: 30px; height: 30px; }
.btn svg { width: 14px; height: 14px; }

/* ====================================================================
   Cards
   ==================================================================== */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card__header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.card__title { font-weight: 600; font-size: 14px; color: var(--text-primary); letter-spacing: -0.005em; }
.card__sub { font-size: 13px; color: var(--text-tertiary); margin-top: 2px; }
.card__body { padding: 20px; }
.card__body--tight { padding: 0; }

/* ====================================================================
   Metric cards
   ==================================================================== */

.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.metric {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    padding: 18px 20px;
    position: relative;
}
.metric__label {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; font-weight: 500; color: var(--text-tertiary);
    margin-bottom: 12px; letter-spacing: 0.01em;
}
.metric__label-icon {
    width: 26px; height: 26px; border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-muted); color: var(--accent);
}
.metric__label-icon svg { width: 14px; height: 14px; }
.metric__value {
    font-size: 28px; font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--text-primary); line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.metric__hint { font-size: 12px; color: var(--text-tertiary); margin-top: 8px; }

.metric--success .metric__label-icon { background: var(--success-muted); color: var(--success); }
.metric--warning .metric__label-icon { background: var(--warning-muted); color: var(--warning); }
.metric--info    .metric__label-icon { background: var(--accent-muted); color: var(--accent); }

@media (max-width: 1100px) { .metrics { grid-template-columns: repeat(2, 1fr); } }

/* ====================================================================
   Tables
   ==================================================================== */

.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data thead th {
    background: var(--bg-surface-2);
    color: var(--text-tertiary);
    font-weight: 500;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data tbody td {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--bg-surface-2); }
table.data tbody tr[data-controller*="file-row"] { cursor: pointer; }

.td-file {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.file-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    background: var(--generic-bg);
    color: var(--generic-fg);
}
.file-icon--pdf { background: var(--pdf-bg); color: var(--pdf-fg); }
.file-icon--xls, .file-icon--xlsx { background: var(--excel-bg); color: var(--excel-fg); }
.file-icon--doc, .file-icon--docx { background: var(--word-bg); color: var(--word-fg); }
.file-icon--png, .file-icon--jpg, .file-icon--jpeg, .file-icon--gif { background: var(--image-bg); color: var(--image-fg); }
.file-icon--txt { background: var(--text-bg); color: var(--text-fg); }
.file-icon--sm { width: 28px; height: 28px; font-size: 9px; border-radius: 6px; }

.file-name { font-weight: 500; color: var(--text-primary); font-size: 13.5px; }
.file-path {
    font-size: 11.5px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    margin-top: 1px;
    max-width: 420px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.company-cell { display: flex; flex-direction: column; gap: 1px; }
.company-cell strong { color: var(--text-primary); font-weight: 500; }
.company-cell small { color: var(--text-tertiary); font-size: 11.5px; font-family: var(--font-mono); }

.size-cell { color: var(--text-tertiary); font-variant-numeric: tabular-nums; font-size: 12.5px; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    background: var(--bg-surface-3);
    color: var(--text-secondary);
}
.badge--info { background: var(--accent-muted); color: var(--accent-muted-text); }
.badge--success { background: var(--success-muted); color: var(--success-muted-text); }
.badge--warning { background: var(--warning-muted); color: var(--warning-muted-text); }
.badge--danger { background: var(--danger-muted); color: var(--danger-muted-text); }
.badge--dot::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ====================================================================
   Forms
   ==================================================================== */

.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field__label { display: block; font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 6px; }
.field__hint { display: block; font-size: 12.5px; color: var(--text-tertiary); margin-top: 6px; }

.input {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.35;
    transition: border-color 0.12s, box-shadow 0.12s;
    box-shadow: var(--shadow-sm);
}
.input::placeholder { color: var(--text-quaternary); }
.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus);
}

.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }

/* Toggle switch */
.toggle { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; cursor: pointer; user-select: none; border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: none; padding-bottom: 0; }
.toggle:first-child { padding-top: 0; }
.toggle input { display: none; }
.toggle__track {
    width: 34px; height: 20px;
    background: var(--border-strong);
    border-radius: 999px;
    position: relative;
    transition: background 0.15s;
    flex-shrink: 0;
    margin-top: 2px;
}
.toggle__track::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 16px; height: 16px;
    border-radius: 50%; background: white;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle input:checked + .toggle__track { background: var(--accent); }
.toggle input:checked + .toggle__track::after { transform: translateX(14px); }
.toggle__text { font-size: 13.5px; color: var(--text-primary); font-weight: 500; line-height: 1.3; }
.toggle__hint { font-size: 12.5px; color: var(--text-tertiary); display: block; margin-top: 4px; font-weight: 400; line-height: 1.4; }

/* ====================================================================
   Segmented control
   ==================================================================== */

.segmented {
    display: inline-flex;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 2px;
    box-shadow: var(--shadow-sm);
}
.segmented button {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.12s;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button.is-active {
    background: var(--bg-surface-3);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}
.segmented svg { width: 13px; height: 13px; }

/* ====================================================================
   Tree view
   ==================================================================== */

.tree { padding: 4px 0; font-size: 13px; }

.tree-section {
    border-bottom: 1px solid var(--border);
}
.tree-section:last-child { border-bottom: none; }

.tree-company {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
.tree-company__icon {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
    letter-spacing: 0.02em;
}
.tree-company__name { font-size: 14px; color: var(--text-primary); }
.tree-company__id {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-tertiary);
    padding: 2px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-weight: 500;
}
.tree-company__count { margin-left: auto; font-size: 12px; color: var(--text-tertiary); font-weight: 500; }

.tree-folder {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 20px 9px 44px;
    color: var(--text-primary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.tree-folder::before {
    content: ''; position: absolute;
    left: 30px; top: 18px;
    width: 8px; height: 1px;
    background: var(--border-strong);
}
.tree-folder svg { width: 16px; height: 16px; color: var(--text-quaternary); flex-shrink: 0; }
.tree-folder__name { font-size: 13px; }
.tree-folder__count { margin-left: auto; font-size: 11.5px; color: var(--text-tertiary); font-weight: 400; font-variant-numeric: tabular-nums; }

.tree-files { background: var(--bg-surface); }
.tree-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px 8px 68px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.12s;
    position: relative;
}
.tree-file:last-child { border-bottom: none; }
.tree-file:hover { background: var(--bg-surface-2); }
.tree-file::before {
    content: ''; position: absolute;
    left: 54px; top: 20px;
    width: 8px; height: 1px;
    background: var(--border-strong);
}
.tree-file__name { font-size: 13px; color: var(--text-primary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-file__size { font-size: 11.5px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* Direct files under company (no subfolder) */
.tree-file--direct { padding-left: 44px; }
.tree-file--direct::before { left: 30px; }

/* ====================================================================
   Drawer
   ==================================================================== */

.drawer-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.drawer-overlay.is-open { display: block; opacity: 1; }

.drawer {
    position: fixed;
    top: 0; right: 0;
    width: 480px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-drawer);
    display: flex;
    flex-direction: column;
    z-index: 101;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer-overlay.is-open .drawer { transform: translateX(0); }

.drawer__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.drawer__title { display: flex; gap: 12px; align-items: center; min-width: 0; }
.drawer__title h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer__body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.drawer__footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: var(--bg-surface-2);
}

.detail-section { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.detail-row {}
.detail-label {
    font-size: 11.5px; font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 4px;
}
.detail-value { font-size: 13px; color: var(--text-primary); word-break: break-all; }
.detail-value--mono { font-family: var(--font-mono); font-size: 12px; }

.detail-path-box {
    padding: 10px 12px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-secondary);
    word-break: break-all;
    line-height: 1.5;
}

/* ====================================================================
   Page headers and empty states
   ==================================================================== */

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header__text h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; color: var(--text-primary); margin: 0; }
.page-header__text p { margin: 4px 0 0; color: var(--text-tertiary); font-size: 13.5px; }

.empty { text-align: center; padding: 56px 24px; }
.empty__icon {
    width: 56px; height: 56px; border-radius: var(--radius-xl);
    background: var(--accent-muted);
    color: var(--accent);
    margin: 0 auto 16px;
    display: flex; align-items: center; justify-content: center;
}
.empty__icon svg { width: 26px; height: 26px; }
.empty h3 { color: var(--text-primary); font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.empty p { color: var(--text-tertiary); font-size: 13.5px; margin: 0 0 20px; max-width: 380px; margin-left: auto; margin-right: auto; line-height: 1.5; }

/* ====================================================================
   Helpers
   ==================================================================== */

.kbd-path {
    display: inline-flex; align-items: center; gap: 6px;
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-tertiary);
    padding: 4px 10px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row--between { justify-content: space-between; }

.title-block h2 { font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 0; }
.title-block p { font-size: 13px; color: var(--text-tertiary); margin: 2px 0 0; }
