:root {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #1f2229;
  --line: #2c3039;
  --text: #ecedf0;
  --muted: #a3a8b4;          /* 7.6:1 on --bg */
  --accent: #ffb547;         /* warm amber */
  --accent-ink: #14110c;
  --danger: #ff7a6b;
  --ok: #6fdc9a;
  --radius: 10px;
  --focus: 0 0 0 3px rgba(255, 181, 71, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 8px; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 1rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #444a56; background: #262a32; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: #ffc46e; border-color: #ffc46e; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 36px; padding: 0 .7rem; font-size: .9rem; }
.btn-big { min-height: 56px; padding: 0 2rem; font-size: 1.1rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label { display: grid; gap: .35rem; font-weight: 600; }
input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; min-height: 44px; padding: 0 .8rem; width: 100%;
}
input:focus { border-color: var(--accent); }
.hint { font-weight: 400; font-size: .875rem; color: var(--muted); }
.form-error { color: var(--danger); margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.stack { display: grid; gap: 1rem; }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 800; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: url(/favicon.svg) center/cover; flex: none; }
.brand-lg { font-size: 1.5rem; }
.brand-lg .brand-mark { width: 40px; height: 40px; border-radius: 10px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; }
.auth-card > p { margin: .5rem 0 1.5rem; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 1.5rem; }
.tabs button { min-height: 40px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: .75rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.quota { display: flex; align-items: center; gap: .75rem; margin-left: auto; font-size: .9rem; color: var(--muted); }
.quota-bar { width: 160px; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.quota-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.quota.full .quota-bar span { background: var(--danger); }
.topnav { display: flex; align-items: center; gap: .25rem; }
.topnav a { color: var(--text); text-decoration: none; padding: .6rem .8rem; border-radius: 8px; font-weight: 600; }
.topnav a:hover { background: var(--surface-2); }
.topnav a[aria-current="page"] { color: var(--accent); }
.me { color: var(--muted); font-weight: 400; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; outline: none; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem; font-size: 1.15rem; font-weight: 700; }
.crumbs a { color: var(--muted); text-decoration: none; padding: .25rem .4rem; border-radius: 6px; }
.crumbs a:hover { color: var(--text); background: var(--surface-2); }
.crumbs span[aria-current] { padding: .25rem .4rem; }
.crumbs .sep { color: var(--line); }

/* ---------- Drop zone ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: 14px; padding: 1.5rem; text-align: center; margin-bottom: 1.25rem;
  transition: border-color .15s, background .15s;
}
.dropzone p { margin: .2rem 0; }
.dropzone.over, body.dragging .dropzone { border-color: var(--accent); background: rgba(255, 181, 71, .07); }

/* ---------- Uploads ---------- */
.uploads { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.uploads ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .9rem; }
.up-item { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; align-items: center; }
.up-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-stats { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.up-bar { grid-column: 1 / -1; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.up-bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.up-item.done .up-bar span { background: var(--ok); }
.up-item.error .up-bar span { background: var(--danger); }
.up-item.error .up-stats { color: var(--danger); }

/* ---------- File table ---------- */
.listing, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.files { width: 100%; border-collapse: collapse; }
.files th { text-align: left; font-size: .875rem; color: var(--muted); font-weight: 600; padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
.files td { padding: .6rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.files tr:last-child td { border-bottom: 0; }
.files tbody tr:hover { background: var(--surface-2); }
.files tbody tr:hover .icon:not(.folder) { background: var(--bg); }
.col-size, .col-date { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-act { width: 1%; white-space: nowrap; text-align: right; }
.row-actions { display: flex; gap: .25rem; justify-content: flex-end; }
.name-cell { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.name-cell a, .name-cell .fname { color: var(--text); text-decoration: none; font-weight: 600; overflow-wrap: anywhere; }
.name-cell a:hover { color: var(--accent); }
.icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex: none; background: var(--surface-2); font-size: .75rem; font-weight: 800; color: var(--muted); letter-spacing: .02em; }
.icon.folder { background: rgba(255, 181, 71, .14); color: var(--accent); }
.icon.folder::before { content: ""; width: 18px; height: 14px; background: var(--accent); border-radius: 2px 4px 3px 3px; clip-path: polygon(0 0, 45% 0, 55% 18%, 100% 18%, 100% 100%, 0 100%); }
.badge { display: inline-block; font-size: .8rem; font-weight: 700; color: var(--ok); border: 1px solid rgba(111, 220, 154, .4); border-radius: 99px; padding: 0 .5rem; margin-left: .4rem; white-space: nowrap; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); margin: 0; }

/* ---------- Admin ---------- */
.admin-grid { display: grid; grid-template-columns: minmax(280px, 1fr) 2fr; gap: 1.25rem; align-items: start; }
.panel { padding: 1.25rem; }
.panel .files th, .panel .files td { padding-left: .5rem; padding-right: .5rem; }
.table-wrap { overflow-x: auto; }
.plain-list { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .6rem; }
.invite { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; display: grid; gap: .3rem; }
.invite code { font-size: 1rem; overflow-wrap: anywhere; color: var(--text); }
.invite .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .9rem; color: var(--muted); }

/* ---------- Dialog & toast ---------- */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 1.5rem; width: min(440px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0; }
dialog p { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(150%);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1.2rem;
  transition: transform .2s; max-width: calc(100vw - 2rem); z-index: 100;
}
.toast:not(.show) { visibility: hidden; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); }

/* ---------- Public share page ---------- */
.share-body { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.share-card { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; }
.share-content { margin-top: 2rem; display: grid; gap: 1.25rem; justify-items: start; }
.share-content h1 { margin: 0; }
.eyebrow { margin: 0; color: var(--muted); font-weight: 600; }
.filename { overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 1.5rem; margin: 0; }
.meta dt { color: var(--muted); font-size: .875rem; }
.meta dd { margin: 0; font-weight: 700; font-size: 1.05rem; }
.small-note { margin: 0; font-size: .9rem; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .topbar { padding: .75rem 1rem; gap: .75rem; }
  .quota { order: 3; width: 100%; margin-left: 0; }
  .quota-bar { flex: 1; }
  .topnav { margin-left: auto; flex-wrap: wrap; }
  main { padding: 1rem; }
  .col-date { display: none; }
  .files td, .files th { padding-left: .6rem; padding-right: .6rem; }
  .row-actions { flex-wrap: wrap; }
  .admin-grid { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 auto; }
}
@media (max-width: 600px) {
  #page-files .files thead { display: none; }
  #page-files .files tbody tr { display: grid; grid-template-columns: 1fr auto; align-items: center; border-bottom: 1px solid var(--line); padding: .4rem 0; }
  #page-files .files tbody tr:last-child { border-bottom: 0; }
  #page-files .files td { border-bottom: 0; padding-top: .3rem; padding-bottom: .3rem; }
  #page-files .files td.col-date { display: none; }
  #page-files .files td.col-act { grid-column: 1 / -1; width: auto; }
  #page-files .row-actions { justify-content: flex-start; }
}
@media (max-width: 480px) {
  .auth-card, .share-card { padding: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
