:root {
  /* F1Group brand palette */
  --brand-orange: #ED5A2E;
  --brand-amber:  #F4A91A;
  --brand-lime:   #A6CE3A;
  --brand-cyan:   #1FA3D9;
  --brand-purple: #7B4FA7;

  /* Light */
  --bg: #fbfaf7;
  --bg-grad: radial-gradient(1100px 560px at 88% -10%, rgba(237, 90, 46, 0.10) 0%, transparent 60%),
             radial-gradient(900px 520px at -10% 8%, rgba(31, 163, 217, 0.10) 0%, transparent 55%),
             radial-gradient(800px 500px at 50% 110%, rgba(244, 169, 26, 0.10) 0%, transparent 55%);
  --surface: rgba(255, 255, 255, 0.74);
  --surface-solid: #ffffff;
  --surface-hover: rgba(237, 90, 46, 0.06);
  --border: rgba(30, 22, 18, 0.08);
  --border-strong: rgba(30, 22, 18, 0.16);
  --text: #1a120d;
  --text-muted: #6b6157;
  --text-soft: #4a3f36;
  --accent: #ED5A2E;
  --accent-hover: #d34a22;
  --accent-fg: #ffffff;
  --accent-soft: rgba(237, 90, 46, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.10);
  --success: #2f9e44;
  --accent-grad-2: var(--brand-amber);
  --accent-glow-1: rgba(237, 90, 46, 0.35);
  --accent-glow-2: rgba(237, 90, 46, 0.45);
  --folder-grad-a: rgba(237, 90, 46, 0.18);
  --folder-grad-b: rgba(244, 169, 26, 0.14);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.18), 0 8px 16px -8px rgba(15, 23, 42, 0.08);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

html[data-theme="dark"] {
  --bg: #0a0a0f;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.18) 0%, transparent 55%),
             radial-gradient(900px 500px at -10% 10%, rgba(139, 92, 246, 0.14) 0%, transparent 55%);
  --surface: rgba(20, 22, 30, 0.72);
  --surface-solid: #14161e;
  --surface-hover: rgba(99, 102, 241, 0.12);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-soft: #cbd5e1;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-fg: #0a0a0f;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #34d399;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.4), 0 2px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6), 0 8px 16px -8px rgba(0, 0, 0, 0.4);
  --accent-grad-2: #a855f7;
  --accent-glow-1: rgba(99, 102, 241, 0.35);
  --accent-glow-2: rgba(99, 102, 241, 0.45);
  --folder-grad-a: rgba(99, 102, 241, 0.16);
  --folder-grad-b: rgba(168, 85, 247, 0.12);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #0a0a0f;
    --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, 0.18) 0%, transparent 55%),
               radial-gradient(900px 500px at -10% 10%, rgba(139, 92, 246, 0.14) 0%, transparent 55%);
    --surface: rgba(20, 22, 30, 0.72);
    --surface-solid: #14161e;
    --surface-hover: rgba(99, 102, 241, 0.12);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-soft: #cbd5e1;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-fg: #0a0a0f;
    --accent-soft: rgba(129, 140, 248, 0.16);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.14);
    --success: #34d399;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.4), 0 2px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6), 0 8px 16px -8px rgba(0, 0, 0, 0.4);
    --accent-grad-2: #a855f7;
    --accent-glow-1: rgba(99, 102, 241, 0.35);
    --accent-glow-2: rgba(99, 102, 241, 0.45);
    --folder-grad-a: rgba(99, 102, 241, 0.16);
    --folder-grad-b: rgba(168, 85, 247, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light dark; }

body {
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "SF Pro Text",
        "Inter var", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s var(--ease); }
a:hover { color: var(--accent-hover); }

