:root {
  --bg: #f5f6f8; --card: #fff; --text: #1c1f26; --muted: #6b7280; --line: #e5e7eb;
  --accent: #4f46e5; --accent-text: #fff; --hover: #f1f2f6; --danger: #dc2626;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --card: #1a1d24; --text: #e7e9ee; --muted: #9aa1ae; --line: #2a2e38;
    --accent: #818cf8; --accent-text: #11131a; --hover: #232732; --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 1000px; margin: 0 auto; padding: 24px 16px 96px; }
a { color: inherit; text-decoration: none; }
h1, h2 { margin: 0; font-size: 1.1rem; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
/* The UA `hidden` rule loses to any `display` we set below, so restate it. */
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.topbar nav a:hover { background: var(--hover); }
.topbar nav a[aria-current] { color: var(--text); background: var(--hover); font-weight: 600; }
.who { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---- cards and tables ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
        box-shadow: var(--shadow); overflow: hidden; }
.page-title { margin-bottom: 16px; font-size: 1.25rem; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; white-space: nowrap; font-size: .78rem; font-weight: 600; text-transform: uppercase;
     letter-spacing: .04em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); }
td { padding: 6px 16px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
.num { text-align: right; }
td.name { width: 100%; max-width: 0; }  /* lets long names truncate instead of widening the table */
td.name a { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-weight: 500; }
td.name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.name a:hover span { text-decoration: underline; }
td.name svg { color: var(--muted); }
td.name svg.folder { color: var(--accent); fill: color-mix(in srgb, var(--accent) 18%, transparent); }
.row-actions { white-space: nowrap; text-align: right; }
.path { word-break: break-all; }
.empty { padding: 56px 16px; text-align: center; }
.empty svg { width: 36px; height: 36px; }
.tag { padding: 2px 8px; border-radius: 99px; font-size: .8rem; background: var(--hover); }
.tag-delete { color: var(--danger); }
.tag-upload { color: var(--accent); }

/* ---- files page ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1;
          font-size: 1.1rem; color: var(--muted); }
.crumbs a { padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--hover); }
.crumbs a[aria-current], .crumbs a:only-child { color: var(--text); font-weight: 600; }
.actions { display: flex; gap: 8px; }
tr[draggable] { cursor: grab; }
tr.dragging { opacity: .4; }
.drop-target, tbody tr.drop-target { background: color-mix(in srgb, var(--accent) 18%, transparent);
                                     outline: 2px dashed var(--accent); outline-offset: -2px; }
#move-dialog select { margin-top: 6px; }
#drop-hint {
  position: fixed; inset: 12px; z-index: 20; display: grid; place-items: center;
  border: 3px dashed var(--accent); border-radius: 16px; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 1.4rem; font-weight: 600; color: var(--accent);
}

/* ---- upload panel ---- */
#uploads, #others { position: fixed; bottom: 16px; z-index: 10;
                    width: min(380px, calc(100vw - 32px)); }
#uploads { right: 16px; }
#others { left: 16px; }
#overall { padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: .85rem; }
#overall progress { height: 8px; margin-bottom: 4px; }
#others header { padding: 8px 16px; border-bottom: 1px solid var(--line); }
#others h2 { margin: 0; font-size: 1rem; }
#uploads header { display: flex; justify-content: space-between; align-items: center;
                  padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
#uploads ul, #others ul { list-style: none; margin: 0; padding: 4px 16px; max-height: 40vh; overflow-y: auto; }
#uploads li, #others li { padding: 10px 0; border-bottom: 1px solid var(--line); }
#uploads li:last-child, #others li:last-child { border-bottom: 0; }
#uploads .up-name, #others .up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
#uploads .up-status, #others .up-status { display: flex; justify-content: space-between; align-items: center;
                      font-size: .85rem; color: var(--muted); min-height: 24px; }
#uploads li.failed .up-status { color: var(--danger); }
#uploads li.done progress { accent-color: #16a34a; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }

/* ---- dialogs, toast, login ---- */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(400px, 90vw);
         background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog form { display: grid; gap: 14px; margin: 0; }
dialog p { margin: 0; word-break: break-word; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
input:not([type=hidden]), select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
#toast { position: fixed; left: 50%; bottom: 24px; translate: -50%; z-index: 30;
         padding: 10px 16px; border-radius: 8px; background: var(--danger); color: #fff;
         box-shadow: var(--shadow); max-width: 90vw; }
.login { max-width: 360px; margin: 12vh auto 0; padding: 28px; display: grid; gap: 14px; }
.login h1 { font-size: 1.5rem; color: var(--accent); }
.login p { margin: 0; }
.login label { display: grid; gap: 4px; font-weight: 500; }

@media (max-width: 640px) {
  .wide { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
  .who span { display: none; }
  th, td { padding-left: 10px; padding-right: 10px; }
}
