:root {
  --bg: #f4f6fa;
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  --text: #1e2330;
  --muted: #8b91a1;
  --border: #e7e9f0;
  --accent: #4c6fff;
  --accent-hover: #3c59e0;
  --accent-soft: #eef1ff;
  --danger: #ef4444;
  --danger-soft: #fdeceb;
  --success: #22c55e;
  --success-soft: #eafbf0;
  --warning: #f5a623;
  --warning-soft: #fef6e7;
  --pink: #ef5da8;
  --pink-soft: #fdecf4;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(20, 24, 38, 0.05), 0 1px 8px rgba(20, 24, 38, 0.04);
}

/* Applied by the inline script in <head>, before first paint, based on a
   stored choice or (if none yet) the OS preference — see theme.js. */
:root[data-theme="dark"] {
  --bg: #12141a;
  --sidebar-bg: #181b23;
  --card-bg: #181b23;
  --text: #e6e8ef;
  --muted: #8b91a1;
  --border: #272b36;
  --accent: #6c86ff;
  --accent-hover: #5a72e8;
  --accent-soft: rgba(108, 134, 255, 0.16);
  --danger: #f56565;
  --danger-soft: rgba(245, 101, 101, 0.16);
  --success: #48d597;
  --success-soft: rgba(72, 213, 151, 0.16);
  --warning: #f6ad55;
  --warning-soft: rgba(246, 173, 85, 0.16);
  --pink: #f783b0;
  --pink-soft: rgba(247, 131, 176, 0.16);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

/* Any element toggled via the `hidden` attribute must actually hide,
   regardless of a `display` value its own class sets (e.g. `.drop-overlay`
   sets `display: flex`, which has the same specificity as the browser's
   default `[hidden] { display: none }` and — being later in the cascade —
   would otherwise win and show the element anyway). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- Login page ---- */

.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px;
  margin-bottom: 20px;
  max-width: 420px;
  width: 100%;
}

.card h1, .card h2 { margin-top: 0; }

.subtitle { color: var(--muted); margin-bottom: 16px; }

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

.error { color: var(--danger); margin-top: 10px; }
.status { color: var(--muted); font-size: 13px; margin-top: 10px; }

input[type="password"], input[type="file"], input[type="text"] {
  width: 100%;
  padding: 10px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
}

button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.link-btn {
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  padding: 4px 8px;
}

.link-btn.small {
  font-size: 12px;
  padding: 0;
  text-decoration: none;
  color: var(--accent);
  font-weight: 500;
}

/* ---- App shell ---- */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  padding: 0 8px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0 12px;
  margin-bottom: 6px;
}

.sidebar-folder-list { display: flex; flex-direction: column; gap: 1px; margin-bottom: 8px; max-height: 220px; overflow-y: auto; }

.sidebar-folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.sidebar-folder-item svg { flex-shrink: 0; }
.sidebar-folder-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-folder-item:hover { background: var(--bg); }
.sidebar-folder-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-storage {
  margin-top: auto;
  padding: 14px 12px 0;
  border-top: 1px solid var(--border);
}

.sidebar-storage-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}

.sidebar-storage-stat { font-size: 13px; color: var(--text); }

.sidebar-theme {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.theme-btn {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.theme-btn:hover:not(.active) { color: var(--text); }

.theme-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 32px 0;
  gap: 16px;
  flex-wrap: wrap;
}

.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.breadcrumb .crumb-link { cursor: pointer; }
.breadcrumb .crumb-link:hover { color: var(--accent); }
.breadcrumb .crumb-sep { margin: 0 6px; }

#page-title { margin: 0; font-size: 24px; }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
}

.search-box svg { flex-shrink: 0; color: var(--muted); }

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  width: 180px;
  color: var(--text);
  margin: 0;
  padding: 0;
}

.content {
  padding: 20px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- Stat cards ---- */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
}

.stat-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-card-title { font-weight: 600; font-size: 14px; }
.stat-card-count { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }

.stat-card-bar {
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 6px;
}

.stat-card-bar-fill { height: 100%; border-radius: var(--radius-pill); }
.stat-card-size { font-size: 11px; color: var(--muted); }

/* ---- Panels ---- */

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-header h2 { margin: 0; font-size: 16px; }
.panel-actions { display: flex; gap: 8px; }

/* ---- Recent strip ---- */

.recent-strip { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 2px; }

.recent-card {
  flex: 0 0 auto;
  width: 150px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.recent-card-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.recent-card-name {
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Sidebar upload button ---- */

.sidebar-upload { padding: 0 2px; }

.upload-btn-primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  font-weight: 600;
}

/* ---- Page-wide drag-and-drop overlay ---- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(76, 111, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay-inner {
  background: var(--card-bg);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 36px 56px;
  text-align: center;
  color: var(--text);
}

.drop-overlay-inner span { display: block; margin: 0 auto 12px; width: fit-content; color: var(--accent); }
.drop-overlay-inner p { margin: 0; font-size: 15px; }

/* ---- Floating upload progress toast ---- */

.upload-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 300px;
  z-index: 1001;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(20, 24, 38, 0.14);
  padding: 16px 18px;
}

.upload-toast-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.upload-toast-title { font-weight: 600; font-size: 14px; }

.stuck-upload-toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 320px;
  z-index: 1001;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(20, 24, 38, 0.14);
  padding: 16px 18px;
}

.stuck-upload-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }

/* ---- File / folder table ---- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: none; }

.checkbox-col { width: 32px; }

.file-name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.folder-row { cursor: pointer; }
.folder-row:hover td { background: var(--bg); }

.row-btn { padding: 6px 10px; font-size: 13px; margin-right: 6px; border-radius: var(--radius-sm); }
.row-btn.danger { background: var(--danger); }
.row-btn.danger:hover { background: #dc2626; }
