/* OfficeVault UI — one stylesheet for every page. Dark and restrained on the
   DESIGN.md §7 palette (#0D1117 base, soft accent glow). System font stack
   only: no external fonts, works on an airgapped LAN.
   CSP note: style-src 'self' blocks inline <style> and style="..." attributes,
   so every rule lives here and the JS uses CSSOM property assignment for
   dynamic widths — never style attributes. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2129;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: rgba(88, 166, 255, 0.4);
  --accent-soft: rgba(88, 166, 255, 0.12);
  --accent-glow: 0 0 12px rgba(88, 166, 255, 0.25);
  --danger: #f85149;
  --danger-dim: rgba(248, 81, 73, 0.4);
  --danger-soft: rgba(248, 81, 73, 0.12);
  --ok: #3fb950;
  --warn: #d29922;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu,
        Cantarell, "Noto Sans", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 1.35rem; font-weight: 650; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }

/* --- top navigation --- */
.topnav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  height: 52px; padding: 0 20px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { color: var(--text); font-weight: 700; }
.brand:hover { color: var(--accent); text-decoration: none; }
.topnav-links { display: flex; gap: 2px; flex: 1; }
.topnav-links a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.topnav-links a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topnav-user { display: flex; align-items: center; gap: 10px; }
.topnav-name {
  color: var(--muted); font-size: 0.9rem; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.btn:hover { background: var(--surface-2); border-color: #3d444d; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary {
  color: #79c0ff; border-color: var(--accent-dim); background: var(--accent-soft);
}
.btn-primary:hover {
  background: rgba(88, 166, 255, 0.22);
  border-color: var(--accent); box-shadow: var(--accent-glow);
}
.btn-danger { color: var(--danger); border-color: var(--danger-dim); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 3px 8px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 6px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.icon-btn svg { pointer-events: none; }

/* --- page shell --- */
.page { max-width: 1120px; margin: 0 auto; padding: 20px 20px 72px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}

/* --- spaces overview --- */
.spaces-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.space-card {
  display: block; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--text);
}
.space-card:hover { border-color: var(--accent-dim); text-decoration: none; }
.space-card-name { color: var(--accent); margin-bottom: 6px; }
.space-card-desc { color: var(--muted); font-size: 0.9rem; min-height: 2.2em; margin: 0 0 10px; }
.space-card-meta {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  color: var(--muted); font-size: 0.82rem; margin: 0 0 8px;
}
.usage-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.usage-fill { height: 100%; width: 0; background: var(--accent); }

/* --- badges --- */
.badge {
  display: inline-block; padding: 1px 8px;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.75rem; color: var(--muted);
}
.badge-admin { color: #79c0ff; border-color: var(--accent-dim); }
.badge-disabled { color: var(--danger); border-color: var(--danger-dim); }

/* --- breadcrumbs --- */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  margin-bottom: 14px; color: var(--muted); font-size: 0.92rem;
}
.crumbs a { color: var(--muted); padding: 2px 4px; border-radius: 4px; }
.crumbs a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.crumbs .sep { opacity: 0.5; padding: 0 2px; }
.crumbs .current { color: var(--text); padding: 2px 4px; }

/* --- toolbar --- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.toolbar .form-row { margin: 0; }
.search-box { flex: 1; min-width: 200px; position: relative; }
.search-box input { width: 100%; padding-left: 32px; }
.search-box svg {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}

/* --- file table --- */
.file-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: auto;
}
.file-panel.drop-active { outline: 2px dashed var(--accent-dim); outline-offset: -2px; background: var(--surface-2); }
.drop-hint {
  display: none; padding: 8px 12px; color: #79c0ff; font-size: 0.9rem;
  border-bottom: 1px dashed var(--accent-dim);
}
.file-panel.drop-active .drop-hint { display: block; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 0.8rem;
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td {
  padding: 8px 12px; border-bottom: 1px solid var(--border-soft);
  vertical-align: middle; max-width: 420px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
td.muted, td.num { color: var(--muted); font-size: 0.85rem; }
.cell-name { width: 55%; }
.cell-size { width: 90px; text-align: right; }
.cell-updated { width: 150px; }
.cell-actions { width: 1%; text-align: right; }
.file-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); max-width: 100%; }
.file-link:hover { color: var(--accent); text-decoration: none; }
.file-link svg { color: var(--muted); flex: none; }
.file-path { display: block; color: var(--muted); font-size: 0.78rem; }
.actions { display: flex; gap: 2px; justify-content: flex-end; }

