:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2128;
  --muted: #667080;
  --border: #dde1e7;
  --hover: #f0f2f5;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #c62f2f;
  --danger-bg: #fdecec;
  --ok: #1a7f37;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --surface: #1c2026;
    --text: #e6e9ee;
    --muted: #98a1ae;
    --border: #2f353d;
    --hover: #262b32;
    --accent: #4c8dff;
    --accent-text: #0b0e12;
    --danger: #ff7b72;
    --danger-bg: #3a1d1d;
    --ok: #4ac26b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }

button, .button-link, select, input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
}
button, .button-link { cursor: pointer; }
button:hover, .button-link:hover { background: var(--hover); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.muted { color: var(--muted); }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Login and setup */
.centered { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.login { display: grid; gap: 12px; }
.login label { display: grid; gap: 4px; }
.login input { width: 100%; }
.form-error { color: var(--danger); margin: 0 0 12px; }

/* Layout */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.bucket-picker { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.bucket-picker select { max-width: 50vw; color: var(--text); }
.signout { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.content { max-width: 1200px; margin: 0 auto; padding: 16px; }

.breadcrumbs { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 12px; font-size: 15px; overflow-wrap: anywhere; }
.breadcrumbs .sep { color: var(--muted); }
.breadcrumbs [aria-current] { color: var(--text); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 0 1 260px; min-width: 140px; }

.notice { margin: 0 0 12px; padding: 8px 12px; border-radius: 6px; background: var(--hover); }
.notice.error { background: var(--danger-bg); color: var(--danger); }

/* Listing */
.listing {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.listing th, .listing td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.listing tbody tr:last-child td { border-bottom: 0; }
.listing tbody tr:hover { background: var(--hover); }
.listing th { padding: 4px 6px; font-weight: 600; }
.listing .num { text-align: right; white-space: nowrap; width: 110px; font-variant-numeric: tabular-nums; }
.listing .date { white-space: nowrap; width: 190px; color: var(--muted); }
.listing .actions { width: 110px; text-align: right; }
.listing .name { overflow-wrap: anywhere; }

.sort { border: 0; background: none; padding: 4px 6px; font-weight: 600; color: var(--muted); }
th[aria-sort="ascending"] .sort::after { content: " ▲"; font-size: 10px; }
th[aria-sort="descending"] .sort::after { content: " ▼"; font-size: 10px; }
th.num .sort { float: right; }

.entry { color: var(--text); }
.entry.folder { font-weight: 600; }
.entry.folder::before { content: ""; display: inline-block; width: 14px; height: 10px; margin-right: 8px; border-radius: 2px; background: #d9a441; }
.entry.file::before { content: ""; display: inline-block; width: 10px; height: 13px; margin: 0 10px 0 2px; border-radius: 2px; border: 1.5px solid var(--muted); vertical-align: -1px; }
.button-link { display: inline-block; padding: 3px 10px; color: var(--text); }

.empty { padding: 32px; text-align: center; color: var(--muted); }
.more { text-align: center; margin-top: 12px; }

/* Upload panel */
.uploads {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(420px, calc(100vw - 32px));
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.22);
}
.uploads > header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.uploads > header button, .upload-head button { padding: 2px 8px; font-size: 12px; }
#upload-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#upload-list li { padding: 8px 12px; border-bottom: 1px solid var(--border); }
#upload-list li:last-child { border-bottom: 0; }
.upload-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.upload-info { font-size: 12px; overflow-wrap: anywhere; }
progress { display: block; width: 100%; height: 6px; margin: 6px 0 4px; accent-color: var(--accent); }
li[data-status="failed"] .upload-info { color: var(--danger); }
li[data-status="done"] .upload-info { color: var(--ok); }

.drop-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(31 111 235 / 0.16);
  border: 3px dashed var(--accent);
  pointer-events: none;
  font-size: 20px;
  font-weight: 600;
}
.drop-overlay span { background: var(--surface); padding: 12px 24px; border-radius: 8px; }

@media (max-width: 640px) {
  .listing .date { display: none; }
  .listing .num { width: auto; }
  .listing .actions { width: auto; }
  .toolbar input[type="search"] { flex-basis: 100%; }
  .toolbar .spacer { display: none; }
}
