:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #dcdcd6;
  --text: #1d1d1b;
  --muted: #6b6b63;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --danger: #a3342a;
  --ok-bg: #e7f2ec;
  --error-bg: #fbeae8;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1e2024;
    --border: #33363c;
    --text: #e8e8e4;
    --muted: #9a9a92;
    --accent: #7fb3a1;
    --accent-text: #10221c;
    --danger: #e08076;
    --ok-bg: #1d2f28;
    --error-bg: #33211f;
  }
}

* {
  box-sizing: border-box;
}

/*
 * An author `display` rule outranks the user-agent stylesheet's
 * `[hidden] { display: none }`, so anything given an explicit display below
 * would still show while hidden. Restore the expected behaviour once, here.
 */
[hidden] {
  display: none !important;
}

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

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

h1,
h2 {
  margin: 0 0 0.75rem;
  font-weight: 600;
  font-size: 1.1rem;
}

h1 {
  font-size: 1.35rem;
}

/* --- top bar ------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar nav a {
  color: var(--muted);
  text-decoration: none;
}

.topbar nav a:hover,
.topbar nav a.current {
  color: var(--text);
}

.topbar nav a.current {
  font-weight: 600;
}

.who {
  color: var(--muted);
  border-left: 1px solid var(--border);
  padding-left: 1rem;
}

form.inline {
  display: inline;
}

/* --- cards and forms ---------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1.25rem;
}

label {
  display: block;
  margin-bottom: 0.7rem;
  color: var(--muted);
  font-size: 0.85rem;
}

label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text);
  font-size: 0.9rem;
}

input[type="text"],
input[type="search"],
input[type="password"],
input[type="file"],
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.55rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

label.checkbox input {
  width: auto;
  margin: 0;
}

textarea {
  resize: vertical;
}

button,
.button {
  display: inline-block;
  padding: 0.42rem 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

button:hover:not(:disabled),
.button:hover {
  border-color: var(--muted);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 500;
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

button.link {
  padding: 0;
  background: none;
  border: none;
  color: var(--accent);
  text-align: left;
}

button.link:hover {
  text-decoration: underline;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0 1rem;
  align-items: end;
}

.grid-form button {
  margin-bottom: 0.7rem;
}

/* --- login -------------------------------------------------------------- */

.login-wrap {
  display: flex;
  justify-content: center;
  padding-top: 3rem;
}

.login {
  width: 100%;
  max-width: 340px;
}

.login button {
  width: 100%;
}

/* --- upload ------------------------------------------------------------- */

.upload-row {
  display: flex;
  gap: 1rem;
  align-items: end;
  flex-wrap: wrap;
}

.grow {
  flex: 1 1 200px;
}

#upload-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

#upload-status progress {
  flex: 1;
  height: 0.6rem;
}

#upload-percent {
  min-width: 5.5rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- toolbar and tables ------------------------------------------------- */

.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.toolbar label {
  margin-bottom: 0;
}

table.files {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.files th,
table.files td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.files th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.files td.num,
table.files th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.date,
td.ip {
  white-space: nowrap;
  color: var(--muted);
}

td.description {
  color: var(--muted);
  max-width: 22rem;
}

td.actions,
th.actions {
  text-align: right;
  white-space: nowrap;
}

tr.inactive td {
  opacity: 0.55;
}

tr.failure td.summary {
  color: var(--danger);
}

.tag {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tag.root,
.tag.failure {
  color: var(--danger);
  border-color: var(--danger);
}

.tag.success {
  color: var(--accent);
  border-color: var(--accent);
}

.empty {
  padding: 1.5rem 0;
  color: var(--muted);
  text-align: center;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.pager-buttons {
  display: flex;
  gap: 0.5rem;
}

/* --- logs --------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.6rem;
}

.tabs a {
  padding: 0.4rem 0;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.tabs a.current {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

table.logs td.summary {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

table.logs summary {
  cursor: pointer;
}

table.logs pre {
  margin: 0.5rem 0 0;
  padding: 0.6rem;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
}

/* --- dialog ------------------------------------------------------------- */

dialog.file-dialog {
  width: min(680px, 92vw);
  padding: 1.1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

dialog h2 {
  margin: 0;
  word-break: break-word;
}

dl.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  margin: 0 0 0.9rem;
  font-size: 0.85rem;
}

dl.meta div {
  display: flex;
  gap: 0.35rem;
}

dl.meta dt {
  color: var(--muted);
}

dl.meta dd {
  margin: 0;
}

dd.hash {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  word-break: break-all;
}

.preview {
  margin-bottom: 0.9rem;
  text-align: center;
}

.preview img,
.preview video {
  max-width: 100%;
  max-height: 46vh;
  border-radius: var(--radius);
}

.preview audio {
  width: 100%;
}

.preview iframe {
  width: 100%;
  height: 46vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

/* --- notices ------------------------------------------------------------ */

.notice {
  margin: 0.7rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
}

.notice.error {
  background: var(--error-bg);
  color: var(--danger);
}

.notice.ok {
  background: var(--ok-bg);
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  table.files td.description,
  table.files th:nth-child(2) {
    display: none;
  }
}
