:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #5f6772;
  --accent: #b3123b;
  --accent-soft: #fbe9ee;
  --ok: #1a7f4b;
  --err: #c02626;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f24;
    --surface-2: #23272e;
    --border: #333941;
    --text: #e9ebee;
    --muted: #9aa3ae;
    --accent: #ff5c81;
    --accent-soft: #2b1a20;
    --ok: #4cc38a;
    --err: #ff6b6b;
  }
}

* { box-sizing: border-box; }

/*
 * The hidden attribute must win over any display rule below. An author rule
 * such as `.boot { display: flex }` beats the browser's `[hidden]` rule,
 * which would otherwise leave hidden panels and buttons on screen.
 */
[hidden] { display: none !important; }

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

h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 0.95rem; margin: 0; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }

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

.boot {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--muted);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 380px;
  text-align: center;
}

.login-card h1 { margin-bottom: 8px; color: var(--text); }
.login-card p { color: var(--muted); }
.login-card button { margin-top: 12px; width: 100%; }

/* ---------- chrome ---------- */

/*
 * Three tracks: brand, navigation, session. The side tracks share the leftover
 * space equally, so the navigation sits in the middle of the header and stays
 * there whatever the length of the email address next to it.
 */
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }

.navbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.session {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.user-email { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 760px) {
  header {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 12px;
  }

  .session { justify-content: center; }
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

/* ---------- buttons ---------- */

button, .download {
  font: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
}

button.primary, .download {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  display: inline-block;
}

button.primary:hover, .download:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.5; cursor: default; filter: none; }

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

button.ghost:hover { color: var(--text); border-color: var(--muted); }
button.remove { padding: 4px 8px; line-height: 1; }

/* ---------- dropzone ---------- */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-icon { font-size: 28px; color: var(--accent); display: block; }
.dropzone-title { margin: 12px 0 4px; font-size: 1.05rem; font-weight: 600; }
.dropzone-hint { margin: 0; color: var(--muted); }
.dropzone-rule { margin: 16px 0 0; color: var(--muted); font-size: 0.8rem; }

/* ---------- queue ---------- */

#queue-section { margin-top: 28px; }

.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.queue-actions { display: flex; gap: 8px; }

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.item[data-state="done"] { border-left-color: var(--ok); }
.item[data-state="error"] { border-left-color: var(--err); }
.item[data-state="uploading"], .item[data-state="converting"] { border-left-color: var(--accent); }

.item-main { min-width: 0; flex: 1; }
.item-name { font-weight: 600; word-break: break-all; }
.item-meta { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.item[data-state="error"] .item-meta { color: var(--err); }

.item-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.state { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

.progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
  display: none;
}

.item[data-state="uploading"] .progress { display: block; }

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s;
}

.error-text { color: var(--err); font-size: 0.85rem; }

/* ---------- voci di navigazione ---------- */

/*
 * Rendered as navbar links. They stay <button> elements because they perform an
 * action rather than navigate: that keeps keyboard and screen reader behaviour
 * correct without inventing an href that leads nowhere.
 */
.navlink {
  background: none;
  border: none;
  padding: 4px 2px;
  color: var(--muted);
  font-size: 0.88rem;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  border-radius: 0;
}

.navlink:hover { color: var(--text); border-bottom-color: var(--accent); }
.navlink:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- contenuti testuali ---------- */

.doc { font-size: 0.92rem; }
.doc .lead { margin-top: 0; font-size: 1rem; }

.doc h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 24px 0 8px;
}

.doc p { margin: 0 0 10px; }
.doc ul, .doc ol { margin: 0 0 10px; padding-left: 22px; }
.doc li { margin-bottom: 5px; }

.doc code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  word-break: break-all;
}

/* ---------- utenti ---------- */

.dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(80vh, 720px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

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

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.dialog-head h2 {
  color: var(--text);
  font-size: 1.05rem;
  text-transform: none;
  letter-spacing: normal;
}

.table-scroll { overflow-x: auto; }

.user-create {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.user-create input[type="email"] {
  font: inherit;
  flex: 1;
  min-width: 220px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.hint { color: var(--muted); font-size: 0.8rem; margin: 0 0 12px; }

.user-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}

.user-table th, .user-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.user-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.user-table tr:last-child td { border-bottom: none; }
.user-table td.actions { text-align: right; white-space: nowrap; }
.user-table .self { color: var(--muted); font-size: 0.78rem; margin-left: 6px; }

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  color: var(--muted);
}

.pill.warn { color: var(--accent); border-color: var(--accent); }

@media (max-width: 560px) {
  .item { flex-direction: column; align-items: stretch; }
  .item-side { justify-content: flex-end; }
}
