:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --hover: #eef2f7;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1f26;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --border: #2c333d;
    --accent: #4f8cff;
    --danger: #ff6b6b;
    --hover: #232a33;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, .button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  display: inline-block;
}
button:hover, .button:hover { background: var(--hover); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .6; cursor: default; }
input {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input.wide { width: 100%; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card label { display: grid; gap: 6px; font-size: 14px; }
.card .error { margin: 0; }
.card .error:empty { display: none; }

/* layout */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-size: 17px; }
.spacer { flex: 1; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  flex-wrap: wrap;
}
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-weight: 600; min-width: 0; }
.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs .sep { color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#sel-actions { display: inline-flex; gap: 8px; align-items: center; }

/* file table */
.files {
  width: calc(100% - 32px);
  margin: 0 16px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.files th, .files td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.files tbody tr:last-child td { border-bottom: 0; }
.files th { font-size: 13px; color: var(--muted); font-weight: 600; }
.files th .sort { border: 0; background: none; padding: 0; color: inherit; font-weight: inherit; }
.files tbody tr:hover { background: var(--hover); }
.files button.name {
  border: 0;
  background: none;
  padding: 4px 0;
  text-align: left;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-check { width: 40px; }
.col-size { width: 90px; }
.col-date { width: 180px; }
.col-menu { width: 52px; text-align: right; }
.empty { text-align: center; padding: 32px; }

/* uploads */
.uploads {
  margin: 16px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.uploads h2 { font-size: 15px; margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.uploads ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.uploads li { display: grid; grid-template-columns: 1fr 120px 110px; gap: 10px; align-items: center; font-size: 14px; }
.uploads li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
progress { width: 100%; }

/* overlays */
#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(37, 99, 235, .15);
  border: 3px dashed var(--accent);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
}
#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100% - 32px);
  z-index: 20;
}
#toast.error { background: var(--danger); color: #fff; }

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
  width: min(520px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 12px; font-size: 17px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
dialog.menu .dialog-actions { flex-direction: column; align-items: stretch; margin-top: 0; }
dialog.wide { width: min(1000px, calc(100% - 32px)); }
.preview { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; }
.folder-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.folder-list button { width: 100%; text-align: left; border-radius: 0; }
.folder-list:empty::after { content: "No subfolders"; display: block; padding: 10px; color: var(--muted); }

@media (max-width: 640px) {
  .col-date { display: none; }
  .uploads li { grid-template-columns: 1fr 80px; }
  .uploads li span.muted { grid-column: 1 / -1; }
}
