:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b2330;
  --muted: #5d6878;
  --faint: #5f6a7a;
  --line: #e3e7ed;
  --line-strong: #cfd6df;
  --accent: #1f5fae;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fa;
  --mark: #fff1b8;
  --danger: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
[hidden] { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: 500 14px var(--font); text-decoration: none;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f1f4f8; }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible, .result-title:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #194f92; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: #eef1f5; color: var(--text); }
.btn-wide { width: 100%; height: 44px; font-size: 15px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Sign in */
.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 36px 32px; box-shadow: var(--shadow); text-align: center;
}
.login-mark { display: block; margin: 0 auto 16px; }
.login-card h1 { font-size: 22px; margin-bottom: 8px; }
.login-card p { margin: 0 0 22px; }
.login-card .notice { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; border-radius: 8px; padding: 10px 12px; }
.login-card .fine { margin: 18px 0 0; font-size: 13px; color: var(--faint); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  height: 58px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tab {
  height: 34px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: 500 14px var(--font); cursor: pointer;
}
.tab:hover { background: #eef1f5; color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-email { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account form { margin: 0; }

/* Layout */
.layout { display: flex; gap: 0; height: calc(100vh - 58px); }

/* Folder explorer */
.btn-tree { width: 34px; padding: 0; margin-left: -8px; }
.explorer {
  flex: 0 0 280px; width: 280px; min-width: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
}
.explorer-closed .explorer { display: none; }
.explorer-head { padding: 16px 16px 8px; }
.explorer-title { font-size: 12px; font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
.explorer-filter { padding: 0 12px 10px; }
.explorer-filter input {
  width: 100%; height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--bg); font: 13px var(--font); color: var(--text);
}
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree { flex: 1 1 auto; overflow-y: auto; padding: 0 8px 24px; }
.tree-row {
  display: flex; align-items: center; gap: 2px; min-height: 30px; border-radius: 7px;
}
.tree-row[data-depth="1"] { padding-left: 14px; }
.tree-row[data-depth="2"] { padding-left: 28px; }
.tree-row[data-depth="3"] { padding-left: 42px; }
.tree-row[data-depth="4"] { padding-left: 56px; }
.tree-row[data-depth="5"] { padding-left: 70px; }
.tree-row[data-depth="6"] { padding-left: 84px; }
.tree-row:hover { background: #f1f4f8; }
.tree-row.is-active { background: var(--accent-soft); }
.tree-row.is-active .tree-name { color: var(--accent); font-weight: 600; }
.twisty, .twisty-space { flex: 0 0 22px; width: 22px; height: 22px; }
.twisty {
  display: inline-grid; place-items: center; padding: 0; border: 0; border-radius: 5px;
  background: transparent; color: var(--faint); cursor: pointer;
}
.twisty:hover { background: #e6ebf1; color: var(--text); }
.twisty svg { transition: transform .12s ease; }
.twisty.is-open svg { transform: rotate(90deg); }
.tree-name {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px 0 2px;
  border: 0; background: transparent; color: var(--text); font: 13.5px var(--font); text-align: left; cursor: pointer;
}
.tree-name:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 7px; }
.folder-ico { flex: 0 0 auto; color: #8fa3bd; }
.tree-row.is-active .folder-ico { color: var(--accent); }
.tree-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count { flex: 0 0 auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.tree-empty { padding: 10px 12px; font-size: 13px; color: var(--muted); }
.explorer-scrim { display: none; }

/* Breadcrumbs */
.crumbs { max-width: 920px; margin: 0 auto 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 14px; }
.crumb { border: 0; background: none; padding: 2px 4px; border-radius: 5px; color: var(--accent); font: inherit; cursor: pointer; }
.crumb:hover { background: var(--accent-soft); }
.crumb.is-current { color: var(--text); font-weight: 600; cursor: default; }
.crumb.is-current:hover { background: none; }
.crumb-sep { color: var(--faint); }
.pane-list { flex: 1 1 auto; min-width: 0; overflow-y: auto; padding: 24px 28px 60px; }
.has-detail .pane-list { flex-basis: 46%; }
.pane-detail {
  flex: 0 0 54%; max-width: 860px; min-width: 0; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line);
}
.section-head { margin: 0 auto 18px; max-width: 920px; }
.section-head h2 { font-size: 20px; margin-bottom: 4px; }
.section-head p { margin: 0; }

/* Search */
.searchbox {
  position: relative; max-width: 920px; margin: 0 auto 14px;
}
.searchbox input {
  width: 100%; height: 52px; padding: 0 48px 0 48px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); font: 16px var(--font); color: var(--text); box-shadow: var(--shadow);
}
.searchbox input::placeholder { color: var(--faint); }
.searchbox input::-webkit-search-cancel-button { cursor: pointer; }
.search-icon { position: absolute; left: 16px; top: 16px; color: var(--faint); }
.hint {
  position: absolute; right: 14px; top: 15px; min-width: 22px; height: 22px; padding: 0 6px;
  border: 1px solid var(--line-strong); border-radius: 6px; color: var(--faint);
  font: 12px/20px var(--mono); text-align: center; background: #fafbfc;
}
.searchbox input:focus + .hint, .searchbox input:not(:placeholder-shown) + .hint { display: none; }

.filters { max-width: 920px; margin: 0 auto 6px; display: flex; flex-direction: column; gap: 8px; }
.filter-group { display: flex; align-items: flex-start; gap: 6px; }
.filter-label { width: 110px; flex: 0 0 110px; padding-top: 6px; font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 13px var(--font); cursor: pointer;
}
.chip:hover { border-color: var(--line-strong); }
.chip .count { color: var(--faint); font-size: 12px; }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.is-on .count { color: rgba(255, 255, 255, .85); }
.filters.is-collapsed .filter-group:not(:first-child) { display: none; }
.more-filters { margin-left: 4px; font-size: 13px; }

.status { max-width: 920px; margin: 12px auto 10px; min-height: 20px; color: var(--muted); font-size: 13px; }

/* Results */
.results { list-style: none; margin: 0 auto; padding: 0; max-width: 920px; display: flex; flex-direction: column; gap: 10px; }
.result {
  display: flex; gap: 16px; align-items: flex-start; padding: 16px 18px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.result:hover { border-color: var(--line-strong); }
.result.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.result-main { flex: 1 1 auto; min-width: 0; }
.result-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600;
  background: #eef1f5; color: #3d4756;
}
.badge-company { background: #eef4ff; color: #2b4c9b; }
.badge-sponsorship { background: #f3eefe; color: #5b3aa6; }
.badge-finance { background: #ecfdf3; color: #146c43; }
.badge-payroll { background: #fff6e5; color: #8a5300; }
.badge-clients { background: #e9f7fb; color: #0e6a83; }
.badge-recruitment { background: #fdf0f5; color: #a13567; }
.badge-people { background: #f2f4f7; color: #364152; }
.type { font-size: 13px; color: var(--muted); }
.ext { font: 11px var(--mono); color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.sensitive { font-size: 12px; color: var(--danger); font-weight: 600; }
.result-title {
  display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer;
  font: 600 16px/1.35 var(--font); color: var(--text);
}
.result-title:hover { color: var(--accent); }
.snippet { margin: 6px 0 8px; color: #3b4555; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.kf { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.kf-item { display: inline-flex; gap: 4px; padding: 2px 8px; border-radius: 6px; background: #f3f5f8; font-size: 12.5px; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kf-label { color: var(--muted); }
.older { font-size: 12px; font-weight: 600; color: #8a5300; background: #fff6e5; border-radius: 6px; padding: 1px 7px; }
.closest { color: #8a5300; }
.detail-note { margin: -8px 0 16px; padding: 10px 12px; border-radius: 8px; background: #fff6e5; color: #6b4300; font-size: 14px; }
.related-link, .question-link { text-align: left; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.meta .folder { color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.meta .overdue { color: var(--danger); font-weight: 600; }
.result-actions { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.has-detail .result-actions { display: none; }
.empty {
  display: flex; flex-direction: column; gap: 4px; padding: 40px 20px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty strong { color: var(--text); }

/* Detail */
.detail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.detail-actions { display: flex; gap: 8px; }
.detail-body { flex: 1 1 auto; overflow-y: auto; padding: 22px 26px 40px; }
.badges { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.detail-body h2 { font-size: 21px; line-height: 1.3; margin-bottom: 8px; }
.detail-desc { margin: 0 0 18px; color: #3b4555; }
.preview { margin-bottom: 22px; }
.preview iframe { width: 100%; height: 62vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fafbfc; }
.preview img { display: block; max-width: 100%; max-height: 62vh; margin: 0 auto; border: 1px solid var(--line); border-radius: var(--radius); }
.textview { border: 1px solid var(--line); border-radius: var(--radius); background: #fafbfc; padding: 14px 16px; }
.textview p { margin: 0 0 10px; font-size: 13px; }
.textview pre { margin: 0; max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 13px/1.55 var(--mono); color: #2b3442; }
/* Full-screen document view */
.btn-icon { width: 34px; padding: 0; }
.btn-icon .ico-collapse { display: none; }
.detail-full .btn-icon .ico-expand { display: none; }
.detail-full .btn-icon .ico-collapse { display: block; }
.detail-full .explorer, .detail-full .pane-list, .detail-full .explorer-scrim { display: none !important; }
.detail-full .pane-detail { flex: 1 1 100%; max-width: none; border-left: 0; }
.detail-full .detail-body { padding: 18px 32px 40px; }
.detail-full .preview iframe { height: calc(100vh - 58px - 64px - 40px); }
.detail-full .preview img { max-height: calc(100vh - 58px - 64px - 40px); }
.detail-full .table-scroll, .detail-full .docview, .detail-full .textview pre { max-height: calc(100vh - 58px - 64px - 110px); }

/* File viewers */
.viewer-loading, .viewer-note { padding: 14px 16px; font-size: 13px; color: var(--muted); }
.viewer-loading { border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; }
.sheet { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.sheet-tabs { display: flex; gap: 2px; overflow-x: auto; padding: 6px 6px 0; background: #f3f5f8; border-bottom: 1px solid var(--line); }
.sheet-tab {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; background: transparent;
  color: var(--muted); font: 500 13px var(--font); cursor: pointer;
}
.sheet-tab:hover { color: var(--text); background: #e9edf2; }
.sheet-tab.is-on { background: var(--surface); color: var(--text); border-color: var(--line); margin-bottom: -1px; }
.sheet-tab .count { font-size: 11px; color: var(--faint); }
.table-scroll { overflow: auto; max-height: 62vh; }
.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
.grid th, .grid td {
  padding: 6px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top;
}
.grid .cell { width: max-content; min-width: 4ch; max-width: 320px; white-space: pre-wrap; overflow-wrap: break-word; }
.grid th .cell { white-space: nowrap; max-width: none; }
.grid thead th { position: sticky; top: 0; z-index: 1; background: #f3f5f8; font-weight: 600; color: var(--text); }
.grid tbody tr:nth-child(even) td { background: #fafbfc; }
.grid .rownum { position: sticky; left: 0; background: #f3f5f8; color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; min-width: 40px; }
.grid thead .rownum { z-index: 2; }
.docview {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 24px 28px; max-height: 62vh; overflow-y: auto; font-size: 14.5px; line-height: 1.6;
}
.docview p { margin: 0 0 10px; white-space: pre-wrap; }
.docview .doc-h { margin: 18px 0 8px; line-height: 1.3; }
.docview h2.doc-h { font-size: 19px; }
.docview h3.doc-h { font-size: 16.5px; }
.docview h4.doc-h, .docview h5.doc-h { font-size: 15px; }
.docview > .doc-h:first-child { margin-top: 0; }
.docview ul { margin: 0 0 10px; padding-left: 22px; }
.docview li { margin: 0 0 4px; }
.docview li.lvl-1 { margin-left: 20px; }
.docview li.lvl-2 { margin-left: 40px; }
.docview li.lvl-3, .docview li.lvl-4 { margin-left: 60px; }
.docview .table-scroll { margin: 6px 0 14px; max-height: none; border: 1px solid var(--line); border-radius: 8px; }
.docview .grid { font-size: 13px; }
.facts { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--faint); font-weight: 600; font-size: 13px; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kw { display: inline-block; margin: 0 4px 4px 0; padding: 1px 8px; border-radius: 999px; background: #f1f4f8; color: var(--muted); font-size: 12px; }

/* Narrow screens */
@media (max-width: 900px) {
  .topbar { gap: 12px; padding: 0 14px; }
  .brand span { display: none; }
  .account-email { display: none; }
  .pane-list { padding: 16px 14px 60px; }
  .has-detail .pane-list { display: none; }
  .pane-detail { flex: 1 1 100%; max-width: none; border-left: 0; }
  .detail-body { padding: 18px 16px 40px; }
  .filter-group { flex-direction: column; gap: 4px; }
  .filter-label { width: auto; flex-basis: auto; padding-top: 0; }
  .result { flex-direction: column; gap: 10px; }
  .result-actions { flex-direction: row; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  .preview iframe { height: 70vh; }
  .hint { display: none; }
  .btn-tree { margin-left: -4px; }
  .explorer {
    position: fixed; z-index: 30; top: 58px; bottom: 0; left: 0; width: min(86vw, 320px);
    box-shadow: 0 8px 30px rgba(16, 24, 40, .18);
  }
  .explorer-scrim { display: block; position: fixed; inset: 58px 0 0 0; z-index: 25; background: rgba(16, 24, 40, .28); }
  .explorer-scrim[hidden] { display: none !important; }
}
