/* voitta-image-rag — Apple-flavoured UI, lifted from voitta-rag's palette. */

:root {
    --color-bg: #f5f5f7;
    --color-bg-elevated: #ffffff;
    --color-bg-hover: #e8e8ed;
    --color-text-primary: #1d1d1f;
    --color-text-secondary: #86868b;
    --color-text-tertiary: #aeaeb2;
    --color-accent: #0071e3;
    --color-accent-hover: #0077ed;
    --color-border: #d2d2d7;
    --color-border-light: #e5e5ea;
    --color-success: #34c759;
    --color-error: #ff3b30;
    --color-warning: #ff9500;

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
        "Helvetica Neue", Helvetica, Arial, sans-serif;

    --xs: 4px;
    --sm: 8px;
    --md: 16px;
    --lg: 24px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --t: 150ms ease;
}

[data-theme="dark"] {
    --color-bg: #1d1d1f;
    --color-bg-elevated: #2c2c2e;
    --color-bg-hover: #3a3a3c;
    --color-text-primary: #f5f5f7;
    --color-text-secondary: #a1a1a6;
    --color-text-tertiary: #636366;
    --color-accent: #0a84ff;
    --color-accent-hover: #409cff;
    --color-border: #3a3a3c;
    --color-border-light: #48484a;
}

* { box-sizing: border-box; }

/* Re-assert the [hidden] attribute against display:flex/grid rules below. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text-primary);
    font: 13px/1.4 var(--font);
    -webkit-font-smoothing: antialiased;
    /* Vertical flex so the main pane fills exactly the remaining viewport
       under the sticky header — lets the folder list scroll internally
       instead of pushing the page below the fold. */
    display: flex;
    flex-direction: column;
}

/* ---------- Header ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border-light);
}
.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    max-width: 1600px;
    margin: 0 auto;
}
.logo {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-text-primary);
    text-decoration: none;
}
.header-actions { display: flex; align-items: center; gap: 12px; }

.status-pill {
    display: inline-flex;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
    text-transform: lowercase;
}
.status-pill.connected {
    background: rgba(52, 199, 89, 0.15);
    color: var(--color-success);
}
.status-pill.disconnected {
    background: rgba(255, 59, 48, 0.15);
    color: var(--color-error);
}

/* ---------- Layout ---------- */

.app-main {
    /* Fill the height left by the sticky app header so children can claim
       their share of the viewport with min-height:0 + flex:1. Without
       min-height:0 a flex child refuses to shrink below its intrinsic
       content size and the grid below would force the whole page to scroll. */
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--lg);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    /* Box-sizing safety: padding shouldn't make us overflow. */
    box-sizing: border-box;
}
.browser-container {
    display: flex;
    flex-direction: column;
    gap: var(--md);
    flex: 1;
    min-height: 0;
}
.toolbar {
    display: flex;
    gap: var(--sm);
    align-items: center;
    flex-wrap: wrap;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
}
.toolbar-group { display: flex; gap: 6px; align-items: center; }
.toolbar-divider {
    width: 1px;
    height: 22px;
    background: var(--color-border);
    margin: 0 4px;
}
.upload-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    min-width: 220px;
}
.upload-progress-label {
    font-size: 11px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}
.upload-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    width: 0;
    background: var(--color-accent);
    transition: width 100ms linear;
}
.browser-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: var(--lg);
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sm);
    padding: 8px 16px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--t), color var(--t);
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-accent-hover); }

.btn-secondary {
    background: var(--color-bg-elevated);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-bg-hover); }

.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c82333; }

.btn-text {
    background: transparent;
    color: var(--color-accent);
    padding: 4px 8px;
    font: inherit;
    font-size: 12px;
    border: none;
    cursor: pointer;
}
.btn-text:hover { text-decoration: underline; }

input[type="text"], input[type="file"] {
    background: var(--color-bg);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font: inherit;
    width: 100%;
}

/* ---------- Folder list ---------- */

/* Container fills its grid cell vertically and turns into a flex column
   so the head row pins to the top while the <ul> below scrolls. */
