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

:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface2: #23232f;
  --border: #2e2e3d;
  --accent: #7c6af4;
  --accent-hover: #9585f8;
  --danger: #e05b5b;
  --success: #4caf7d;
  --text: #e8e8f0;
  --muted: #888899;
  --radius: 8px;
  --font: 'Inter', system-ui, sans-serif;
  --sidebar-w: 220px;
  --tree-w: 260px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Layout ── */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 4px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Three-zone mode when Kyvora section is active */
.app-shell.kyvora-mode {
  grid-template-columns: var(--sidebar-w) 4px var(--tree-w) 4px 1fr;
}

.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}
.topbar .logo { font-weight: 700; font-size: 15px; letter-spacing: .5px; color: var(--text); }
.topbar .spacer { flex: 1; }
.topbar .user-badge { font-size: 12px; color: var(--muted); }
.topbar .btn-sm { font-size: 12px; }

.sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding-top: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar .nav-section {
  padding: 8px 16px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background .15s;
}
.sidebar .nav-item:hover,
.sidebar .nav-item.active {
  background: var(--surface2);
  color: var(--accent);
}
.sidebar .nav-item .icon { width: 16px; text-align: center; opacity: .7; }

/* ── Resize handles ── */
.sidebar-resize-handle {
  grid-column: 2;
  grid-row: 2;
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle:active {
  background: var(--accent);
  opacity: 0.5;
}

.tree-resize-handle {
  grid-column: 4;
  grid-row: 2;
  display: none;
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}
.app-shell.kyvora-mode .tree-resize-handle {
  display: block;
}
.tree-resize-handle:hover,
.tree-resize-handle:active {
  background: var(--accent);
  opacity: 0.5;
}

/* ── Kyvora tree panel (column 3 in kyvora-mode) ── */
.kyvora-tree-panel {
  grid-column: 3;
  grid-row: 2;
  display: none;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}
.app-shell.kyvora-mode .kyvora-tree-panel {
  display: flex;
}

.kyvora-tree-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
}

.kyvora-pane-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.kyvora-tree-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0;
}

/* ── Main content ── */
.main-content {
  grid-column: 3;
  grid-row: 2;
  overflow-y: auto;
  padding: 24px;
}
.app-shell.kyvora-mode .main-content {
  grid-column: 5;
}

/* ── Cards / surfaces ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--accent); }
.form-select option { background: var(--surface); }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
}
.login-logo { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 28px; }

/* ── File table ── */
.file-table { width: 100%; border-collapse: collapse; }
.file-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.file-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.file-table tr:last-child td { border-bottom: none; }
.file-table tr:hover td { background: var(--surface2); }

.file-icon { margin-right: 6px; opacity: .7; }
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--muted);
  margin-left: 4px;
}
.badge-private { background: #2a1a3a; color: #bb88ff; }
.badge-ro { background: #1a2a2a; color: #88cccc; }

/* ── Breadcrumb ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.breadcrumb .sep { color: var(--muted); }
.breadcrumb a { color: var(--accent); }
.breadcrumb .current { color: var(--text); }

/* ── Preview modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.preview-img { max-width: 80vw; max-height: 75vh; display: block; border-radius: 6px; }
.preview-video { max-width: 80vw; max-height: 75vh; display: block; border-radius: 6px; }

/* ── Alerts ── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.alert-error { background: #2a1111; border: 1px solid #5a2020; color: #f08080; }
.alert-success { background: #0d2a1a; border: 1px solid #1a5a35; color: #70d4a0; }
.alert-info { background: #0d1a2a; border: 1px solid #1a3a5a; color: #70a0d4; }

/* ── Audit table ── */
.audit-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.audit-table th {
  text-align: left;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.audit-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); font-family: monospace; }
.audit-table tr:hover td { background: var(--surface2); }
.result-ok { color: var(--success); }
.result-denied { color: var(--danger); }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); color: var(--text); }
.upload-zone input { display: none; }

/* ── Signed links table ── */
.signed-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.signed-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.signed-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.signed-table .link-url {
  font-family: monospace;
  font-size: 11px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Utility ── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.loading { opacity: .5; pointer-events: none; }

/* ── TOTP QR area ── */
.qr-area { text-align: center; padding: 16px; }
.qr-uri { font-family: monospace; font-size: 11px; word-break: break-all; color: var(--muted); margin-top: 8px; }

/* ── Folder tree nodes ── */
.tree-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px 5px 0;
  cursor: default;
  border-radius: 4px;
  margin: 1px 4px 1px 0;
  font-size: 13px;
  color: var(--text);
  transition: background 0.1s;
}
.tree-node:hover { background: var(--surface2); }
.tree-node.selected { background: rgba(124, 106, 244, 0.25); border-left: 2px solid var(--accent); }
.tree-node.selected .tree-label { color: var(--accent); font-weight: 500; }

.tree-folder-icon {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.8;
  flex-shrink: 0;
}

.tree-arrow {
  width: 18px;
  min-width: 18px;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  user-select: none;
  cursor: pointer;
  line-height: 1;
  padding: 2px 0;
}
.tree-arrow:hover { color: var(--text); }

.tree-arrow-placeholder {
  width: 18px;
  min-width: 18px;
  display: inline-block;
}

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  padding: 1px 0;
}
.tree-label:hover { color: var(--accent-hover); }

.tree-empty {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  padding: 3px 8px 3px 0;
  margin: 1px 4px;
}

.tree-legacy-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  cursor: pointer;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  user-select: none;
}
.tree-legacy-toggle:hover { color: var(--text); }
