/* ---- Theme ----
   Light by default; dark follows the OS unless the user picked a theme with the
   toggle, which sets <html data-theme="light|dark"> (see theme.js). */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #fff;
  --text: #1f2328;
  --muted: #5f6b7a;
  --line: #e1e4e8;
  --hover: #eef0f3;
  --accent: #0f6cbd;
  --accent-text: #fff;
  --ok: #e6f4ea;
  --ok-text: #1e5e2f;
  --err: #fdecea;
  --err-text: #8a1c14;
  --danger: #c42b1c;
  --shadow: 0 6px 20px rgb(0 0 0 / .12);
  --show-sun: none;
  --show-moon: block;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16181c; --card: #1f2227; --text: #e6e8eb; --muted: #9aa4b2; --line: #2e333a; --hover: #272b31;
    --accent: #4c9be8; --accent-text: #0b1220; --ok: #173222; --ok-text: #9fd8b0; --err: #3a1a18; --err-text: #f2b3ad;
    --danger: #ff8a7a; --shadow: 0 6px 20px rgb(0 0 0 / .45);
    --show-sun: block; --show-moon: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181c; --card: #1f2227; --text: #e6e8eb; --muted: #9aa4b2; --line: #2e333a; --hover: #272b31;
  --accent: #4c9be8; --accent-text: #0b1220; --ok: #173222; --ok-text: #9fd8b0; --err: #3a1a18; --err-text: #f2b3ad;
  --danger: #ff8a7a; --shadow: 0 6px 20px rgb(0 0 0 / .45);
    --show-sun: block; --show-moon: none;
}

/* ---- Base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html.js .js-hide { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Top bar ---- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; color: var(--text); white-space: nowrap; }
.who { display: flex; gap: 14px; align-items: center; color: var(--muted); min-width: 0; }
.who .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who form { margin: 0; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; flex: none; }
.theme-toggle:hover { background: var(--hover); }
.theme-toggle svg { width: 18px; height: 18px; }
/* Each theme shows the icon for the theme you'd switch to. */
.theme-toggle .sun { display: var(--show-sun); }
.theme-toggle .moon { display: var(--show-moon); }

/* ---- Navigation ---- */
.tabs { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 20px; padding: 12px 24px 0; }
.tab-links { display: flex; gap: 4px; }
.tab-links a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tab-links a:hover { background: var(--hover); text-decoration: none; }
.tab-links a[aria-current="page"] { color: var(--accent); background: var(--hover); }
.search { flex: 0 1 420px; margin: 0; }
.search input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }

/* ---- Layout ---- */
main { padding: 16px 24px 32px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card.flush { padding: 0; }
.narrow { max-width: 440px; margin: 48px auto; }
.center { text-align: center; }
.crumbs { margin: 4px 0 12px; color: var(--muted); overflow-wrap: anywhere; }
.crumbs span { margin: 0 4px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; overflow-wrap: anywhere; }
.flash.success { background: var(--ok); color: var(--ok-text); }
.flash.error { background: var(--err); color: var(--err-text); }

/* ---- Buttons ---- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--accent); color: var(--accent-text); border: 1px solid transparent; border-radius: 6px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.button:hover { text-decoration: none; filter: brightness(1.08); }
.button.secondary { background: var(--card); color: var(--accent); border-color: var(--line); }
.button.secondary:hover { background: var(--hover); filter: none; }
.button.danger { color: var(--danger); }
.button:disabled { opacity: .45; cursor: default; filter: none; background: var(--card); }
.button.small { padding: 4px 10px; font-size: .9rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }

/* ---- Usage ---- */
.usage { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 12px; color: var(--muted); font-size: .9rem; }
.usage-bar { flex: 0 1 320px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); }
.usage-bar.full span { background: var(--danger); }

/* ---- Upload ---- */
.dropzone { border: 2px dashed var(--line); transition: border-color .15s, background .15s; }
.dropzone.dragging { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.upload { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.upload-pick { position: relative; }
.upload-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.upload-hint { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.progress { display: flex; flex-direction: column; gap: 8px; }
.progress-bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { color: var(--muted); overflow-wrap: anywhere; }
@media (hover: none) { .drag-only { display: none; } }

/* ---- Toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.toolbar-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- File tables ---- */
.files { width: 100%; border-collapse: collapse; }
.files th, .files td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.files tbody tr:last-child td { border-bottom: 0; }
.files tbody tr:hover { background: var(--hover); }
.files th { color: var(--muted); font-weight: 600; font-size: .85rem; white-space: nowrap; }
.files th:first-child, .files td:first-child { padding-left: 14px; }
.files th:last-child, .files td:last-child { padding-right: 14px; }
.files td.name { overflow-wrap: anywhere; }
.files .num { text-align: right; white-space: nowrap; }
.files .modified { white-space: nowrap; }
.files .empty { color: var(--muted); text-align: center; padding: 24px; }
.files th.check, .files td.check { width: 36px; }
.files input[type=checkbox] { width: 18px; height: 18px; margin: 0; vertical-align: middle; accent-color: var(--accent); }
.files td.actions { width: 48px; text-align: right; }
.files td.actions form { margin: 0; }
.files td.location { color: var(--muted); overflow-wrap: anywhere; }
.files .sub { display: none; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.dir::before { content: "📁 "; }
.file::before { content: "📄 "; }

/* ---- Row menu ---- */
.menu { position: relative; display: inline-block; }
.menu summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 32px; border-radius: 6px; color: var(--muted); font-weight: 700; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { background: var(--line); }
.menu-items { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 180px; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px 0; text-align: left; }
.menu-items a, .menu-items button { display: block; width: 100%; padding: 9px 14px; background: none; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu-items a:hover, .menu-items button:hover { background: var(--hover); text-decoration: none; }
.menu-items .danger { color: var(--danger); }

/* ---- Phones ---- */
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; }
  .who { gap: 10px; }
  .who .name { display: none; }
  .tabs { padding: 10px 16px 0; }
  .tab-links { flex: 1; }
  .tab-links a { flex: 1; text-align: center; }
  .search { flex: 1 1 100%; }
  .search input { font-size: 16px; } /* stops iOS zooming in on focus */
  main { padding: 12px 16px 24px; }
  h1 { font-size: 1.25rem; }

  .usage-bar { flex: 1 1 100%; }

  .upload { flex-direction: column; align-items: stretch; text-align: center; }
  .upload .button { width: 100%; padding: 12px 16px; }

  .toolbar, .toolbar-group { flex-wrap: nowrap; }
  .toolbar { gap: 6px; }
  .toolbar-group { gap: 6px; flex: 2; }
  .toolbar-group:last-child { flex: 1; }
  .toolbar .button { flex: 1; padding: 8px 6px; font-size: .9rem; }
  .toolbar .wide { display: none; }

  .files th.modified, .files td.modified, .files th.location, .files td.location, .files th.hide-sm, .files td.hide-sm { display: none; }
  .files .sub { display: block; }
  .files th:first-child, .files td:first-child { padding-left: 10px; }
  .files th:last-child, .files td:last-child { padding-right: 8px; }
  .files td { padding-top: 10px; padding-bottom: 10px; }
}