.folder-list-container {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* One source of truth for the column layout — every row (head + body)
   uses this so header text aligns with cell content. Switch columns are
   locked to a fixed width to keep alignment predictable. */
:root {
    /* name · files · indexed · status · search · share */
    --tree-cols: 1fr 56px 64px 100px 56px 56px;
    --tree-gap: 10px;
    --tree-pad-x: 16px;
}
/* Depth indentation lives as padding-left on the .name-cell (see main.js).
   That keeps chevron + glyph + label moving together as a unit while the
   metadata columns to the right stay aligned with the column header. */
.tree-row .name-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    min-width: 0;
}

.tree-head {
    display: grid;
    grid-template-columns: var(--tree-cols);
    gap: var(--tree-gap);
    padding: 8px var(--tree-pad-x);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    flex-shrink: 0;
    /* The ul is a separate scroll container, so this row doesn't need
       position:sticky — but keep a subtle shadow when content scrolls
       under it for visual continuity. */
    position: relative;
    z-index: 1;
}
.tree-head .num { text-align: right; }
.tree-head .center { text-align: center; }

.tree {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    /* Hide horizontal scroll-bars on tight viewports — the toggle column
       widths are fixed, so there's no horizontal overflow to expose. */
    overflow-x: hidden;
}
.tree-row {
    display: grid;
    grid-template-columns: var(--tree-cols);
    align-items: center;
    gap: var(--tree-gap);
    padding: 5px var(--tree-pad-x);
    border-bottom: 1px solid var(--color-border-light);
    cursor: pointer;
    transition: background var(--t);
    user-select: none;
}
/* Read-only shared folders (someone else owns them) get a left-edge accent
   so they stand out from your own. The accent persists even when selected. */
.tree-row.folder-root.shared-readonly {
    border-left: 3px solid var(--color-accent);
    padding-left: 13px;
    background: linear-gradient(
        to right,
        color-mix(in srgb, var(--color-accent) 6%, transparent),
        transparent 40%
    );
}
.tree-row.folder-root.shared-readonly.selected {
    background: var(--color-accent);
}

/* "Sign in with Google" button — matches Google's Identity Branding
   guidelines (https://developers.google.com/identity/branding-guidelines):
   white surface, 1px #dadce0 border, four-colour G mark, Roboto-style
   label. We render a real <a>, not an iframe widget, because we just need
   to send the user to /api/auth/login/google — no client-side SDK. */
.gsi-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    padding: 0 16px;
    height: 40px;
    min-width: 220px;
    background: #ffffff;
    border: 1px solid #dadce0;
    border-radius: 4px;
    color: #1f1f1f;
    font-family: "Google Sans", "Roboto", -apple-system, BlinkMacSystemFont,
        "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.25px;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow 120ms ease, background 120ms ease;
    /* Subtle Material-style elevation that lifts on hover. */
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.06),
                0 1px 3px 1px rgba(60, 64, 67, 0.04);
}
.gsi-button:hover {
    background: #f8faff;
    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.10),
                0 2px 6px 2px rgba(60, 64, 67, 0.08);
}
.gsi-button:active {
    background: #f1f3f4;
    box-shadow: 0 1px 1px rgba(60, 64, 67, 0.10);
}
.gsi-button:focus-visible {
    outline: 2px solid #4285F4;
    outline-offset: 2px;
}
.gsi-button-icon {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}
.gsi-button-label {
    line-height: 1;
}
/* Dark theme: invert to the Google "filled blue" variant — same brand
   guidelines, white G on a #131314 surface with reduced opacity. */
[data-theme="dark"] .gsi-button {
    background: #131314;
    border-color: #8e918f;
    color: #e3e3e3;
}
[data-theme="dark"] .gsi-button:hover {
    background: #1a1b1d;
    border-color: #ffffff;
}
[data-theme="dark"] .gsi-button:active {
    background: #232427;
}

/* Segmented tabs (e.g. Google Drive auth-mode picker). Two-button row
   styled like an iOS segmented control: the active segment gets the
   accent fill, hover dims the inactive side. Picked over a select-box
   because the choices change which fields render below — visible options
   make that consequence obvious without a dropdown click. */