h1 { font-weight: 600; letter-spacing: -0.02em; }

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); font-weight: 600; font-size: 15px;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
.brand .logo {
  height: 26px; width: auto;
  display: block;
}
.brand .logo-dark { display: none; }
html[data-theme="dark"] .brand .logo-light { display: none; }
html[data-theme="dark"] .brand .logo-dark  { display: block; }
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .brand .logo-light { display: none; }
  html[data-theme="system"] .brand .logo-dark  { display: block; }
}
.brand-sep { color: var(--text-muted); margin: 0 2px; }
.brand-sub { color: var(--text-soft); font-weight: 500; }
.nav { display: flex; align-items: center; gap: 18px; }
.nav a { color: var(--text-soft); font-weight: 500; font-size: 13.5px; transition: color 0.15s var(--ease); }
.nav a:hover { color: var(--text); }
.user-tag {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 13px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); border: 1px solid var(--border);
}
.user-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

/* ===== Theme toggle ===== */
.theme-toggle {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.theme-toggle button {
  position: relative; z-index: 1;
  background: transparent; border: 0;
  color: var(--text-muted);
  width: 28px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s var(--ease);
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button.active { color: var(--accent-fg); }
.theme-toggle .pill {
  position: absolute; top: 3px; left: 3px;
  width: 28px; height: 26px;
  background: var(--accent);
  border-radius: 999px;
  transition: transform 0.28s var(--ease);
  z-index: 0;
}
.theme-toggle button svg { width: 14px; height: 14px; }

/* ===== Layout ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 32px 24px 80px; }

/* ===== Breadcrumbs ===== */
.crumbs {
  display: flex; align-items: center; flex-wrap: wrap;
  font-size: 14px; margin-bottom: 20px; gap: 2px;
  color: var(--text-muted);
}
.crumbs a {
  color: var(--text-soft);
  padding: 4px 10px;
  border-radius: 6px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.crumbs a:hover { background: var(--surface-hover); color: var(--text); }
.crumbs .sep { color: var(--text-muted); opacity: 0.5; }

/* ===== Actions ===== */
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; align-items: center; }
.inline { display: inline-flex; gap: 6px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--surface-solid); color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer; font: inherit; font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s var(--ease);
}
.btn:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn svg { width: 15px; height: 15px; }
.btn-primary {
  background: var(--accent); color: var(--accent-fg);
  border-color: transparent;
  box-shadow: 0 1px 2px var(--accent-glow-1), 0 4px 12px -2px var(--accent-glow-1);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 4px var(--accent-glow-2), 0 8px 20px -4px var(--accent-glow-2); }

input[type=text], input[type=password], input:not([type]) {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ===== Listing ===== */
.listing {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.row {
  display: grid;
  grid-template-columns: 1fr 110px 170px 90px;
  align-items: center;
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  position: relative;
  transition: background 0.12s var(--ease);
}
.row:first-child, .row.head { border-top: 0; }
.row.head {
  background: transparent;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; font-weight: 600;
  color: var(--text-muted);
  padding-top: 14px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.row:not(.head):not(.empty):hover { background: var(--surface-hover); }
.row:not(.head):not(.empty):hover .col-actions { opacity: 1; }
.row.empty {
  color: var(--text-muted);
  padding: 32px 18px; justify-content: center; text-align: center;
  font-style: normal;
}
.row.empty .col-name { color: var(--text-muted); }

.col-name { display: flex; align-items: center; gap: 12px; min-width: 0; font-weight: 500; }
.col-name .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-size, .col-mtime {
  color: var(--text-muted); font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.col-actions {
  display: flex; gap: 4px; justify-content: flex-end;
  opacity: 0.4;
  transition: opacity 0.15s var(--ease);
}
.col-actions form { display: inline; }

/* File/folder icons */
.icon {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}
.icon svg { width: 18px; height: 18px; }
.icon.folder { background: linear-gradient(135deg, var(--folder-grad-a), var(--folder-grad-b)); color: var(--accent); }
.icon.file { background: var(--surface-hover); color: var(--text-soft); }
.icon.up { background: transparent; color: var(--text-muted); }

.link {
  background: transparent; border: 0; color: var(--text-muted);
  cursor: pointer; padding: 6px;
  border-radius: 6px; font: inherit;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.12s var(--ease);
}
.link svg { width: 15px; height: 15px; }
.link:hover { background: var(--surface-hover); color: var(--text); }
.link.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ===== Flashes (toast-like) ===== */
.flashes {
  position: fixed; top: 78px; right: 24px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px;
  pointer-events: none;
}
.flash {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: slideIn 0.3s var(--ease);
}
.flash-error { border-left: 3px solid var(--danger); color: var(--text); }
.flash-success { border-left: 3px solid var(--success); color: var(--text); }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Auth card ===== */
.auth-card {
  max-width: 380px; margin: 64px auto; padding: 32px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.auth-card.center { text-align: center; }
.auth-card h1 { margin: 0 0 20px; font-size: 24px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600;
}
.stack label input { text-transform: none; letter-spacing: normal; font-weight: 400; }
.stack .btn-primary { margin-top: 6px; justify-content: center; padding: 10px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ===== Drag-drop ===== */
body.dragging::before {
  content: "";
  position: fixed; inset: 0; z-index: 100;
  background: var(--accent-soft);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
body.dragging::after {
  content: "Drop to upload";
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 101;
  font-size: 24px; font-weight: 600;
  color: var(--accent);
  padding: 20px 36px;
  background: var(--surface-solid);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

/* ===== Lock badge on protected folders ===== */
.lock-badge {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px;
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.lock-badge svg { width: 12px; height: 12px; }

/* ===== Internal drag-and-drop (move) ===== */
.dragging-row { opacity: 0.4; }
[data-drag-src] { cursor: grab; }
[data-drag-src]:active { cursor: grabbing; }

.row.drop-hover {
  background: var(--accent-soft) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
}
.crumbs a.drop-hover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
  color: var(--text);
}

/* ===== Upload tray ===== */
.upload-tray {
  position: fixed; right: 24px; bottom: 24px; z-index: 70;
  width: 340px; max-height: 60vh; overflow: hidden;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  transform: translateY(120%); opacity: 0;
  transition: transform 0.3s var(--ease), opacity 0.2s var(--ease);
  display: flex; flex-direction: column;
}
.upload-tray.open { transform: translateY(0); opacity: 1; }
.upload-tray-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px;
}
.ut-close {
  background: transparent; border: 0; color: var(--text-muted);
  cursor: pointer; font-size: 18px; line-height: 1;
  padding: 2px 6px; border-radius: 6px;
}
.ut-close:hover { background: var(--surface-hover); color: var(--text); }
.upload-tray-list { overflow-y: auto; padding: 6px; }
.ut-row { padding: 8px 10px; border-radius: var(--radius-sm); }
.ut-row + .ut-row { margin-top: 2px; }
.ut-info { display: flex; justify-content: space-between; gap: 8px; }
.ut-name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px;
}
.ut-meta { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.ut-dest {
  font-size: 11px; color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ut-bar {
  margin-top: 6px; height: 4px; border-radius: 999px;
  background: var(--surface-hover); overflow: hidden;
}
.ut-bar-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--brand-cyan), var(--brand-purple), var(--brand-orange), var(--brand-amber));
  background-size: 200% 100%;
  animation: utShimmer 2.4s linear infinite;
  transition: width 0.15s linear;
}
@keyframes utShimmer {
  from { background-position: 200% 0; }
  to   { background-position: 0 0; }
}
.ut-row.ok .ut-bar-fill { background: var(--success); }
.ut-row.err .ut-bar-fill { background: var(--danger); }

@media (max-width: 640px) {
  .container { padding: 20px 16px 64px; }
  .row { grid-template-columns: 1fr 70px 36px; padding: 10px 14px; }
  .col-mtime { display: none; }
  .col-actions { opacity: 1; }
  .nav a:not(.icon-only) { display: none; }
  .nav { gap: 10px; }
  .flashes { top: auto; bottom: 20px; right: 16px; left: 16px; max-width: none; }
}
