:root {
  --paper: #f6f4ef;
  --panel: #fdfcf9;
  --ink: #191714;
  --muted: #6d675e;
  --rule: #d8d3c8;
  --accent: #c1440e;
  --accent-ink: #fff;
  --danger: #a41623;
  --mono: "Cascadia Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  border-top: 4px solid var(--accent);
}

.wrap { max-width: 780px; margin: 0 auto; padding: 0 20px; width: 100%; }

.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* masthead */
header { border-bottom: 1px solid var(--rule); background: var(--panel); }
.masthead { display: flex; align-items: baseline; gap: 12px; padding-top: 14px; padding-bottom: 14px; }
.brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.brand::before { content: "▮ "; color: var(--accent); }
.tag { color: var(--muted); font-size: 13px; }
.session { font-size: 13px; color: var(--muted); }
.session b { font-family: var(--mono); color: var(--ink); font-weight: 600; }

main { flex: 1; padding: 28px 0 48px; }

.intro { max-width: 56ch; color: var(--muted); margin: 0 0 26px; }

/* landing panes */
.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 640px) { .panes { grid-template-columns: 1fr; } }

.pane {
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: 18px 20px 20px;
}
.pane h2 {
  margin: 0 0 14px;
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin: 12px 0 4px;
}
label .hint { font-weight: 400; color: var(--muted); }

input[type="text"], input[type="password"] {
  width: 100%;
  font: 14px var(--mono);
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button[type="submit"] {
  margin-top: 16px;
  width: 100%;
  font: 600 14px var(--sans);
  padding: 9px 12px;
  background: var(--ink);
  color: var(--accent-ink);
  border: none;
  border-radius: 0;
  cursor: pointer;
}
button[type="submit"]:hover { background: var(--accent); }
button[type="submit"]:active { transform: translateY(1px); }

.linkish {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.linkish.danger { color: var(--danger); }

.formerr { color: var(--danger); font-size: 13px; min-height: 1.2em; margin: 10px 0 0; }

/* bucket view */
.bucket-bar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
  margin-bottom: 18px;
}
.bucket-bar h2 { margin: 0; font-size: 20px; font-weight: 700; }
.bucket-bar h2::before { content: "/"; color: var(--accent); margin-right: 2px; }

#dropzone {
  border: 1px dashed var(--muted);
  background: var(--panel);
  padding: 22px 20px;
  text-align: center;
  color: var(--muted);
  margin-bottom: 22px;
}
#dropzone.drag { border-color: var(--accent); border-style: solid; color: var(--ink); background: #fff; }
#dropzone p { margin: 0; }
#dropzone b { color: var(--ink); }
.browse { display: inline; font-weight: 600; color: var(--accent); text-decoration: underline; cursor: pointer; margin: 0; font-size: inherit; }
#file-input { display: none; }

.progress { margin-top: 14px; display: flex; align-items: center; gap: 10px; }
.progress-bar {
  flex: 1;
  height: 10px;
  background: var(--rule);
  position: relative;
  overflow: hidden;
}
.progress-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--pct, 0%);
  background: var(--accent);
  transition: width 0.15s linear;
}
.progress-text { font-size: 12px; color: var(--ink); min-width: 4ch; text-align: right; }

/* file table */
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  border-bottom: 1px solid var(--ink);
  padding: 6px 8px;
}
td { padding: 7px 8px; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
.num { text-align: right; white-space: nowrap; }
td.name { word-break: break-all; }
td.name a { color: var(--ink); text-decoration: none; }
td.name a:hover { color: var(--accent); text-decoration: underline; }
tr:hover td { background: var(--panel); }
td .linkish { font-family: var(--mono); font-size: 12px; text-decoration: none; }
td .linkish:hover { text-decoration: underline; }
td .actions { display: inline-flex; gap: 12px; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; border-bottom: 1px solid var(--rule); margin: 0; }

/* admin */
.admin-login { max-width: 340px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  margin-bottom: 8px;
}
.stat {
  background: var(--panel);
  padding: 12px 14px;
}
.stat .k {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 2px;
}
.stat .v { font-family: var(--mono); font-size: 17px; font-weight: 600; }

.subhead {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 28px 0 8px;
}

td.path { color: var(--muted); font-size: 11px; word-break: break-all; }

.kv-table { width: 100%; }
.kv-table td:first-child { color: var(--muted); width: 200px; }

footer { border-top: 1px solid var(--rule); background: var(--panel); }
footer a { color: var(--muted); }
footer .wrap { padding-top: 10px; padding-bottom: 10px; font-size: 11px; color: var(--muted); }

/* preview modal */
#preview {
  position: fixed;
  inset: 0;
  background: rgba(25, 23, 20, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.pv-panel {
  background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(25, 23, 20, 0.35);
  max-width: min(960px, 94vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  min-width: min(420px, 94vw);
}
.pv-bar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
}
.pv-name { font-size: 13px; font-weight: 600; word-break: break-all; }
.pv-meta, .pv-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
.pv-bar .linkish { text-decoration: none; white-space: nowrap; }
.pv-bar .linkish:hover { text-decoration: underline; }
.pv-bar .linkish:disabled { color: var(--rule); cursor: default; text-decoration: none; }
.pv-body {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  min-height: 120px;
}
.pv-body img, .pv-body video {
  max-width: 100%;
  max-height: calc(90vh - 90px);
  display: block;
}
.pv-body audio { width: min(480px, 80vw); }
.pv-body iframe {
  border: none;
  width: min(900px, 90vw);
  height: calc(90vh - 90px);
  background: #fff;
}
.pv-body pre {
  align-self: stretch;
  margin: 0;
  font: 12px/1.5 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 12px 14px;
  width: min(860px, 90vw);
  max-height: calc(90vh - 90px);
  overflow: auto;
}
.pv-note { color: var(--muted); font-size: 12px; }

/* toast */
#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  padding: 8px 14px;
  max-width: 90vw;
}