.seg-tabs {
    display: inline-flex;
    margin: 6px 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    padding: 2px;
    gap: 2px;
}
.seg-tab {
    padding: 6px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: transparent;
    border: none;
    border-radius: calc(var(--radius-md) - 2px);
    cursor: pointer;
    transition: background var(--t), color var(--t);
}
.seg-tab:hover:not(.active) {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}
.seg-tab.active {
    background: var(--color-accent);
    color: #fff;
}

/* Compact iOS-style toggle switch used for the per-folder Active and Share
   flags. Built around an unstyled checkbox so screen readers and keyboard
   navigation work for free. */
.folder-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}
.folder-switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.folder-switch .track {
    position: absolute;
    inset: 0;
    background: var(--color-text-tertiary);
    border-radius: 9px;
    transition: background var(--t);
    pointer-events: none;
}
.folder-switch .track::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform 120ms ease;
}
.folder-switch input:checked + .track {
    background: var(--color-accent);
}
.folder-switch input:checked + .track::before {
    transform: translateX(14px);
}
.folder-switch input:disabled + .track {
    opacity: 0.4;
    cursor: not-allowed;
}
.folder-switch input:disabled {
    cursor: not-allowed;
}
.tree-row:last-child { border-bottom: none; }
.tree-row:hover { background: var(--color-bg-hover); }
.tree-row.selected,
.tree-row.selected:hover { background: var(--color-accent); color: #fff; }
.tree-row.selected .num,
.tree-row.selected .label,
.tree-row.selected .chevron { color: #fff; }
.tree-row.selected .glyph { color: #fff; }

/* Legacy indent span — unused since depth moved to label padding-left.
   Kept hidden in case any cached JS still emits it. */
.tree-row .indent { display: none; }
.tree-row .chevron {
    width: 14px;
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 10px;
    transition: transform 120ms ease;
}
.tree-row .chevron.open { transform: rotate(90deg); }
.tree-row .chevron.leaf { visibility: hidden; }
.tree-row .label {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    font-size: 13px;
}
.tree-row .label .glyph { flex-shrink: 0; font-size: 14px; }
.tree-row.folder-root .label .glyph,
.tree-row.dir .label .glyph { color: var(--color-accent); }
.tree-row.file .label { color: var(--color-text-secondary); }
.tree-row.file .label .glyph { color: var(--color-text-tertiary); }

.tree-row .num {
    text-align: right;
    font-size: 12px;
    color: var(--color-text-secondary);
}

/* Status pill: smaller and quieter inside tree rows. */
.tree-row .status-tag {
    min-width: auto;
    font-size: 10px;
    padding: 1px 8px;
    text-transform: lowercase;
}
.tree-row.selected .status-tag {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* ---------- Status pills ---------- */

.status-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 90px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.status-tag.indexed { background: rgba(52, 199, 89, 0.15); color: var(--color-success); }
.status-tag.indexing,
.status-tag.embedding,
.status-tag.extracting,
.status-tag.extracted {
    background: rgba(0, 113, 227, 0.15);
    color: var(--color-accent);
}
.status-tag.pending { background: rgba(255, 149, 0, 0.15); color: var(--color-warning); }
.status-tag.error { background: rgba(255, 59, 48, 0.15); color: var(--color-error); }
.status-tag.unsupported,
.status-tag.deleted,
.status-tag.none {
    background: rgba(142, 142, 147, 0.18);
    color: var(--color-text-secondary);
}

/* ---------- Sidebar ---------- */

.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--md);
    /* Match the folder-list pattern: the sidebar is a grid cell with
       height already fixed by the layout above, so it just needs to scroll
       internally when its sections (extension table, kv-grid) overflow. */
    min-height: 0;
    overflow-y: auto;
}
.sidebar-section {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--lg);
}
.sidebar-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 var(--md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-actions-inline { display: flex; gap: 4px; }

.sidebar-empty { text-align: center; }
.hint, .hint-large { color: var(--color-text-secondary); }
.hint { font-size: 11px; margin: 0; }
.hint-large { font-size: 13px; }

#folder-detail h3 {
    font-size: 17px;
    color: var(--color-text-primary);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 600;
    margin: 0 0 4px;
    display: block;
}
.path {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: var(--color-text-secondary);
    word-break: break-all;
    margin: 0 0 var(--md);
}
.badge-row { display: flex; gap: 6px; margin-bottom: var(--md); }
.badge {
    background: rgba(142, 142, 147, 0.18);
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}
.kv-grid {
    display: grid;
    grid-template-columns: 90px 1fr;
    row-gap: 6px;
    margin-bottom: var(--md);
    font-size: 12px;
}
.kv-grid .k { color: var(--color-text-secondary); }
.kv-grid .v { font-weight: 500; }

.actions { display: flex; gap: 8px; }
.actions-right { justify-content: flex-end; }

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: var(--md);
}
.stats-table th {
    text-align: left;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.05em;
    padding: 4px 0;
    border-bottom: 1px solid var(--color-border-light);
}
.stats-table th.num,
.stats-table td.num { text-align: right; }
.stats-table td {
    padding: 4px 0;
    border-bottom: 1px solid var(--color-border-light);
}
.stats-table tr:last-child td { border-bottom: none; }
.stats-table .ext { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* Per-extension row coloring in the by-extension table.
   Tints are subtle so the table still scans as a list, not a heatmap. */
.stats-table tr.ext-error td      { color: var(--color-error); }
.stats-table tr.ext-error .ext    { color: var(--color-error); }
.stats-table tr.ext-unsupported td { color: var(--color-text-secondary); font-style: italic; }
.stats-table tr.ext-pending td    { color: var(--color-warning); }
.stats-table tr.ext-indexed td    { color: var(--color-text); }

.file-rows, .job-rows {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 280px;
    overflow-y: auto;
}
.file-rows li, .job-rows li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 12px;
}
.file-rows li:last-child, .job-rows li:last-child { border-bottom: none; }
.file-rows .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.job-rows .col { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.job-rows .meta { color: var(--color-text-tertiary); font-size: 11px; }
.job-rows .err { color: var(--color-error); font-size: 11px; word-break: break-word; }
.job-rows .retry {
    background: transparent;
    border: 1px solid var(--color-accent);
    color: var(--color-accent);
    border-radius: var(--radius-sm);
    font-size: 11px;
    padding: 2px 8px;
    cursor: pointer;
}
.job-rows .retry:hover { background: var(--color-accent); color: #fff; }

#upload-card .btn,
#upload-card input { margin-top: 8px; }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal {
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    width: min(92vw, 520px);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}
.modal.modal-wide { width: min(94vw, 720px); }
.modal-body input[type="text"],
.modal-body input[type="password"],
.modal-body select,
.modal-body textarea {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    color: var(--color-text);
    font: inherit;
    width: 100%;
    box-sizing: border-box;
}
.modal-body textarea { font: 12px ui-monospace, "SF Mono", Menlo, monospace; resize: vertical; }
.modal-body select[multiple] { padding: 4px; }
.modal-body .radio-row,
.modal-body .branches-row,
.modal-body .check-row {
    display: flex;
    align-items: center;
    gap: var(--md);
    flex-wrap: wrap;
}
.modal-body .radio-row label,
.modal-body .check-row label,
.modal-body .branches-row label {
    text-transform: none;
    color: var(--color-text);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--md) var(--lg);
    border-bottom: 1px solid var(--color-border-light);
}
.modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body {
    padding: var(--lg);
    display: flex;
    flex-direction: column;
    gap: var(--md);
    overflow-y: auto;
}
.modal-body label {
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.agpl-footer {
    padding: var(--md);
    text-align: center;
    font-size: 12px;
    color: var(--color-text-tertiary);
    border-top: 1px solid var(--color-border-light);
    margin-top: var(--lg);
}
.agpl-footer a { color: var(--color-text-secondary); text-decoration: none; }
.agpl-footer a:hover { color: var(--color-accent); }
