:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1c2430;
  --muted: #6b7280;
  --accent: #de0001;
  --accent-dark: #b50000;
  --accent-soft: #fdf0f0;
  --link: #2f5fe0;
  --danger: #c0392b;
  --danger-soft: #fdeeec;
  --warn-soft: #fff6e5;
  --warn-border: #f0d19a;
  --ok: #1f7a4d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 6px 20px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, 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;
  -webkit-font-smoothing: antialiased;
}

/* Blue is the complementary second color for links; brand red stays
   reserved for actions and active states. */
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.4rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 16px; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
.sep { color: var(--border-strong); padding: 0 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  min-width: 0;
}
.brand:hover { text-decoration: none; color: var(--text); }

.brand-mark {
  height: 25px;
  width: auto;
  display: inline-block;
  flex: none;
}

/* The rebranded name is long - keep it from shoving the topbar-right off
   the bar on narrow windows, and hide it entirely on phones. */
.brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-right form { margin: 0; }

.quota {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
}
.quota-full { color: var(--danger); border-color: #f0c5bf; background: var(--danger-soft); }

/* Usernames can be email addresses, so keep a long one from shoving the
   sign-out button off the bar - truncate it and show the rest on hover. */
.who {
  font-size: 0.9rem;
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- layout ---------- */

.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head p { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

/* ---------- setup guide callout ---------- */

/* The whole card is one click target, so it reads as an invitation rather
   than competing with the Upload button as a second button. */
.setup-guide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--accent-soft);
  border: 1px solid #efc3c3;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.setup-guide:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.setup-guide h2 { font-size: 1rem; margin: 0 0 2px; }
.setup-guide p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.setup-guide-cta {
  flex: none;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.95rem;
  white-space: nowrap;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { background: #f7f8fa; color: var(--text); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); color: var(--text); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-primary:disabled,
.btn-primary:disabled:hover {
  background: var(--border-strong);
  border-color: var(--border-strong);
  color: #fff;
}

.btn-quiet { border-color: transparent; color: var(--muted); background: transparent; }
.btn-quiet:hover { background: var(--bg); color: var(--text); }

.btn-danger-quiet { border-color: transparent; color: var(--danger); background: transparent; padding: 6px 10px; }
.btn-danger-quiet:hover { background: var(--danger-soft); }

.btn-block { width: 100%; }

.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}
.link:hover { text-decoration: underline; }

/* ---------- flashes ---------- */

.flashes { margin-bottom: 16px; }

.flash {
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface);
}
.flash-success { border-color: #bfe3ce; background: #f1faf4; color: var(--ok); }
.flash-error { border-color: #f0c5bf; background: var(--danger-soft); color: var(--danger); }
.flash-warn { border-color: var(--warn-border); background: var(--warn-soft); color: #8a5a08; }

/* ---------- filters ---------- */

.filters-disclosure {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.filters-disclosure summary {
  cursor: pointer;
  padding: 11px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  user-select: none;
}
.filters-disclosure[open] summary { border-bottom: 1px solid var(--border); }

.filter-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 2px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  padding: 16px;
  align-items: end;
}

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

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 0.8rem; color: var(--muted); font-weight: 500; }

input[type="text"], input[type="search"], input[type="password"],
input[type="date"], input[type="number"], textarea {
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- table ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

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

table.uploads th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  white-space: nowrap;
}
table.uploads th.num, table.uploads td.num { text-align: right; }

.th-sort { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.th-sort:hover { color: var(--text); text-decoration: none; }
.th-sort.is-active { color: var(--accent); }
.th-sort .arrow { font-size: 0.8rem; }

table.uploads td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.uploads tr:last-child td { border-bottom: 0; }
table.uploads tbody tr:hover { background: #fafbfc; }

.cell-name { font-weight: 500; max-width: 320px; overflow-wrap: anywhere; }
.name-plain { color: var(--muted); }

.row-pending { background: #fffdf7; }
.row-pending:hover { background: #fffaf0 !important; }

.col-actions { width: 128px; text-align: right; white-space: nowrap; }
.col-actions form { margin: 0; display: inline; }
/* Edit and Delete sit side by side; match their compact padding. */
.col-actions .btn { padding: 6px 10px; margin-left: 4px; }

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}

.pill {
  display: inline-block;
  font-size: 0.78rem;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #a10002;
  border: 1px solid #efc3c3;
  white-space: nowrap;
}
.pill-warn {
  background: var(--warn-soft);
  color: #8a5a08;
  border-color: var(--warn-border);
}

/* ---------- modal ---------- */

dialog.modal {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 18px 60px rgba(16, 24, 40, 0.25);
  color: var(--text);
}
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.45); }
dialog.modal form { padding: 26px; display: flex; flex-direction: column; gap: 16px; }
dialog.modal h2 { margin: 0; }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  background: #fbfcfd;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone p { margin: 0 0 4px; }
.dz-title { font-weight: 500; }

.file-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-soft);
  border: 1px solid #efc3c3;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
}
.file-summary .name { font-weight: 500; overflow-wrap: anywhere; }

.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-track {
  height: 7px;
  border-radius: 999px;
  background: #e9ecf1;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.15s ease;
}
.progress-label { margin: 0; font-size: 0.82rem; color: var(--muted); }

.status { margin: 0; font-size: 0.87rem; min-height: 1.2em; }
.status.is-error { color: var(--danger); }
.status.is-warn { color: #8a5a08; }
.status.is-ok { color: var(--ok); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Full-image modal (setup guide) */
.modal-image { width: min(680px, calc(100vw - 32px)); }
.modal-image-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-image-head h2 { margin: 0; font-size: 1rem; }
.modal-image-body {
  max-height: calc(100vh - 180px);
  overflow: auto;
  background: #fff;
  border-radius: 0 0 13px 13px;
}
.modal-image-body img { display: block; width: 100%; height: auto; }

.modal-image-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  border-radius: 0 0 13px 13px;
}
/* The dialog form rule above would pad and stack this tiny form. */
.modal-image-foot form { margin: 0; padding: 0; display: block; }

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

.login-wrap { display: flex; justify-content: center; padding: 48px 0; }
.login-card { width: min(400px, 100%); }
.login-card h1 { margin-bottom: 4px; }
.login-card p { margin: 0 0 18px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .btn { margin-top: 4px; }

.error-card { text-align: center; max-width: 440px; }
.error-card h1 { margin-bottom: 8px; }
.error-card p { margin: 0 0 18px; }
.error-code { font-size: 2.2rem; font-weight: 600; color: var(--border-strong); margin: 0 0 4px; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 48px;
  padding: 18px 0 22px;
}
.site-footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.84rem;
}
.site-footer-inner a { color: var(--muted); }
.site-footer-inner a:hover { color: var(--link); }

/* ---------- terms & consent ---------- */

.doc-wrap { max-width: 760px; margin: 0 auto; }
.doc-wrap h1 { margin-bottom: 8px; }
.doc-text { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px 30px; }
.doc-text h2 { font-size: 1.25rem; margin: 0 0 18px; }
.doc-text h3 { font-size: 1rem; margin: 22px 0 8px; }
.doc-text p { margin: 0 0 12px; line-height: 1.6; }

.consent-wrap { padding-bottom: 24px; }
.terms-box { max-height: 46vh; overflow-y: auto; margin: 4px 0 18px; }

.consent-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.consent-form { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.consent-check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.92rem; }
.consent-check input { margin-top: 3px; accent-color: var(--accent); }
.consent-decline { align-self: flex-end; }

/* ---------- analysis error chip ---------- */

.err-chip {
  position: relative;
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #ecc6c0;
  cursor: help;
  white-space: nowrap;
}
.err-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 300px;
  background: #2b3440;
  color: #f4f5f7;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.45;
  padding: 8px 11px;
  border-radius: 8px;
  white-space: normal;
  text-align: left;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.22);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  pointer-events: none;
  z-index: 10;
}
.err-chip:hover .err-tip, .err-chip:focus-visible .err-tip { opacity: 1; visibility: visible; }

@media (max-width: 640px) {
  .topbar-inner, .page { padding-left: 16px; padding-right: 16px; }
  .page-head { flex-direction: column; }
  .field-row { grid-template-columns: 1fr; }
  .quota { display: none; }
  .brand-text { display: none; }
  .setup-guide { flex-direction: column; align-items: flex-start; }
  .site-footer-inner { padding-left: 16px; padding-right: 16px; }
  .doc-text { padding: 20px 16px; }
}
