:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-hover: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa1ac;
  --accent: #7c5cff;
  --accent-dim: #5b3fd6;
  --danger: #ff5c5c;
  --radius: 12px;
  --topbar-bg: rgba(15, 17, 21, 0.9);
}

:root[data-theme="light"] {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-hover: #eef0f4;
  --border: #dfe2e8;
  --text: #1a1c22;
  --text-dim: #6b7280;
  --accent: #6942f5;
  --accent-dim: #5735d6;
  --danger: #d9364a;
  --topbar-bg: rgba(255, 255, 255, 0.85);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 20px;
  transition: width 0.15s;
}
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .sidebar-label { display: none; }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; }

.sidebar-header { display: flex; align-items: center; gap: 8px; }
.sidebar-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  transition: transform 0.15s;
}
.sidebar-toggle:hover { color: var(--text); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}
.nav-item:hover { background: var(--panel-hover); color: var(--text); }
.nav-item.active { background: rgba(124, 92, 255, 0.15); color: var(--accent); }
.nav-icon { font-size: 18px; width: 20px; text-align: center; flex-shrink: 0; }

.main-area { flex: 1; min-width: 0; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand-icon { width: 24px; height: 24px; display: block; flex-shrink: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.topbar-spacer { flex: 1; }

.file-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.btn-icon { padding: 8px 12px; font-size: 15px; line-height: 1; }
.btn-icon:disabled { opacity: 0.35; cursor: default; }
.btn-icon:disabled:hover { background: var(--panel); }

.breadcrumb[hidden] { display: none; }
.breadcrumb { flex: 1; display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-size: 14px; overflow-x: auto; white-space: nowrap; }
.breadcrumb button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.breadcrumb button:hover { background: var(--panel-hover); color: var(--text); }
.breadcrumb .sep { opacity: 0.5; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: var(--panel-hover); }
.btn-ghost { background: transparent; }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--text-dim);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.dropzone.drag-over { border-color: var(--accent); background: rgba(124, 92, 255, 0.08); }
.dropzone-icon { font-size: 28px; display: block; margin-bottom: 6px; }
.dropzone-hint { font-size: 13px; margin: 4px 0 0; }

.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

.uploads { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.upload-row { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.upload-row .name { display: flex; justify-content: space-between; margin-bottom: 6px; color: var(--text-dim); }
.upload-row .bar-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.upload-row .bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.1s; }
.upload-row.error .bar-fill { background: var(--danger); }
.upload-row.done .bar-fill { background: #4caf7d; }

.file-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.file-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  position: relative;
  transition: background 0.12s, transform 0.12s;
}
.file-card:hover { background: var(--panel-hover); transform: translateY(-2px); }
.file-icon { font-size: 34px; }
.file-name { font-size: 13px; text-align: center; word-break: break-word; max-width: 100%; }
.file-meta { font-size: 11px; color: var(--text-dim); }

.file-card .delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.12s;
}
.file-card .delete-btn.rename-btn { right: 28px; }
.file-card:hover .delete-btn { opacity: 1; }
.file-card .delete-btn:hover { color: var(--danger); }
.file-card .delete-btn.rename-btn:hover { color: var(--accent); }

.empty-state { text-align: center; color: var(--text-dim); margin-top: 40px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
}

.whoami { color: var(--text-dim); font-size: 13px; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-screen[hidden] { display: none; }

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.auth-brand { justify-content: center; margin-bottom: 24px; font-size: 20px; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form[hidden] { display: none; }
.auth-form h2 { margin: 0 0 4px; font-size: 18px; text-align: center; }

.auth-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }

.btn-primary { background: var(--accent); border-color: var(--accent-dim); font-weight: 600; }
.btn-primary:hover { background: var(--accent-dim); }

.auth-links { display: flex; justify-content: space-between; margin-top: 4px; flex-wrap: wrap; gap: 8px; }
.auth-hint { color: var(--text-dim); font-size: 13px; margin: -4px 0 4px; }
.auth-error { color: var(--danger); font-size: 13px; margin: 0; }
.auth-success { color: #4caf7d; font-size: 13px; margin: 0; }

.section-title { font-size: 18px; margin: 0 0 16px; }
.section-subtitle { font-size: 14px; color: var(--text-dim); margin: 24px 0 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.stats-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 140px;
}
.stat-card .value { font-size: 20px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.user-table .actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-danger { color: var(--danger); border-color: rgba(255, 92, 92, 0.3); }
.btn-danger:hover { background: rgba(255, 92, 92, 0.12); }

.user-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 14px;
}
.user-table th, .user-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.user-table th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.user-table tr:last-child td { border-bottom: none; }
.user-table .badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.15);
  color: var(--accent);
}

/* ------------------------------------------------------------- toolbar extras */

.search-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  width: 160px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.sort-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
}

.theme-toggle { font-size: 15px; padding: 8px 10px; }

/* ------------------------------------------------------------------ selection */

.file-card { user-select: none; }
.file-card.selected { outline: 2px solid var(--accent); background: var(--panel-hover); }

.select-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 16px;
  height: 16px;
  cursor: pointer;
  display: none;
}
.selection-mode .select-checkbox { display: block; }
.selection-mode .delete-btn { display: none; }

.selection-bar[hidden] { display: none; }
.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-dim);
}
.selection-bar .spacer { flex: 1; }

/* ----------------------------------------------------------------------- nav badge */

.nav-item { position: relative; }
.nav-dot {
  position: absolute;
  top: 6px;
  left: 24px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: none;
}
.nav-item.has-badge .nav-dot { display: block; }
.sidebar.collapsed .nav-dot { left: 30px; }

/* --------------------------------------------------------------------------- modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.preview-modal img, .preview-modal video { max-width: 80vw; max-height: 80vh; display: block; border-radius: 8px; }
.preview-modal audio { width: 400px; max-width: 80vw; }
.preview-modal iframe { width: 80vw; height: 80vh; border: none; border-radius: 8px; }

.trash-modal { width: 600px; }
.trash-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.trash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.trash-row .trash-name { flex: 1; }
.trash-row .trash-meta { color: var(--text-dim); font-size: 12px; }

/* ------------------------------------------------------------------- servers page */

.server-gauges { display: flex; gap: 20px; flex-wrap: wrap; }

.gauge-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 150px;
}

.gauge-svg { width: 110px; height: 110px; transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: var(--border); stroke-width: 9; }
.gauge-fill { fill: none; stroke-width: 9; stroke-linecap: round; transition: stroke-dasharray 0.6s ease, stroke 0.3s ease; }

.gauge-wrap { position: relative; width: 110px; height: 110px; }
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-percent { font-size: 20px; font-weight: 700; }
.gauge-name { font-size: 12px; color: var(--text-dim); text-align: center; }
.gauge-sub { font-size: 11px; color: var(--text-dim); text-align: center; }

.server-meta {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin: 18px 0;
  color: var(--text-dim);
  font-size: 13px;
}
.server-meta strong { color: var(--text); font-weight: 600; }