/* --- dialogs --- */
.dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 20px;
  min-width: min(440px, calc(100vw - 32px)); max-width: 560px;
  box-shadow: 0 12px 48px rgba(1, 4, 9, 0.6);
}
.dialog::backdrop { background: rgba(1, 4, 9, 0.72); }
.dialog h2 { margin: 0 0 14px; font-size: 1.05rem; }
.dialog .form-row { margin-bottom: 12px; }
.dialog .file-panel { margin-top: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* --- forms --- */
.form-row label { display: block; color: var(--muted); font-size: 0.82rem; margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font: inherit; font-size: 0.92rem;
}
textarea { resize: vertical; min-height: 64px; font-family: var(--mono); font-size: 0.85rem; }
select { appearance: auto; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.18);
}
input[readonly] { color: var(--muted); }
.form-error { color: var(--danger); font-size: 0.85rem; margin: 10px 0 0; }
.form-hint { color: var(--muted); font-size: 0.78rem; margin: 4px 0 0; }
.check-row { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; font-size: 0.9rem; }
.check-row label { color: var(--text); font-size: 0.9rem; display: flex; gap: 8px; align-items: flex-start; }
.check-row input[type="checkbox"] { width: auto; margin-top: 3px; accent-color: var(--accent); }
.field-group { display: flex; gap: 10px; }
.field-group > .form-row { flex: 1; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 12px; padding: 8px 12px 10px; }
legend { color: var(--muted); font-size: 0.82rem; padding: 0 4px; }

/* --- login --- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px;
  box-shadow: 0 8px 40px rgba(1, 4, 9, 0.5);
}
.login-brand { text-align: center; color: var(--accent); font-size: 1.5rem; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 0.9rem; }
.login-card .form-row { margin-bottom: 14px; }

/* --- upload queue --- */
.upload-queue {
  position: fixed; right: 16px; bottom: 16px; z-index: 20;
  width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 32px rgba(1, 4, 9, 0.6);
}
.upload-queue-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; border-bottom: 1px solid var(--border-soft);
  font-size: 0.85rem; color: var(--muted);
}
.upload-item { padding: 8px 14px; border-bottom: 1px solid var(--border-soft); font-size: 0.85rem; }
.upload-item:last-child { border-bottom: none; }
.upload-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 4px; }
.upload-item-status { color: var(--muted); font-size: 0.78rem; }
.upload-item-status.error { color: var(--danger); }
.upload-item-status.ok { color: var(--ok); }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-bottom: 4px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }
.upload-item.done .progress-fill { background: var(--ok); }

/* --- tabs --- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  background: transparent; border: 1px solid transparent; border-bottom: none;
  color: var(--muted); padding: 8px 14px; font: inherit; font-size: 0.92rem;
  cursor: pointer; border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--accent); border-color: var(--border); background: var(--surface); }
.tab-panel[hidden] { display: none; }

/* --- one-time key reveal --- */
.key-reveal { display: flex; gap: 8px; margin-top: 6px; }
.key-reveal input { font-family: var(--mono); font-size: 0.85rem; flex: 1; }
.warning { color: var(--warn); font-size: 0.85rem; }

/* --- toasts --- */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 30;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 16px; font-size: 0.88rem; box-shadow: 0 6px 24px rgba(1, 4, 9, 0.5);
}
.toast-error { border-color: var(--danger-dim); }

/* --- misc --- */
.empty { color: var(--muted); padding: 28px 12px; text-align: center; }
.notice { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; font-size: 0.9rem; }
.notice-error { border: 1px solid var(--danger-dim); color: var(--danger); }
.notice-info { border: 1px solid var(--border); color: var(--muted); }
.audit-table td, .audit-table th { font-size: 0.82rem; }
.table-note { color: var(--muted); font-size: 0.82rem; margin: 10px 2px 0; }
.clipboard-fallback {
  position: fixed; left: -9999px; top: 0; opacity: 0;
}

/* --- responsive: tablet and below --- */
@media (max-width: 900px) {
  .hide-sm { display: none; }
  .cell-name { width: auto; }
  .page { padding: 16px 12px 72px; }
}
@media (max-width: 640px) {
  .topnav-name { display: none; }
  .topnav { padding: 0 12px; gap: 10px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .field-group { flex-direction: column; gap: 0; }
}
