:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #667085;
  --border: #e4e7ec;
  --hover: #f2f4f7;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --shadow: 0 8px 30px rgba(16, 24, 40, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e7e9ee;
    --muted: #98a2b3;
    --border: #2a2f38;
    --hover: #20242c;
    --accent: #3b82f6;
    --danger: #f87171;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

input[type="text"], input[type="password"], input[type="search"], select {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.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 { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { padding: 2px 8px; font-size: 13px; }
.btn.icon { padding: 4px 8px; border-color: transparent; background: transparent; }
.btn.icon:hover { background: var(--hover); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card .btn { justify-content: center; padding: 10px; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; text-decoration: none; }
#search { max-width: 360px; }
.stats { margin-left: auto; font-size: 13px; }

.content { max-width: 1100px; margin: 0 auto; padding: 20px 24px 120px; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 16px; min-height: 34px; }
.crumbs a { text-decoration: none; padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--hover); }
.crumbs .current { font-weight: 600; padding: 2px 6px; }
.crumbs .sep { color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bulk { display: inline-flex; align-items: center; gap: 8px; padding-right: 8px; border-right: 1px solid var(--border); }

/* File list */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.list td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: var(--hover); }
.list tr.drop-target { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.col-check { width: 36px; }
.col-num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-date { white-space: nowrap; width: 130px; }
.col-actions { width: 48px; text-align: right; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name-cell a, .name-cell span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.name-cell a:hover { text-decoration: underline; }
.badge {
  flex: none;
  width: 34px;
  height: 26px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.folder { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-color: transparent; }
.sub { font-size: 12px; color: var(--muted); }
.empty { padding: 48px 16px; text-align: center; }
.empty p { margin: 4px 0; }

/* Context menu */
.menu {
  position: fixed;
  z-index: 20;
  min-width: 190px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  background: var(--card);
  color: var(--text);
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog.wide { width: min(720px, calc(100vw - 32px)); }
dialog h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog p { margin: 0 0 12px; word-break: break-word; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.tree { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.tree button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.tree button:hover { background: var(--hover); }
.tree button.selected { background: var(--accent); color: var(--accent-text); }
.tree button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Info dialog */
.info h2 { word-break: break-word; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.links { border: 1px solid var(--border); border-radius: 10px; }
.link-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.link-row:last-child { border-bottom: 0; }
.link-main { flex: 1; min-width: 0; }
.link-label { font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.link-label .sub { font-weight: 400; }
.link-url { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.link-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
a.btn { text-decoration: none; }
.link-form { display: flex; gap: 8px; }
.slug-input {
  flex: 1;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding-left: 10px;
  background: var(--card);
  min-width: 0;
}
.slug-input:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.slug-input span { white-space: nowrap; }
.slug-input input { border: 0; padding-left: 0; outline: none; min-width: 0; }
.info .error { margin-top: 8px; }
.pill {
  flex: none;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 600;
}

/* Links dialog */
.links-table-wrap { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 10px; }
.links-table td { vertical-align: middle; }
.links-table code { white-space: nowrap; }
.links-table .link-actions { flex-wrap: nowrap; }
.cell-file { overflow-wrap: anywhere; }
.empty-links { padding: 24px; text-align: center; margin: 0; }

/* Drag & drop */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 3px dashed var(--accent);
  pointer-events: none;
  font-size: 22px;
  font-weight: 600;
}
.drop-overlay div { background: var(--card); padding: 16px 28px; border-radius: 12px; box-shadow: var(--shadow); }

/* Upload panel */
.uploads {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  width: min(380px, calc(100vw - 32px));
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.uploads header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.uploads ul { list-style: none; margin: 0; padding: 0; overflow: auto; }
.uploads li { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.uploads li:last-child { border-bottom: 0; }
.up-row { display: flex; align-items: center; gap: 8px; }
.up-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.up-status.error { color: var(--danger); }
.progress { height: 4px; margin-top: 6px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.progress.done div { background: #16a34a; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .link-row { flex-direction: column; align-items: stretch; }
  .link-actions { justify-content: flex-start; }
  .link-form { flex-direction: column; }
  .links-table thead { display: none; }
  .links-table tr { display: grid; grid-template-columns: 1fr auto; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .links-table td { border: 0; padding: 2px 8px; }
  .links-table td.col-link-actions { grid-column: 1 / -1; }
  .links-table .link-actions { flex-wrap: wrap; justify-content: flex-start; }
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .stats { display: none; }
  #links-btn { margin-left: auto; }
  #search { order: 3; max-width: none; }
  .content { padding: 16px 16px 120px; }
  .col-date, .col-dl { display: none; }
  .list td, .list th { padding: 8px; }
}
