/* ==========================================================================
   King Deux CV Portal — design system
   Warm, precise, private-bank-adjacent. Serif display, system sans UI.
   No build step: this file is the whole design system.
   ========================================================================== */

:root {
  --bg: #FBFAF8;
  --surface: #FFFFFF;
  --ink: #1A1A1A;
  --muted: #6B6B6B;
  --muted-2: #9A9690;
  --hairline: #E7E4DE;
  --hairline-strong: #D8D3CA;
  --accent: #2F4F45;
  --accent-ink: #FFFFFF;
  --accent-tint: #EEF2F0;
  --danger: #8B3A3A;
  --danger-tint: #F6ECEA;

  --font-serif: Georgia, "Iowan Old Style", "Noto Serif TC", "Noto Serif SC", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "Noto Sans SC", "PingFang TC", "PingFang SC", "Microsoft JhengHei", "Microsoft YaHei", Helvetica, Arial, sans-serif;

  --radius: 3px;
  --radius-lg: 6px;
  --shadow-soft: 0 1px 2px rgba(26, 26, 26, 0.04);

  --container-width: 1120px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
}

/* ── reset ────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body, h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

ul, ol { padding: 0; list-style: none; }

img, svg { display: block; max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }

a { color: inherit; }

table { border-collapse: collapse; width: 100%; }

/* ── accessibility ───────────────────────────────────────────────────── */

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

.noscript-banner {
  background: var(--danger-tint);
  color: var(--danger);
  text-align: center;
  font-size: 13px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--hairline);
}

.skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-4);
  background: var(--ink);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  z-index: 100;
  transition: top .15s ease;
}
.skip-link:focus {
  top: var(--space-3);
}

:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── type ─────────────────────────────────────────────────────────────── */

h1, h2, h3, h4, .font-serif {
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
}

h1 { font-size: 28px; line-height: 1.25; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 16px; line-height: 1.35; }

.eyebrow {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ── layout ───────────────────────────────────────────────────────────── */

.container {
  width: 100%;
  max-width: var(--container-width);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.site-header {
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header__inner {
  max-width: var(--container-width);
  margin-inline: auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.wordmark {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 19px;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  white-space: nowrap;
}

.wordmark__sub {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.site-nav {
  display: flex;
  gap: var(--space-5);
  flex: 1;
}

.site-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: var(--space-2) 0;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover { color: var(--ink); }

.site-nav a.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.signout-form { margin: 0; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.link-button:hover { color: var(--ink); text-decoration: underline; }

.site-main {
  flex: 1;
  width: 100%;
  padding-block: var(--space-7) var(--space-8);
}

.site-footer {
  border-top: 1px solid var(--hairline);
  padding: var(--space-5);
  text-align: center;
}
.site-footer p {
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: 0.02em;
}

/* ── buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  padding: 11px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover { background: #000; border-color: #000; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn--primary:hover { background: #253f37; border-color: #253f37; }

.btn--ghost {
  background: transparent;
  border-color: var(--hairline-strong);
  color: var(--ink);
}
.btn--ghost:hover { border-color: var(--ink); background: var(--surface); }

.btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 8px 12px;
  font-weight: 500;
}
.btn--quiet:hover { color: var(--ink); background: var(--accent-tint); }

.btn--danger {
  background: transparent;
  border-color: var(--hairline-strong);
  color: var(--danger);
}
.btn--danger:hover { border-color: var(--danger); background: var(--danger-tint); }

.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn--block { width: 100%; }

.btn__icon { width: 16px; height: 16px; flex: none; }

/* ── forms ────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }

.field__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.field__hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.input, .select, .textarea {
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
}
.textarea { resize: vertical; min-height: 64px; }

.input--search {
  padding-left: 36px;
  background-repeat: no-repeat;
  background-position: 12px center;
}

/* checkbox pill (language multi-select) */

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  padding: 9px 16px 9px 12px;
  cursor: pointer;
  background: var(--surface);
  font-size: 14px;
  transition: border-color .12s ease, background .12s ease;
}
.check-pill:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.check-pill:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.check-pill input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--hairline-strong);
  border-radius: 3px;
  display: inline-grid;
  place-content: center;
  margin: 0;
  flex: none;
}
.check-pill input[type="checkbox"]::before {
  content: "";
  width: 8px;
  height: 8px;
  transform: scale(0);
  border-radius: 1px;
  background: var(--accent);
  transition: transform .1s ease;
}
.check-pill input[type="checkbox"]:checked::before { transform: scale(1); }
.check-pill input[type="checkbox"]:checked { border-color: var(--accent); }

/* toggle switch (anonymise) */

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.switch-input {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 23px;
  min-width: 40px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  position: relative;
  cursor: pointer;
  margin-top: 2px;
  transition: background .15s ease, border-color .15s ease;
}
.switch-input::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--muted-2);
  transition: transform .15s ease, background .15s ease;
}
.switch-input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.switch-input:checked::after {
  transform: translateX(17px);
  background: #fff;
}

.switch-text__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  display: block;
  margin-bottom: 2px;
}
.switch-text__desc {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── cards / surfaces ─────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.card--pad { padding: var(--space-6); }

/* ── sign-in ──────────────────────────────────────────────────────────── */

.auth-shell {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: var(--space-7) var(--space-6);
}

.auth-card__mark {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 700;
}

.auth-card__tagline {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: var(--space-1);
}

.auth-card__desc {
  color: var(--muted);
  font-size: 14px;
  margin-top: var(--space-5);
  margin-bottom: var(--space-6);
  line-height: 1.6;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: border-color .12s ease, background .12s ease;
}
.google-btn:hover { border-color: var(--ink); background: var(--bg); }
.google-btn svg { width: 18px; height: 18px; flex: none; }

/* ── page headers ─────────────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}

.page-head__title { display: flex; flex-direction: column; gap: var(--space-1); }
.page-head p.muted { max-width: 60ch; }

/* ── dropzone (upload) ────────────────────────────────────────────────── */

.dropzone {
  border: 1.5px dashed var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-8) var(--space-5);
  text-align: center;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
}
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-tint);
}
.dropzone__icon {
  width: 32px; height: 32px;
  margin: 0 auto var(--space-4);
  color: var(--muted);
}
.dropzone__title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
}
.dropzone__hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: var(--space-2);
}

.file-list { margin-top: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); }

.file-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
}
.file-row__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
}
.file-row__size { color: var(--muted); font-size: 12.5px; flex: none; }
.file-row__remove {
  flex: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 0;
}
.file-row__remove:hover { color: var(--danger); }

.lang-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.upload-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-6);
  flex-wrap: wrap;
}

.upload-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: var(--space-3);
}

/* ── status list (upload progress) ───────────────────────────────────── */

.status-list {
  margin-top: var(--space-7);
  border-top: 1px solid var(--hairline);
  padding-top: var(--space-5);
}

.status-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--hairline);
}
.status-row:last-child { border-bottom: none; }

.status-row__name {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-row__lang {
  flex: none;
}
.status-row__error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

/* ── chips ────────────────────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--hairline-strong);
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}

.chip--lang { color: var(--ink); background: var(--accent-tint); border-color: transparent; }

.chip--status { position: relative; }
.chip--status::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted-2);
  flex: none;
}
.chip--status-queued::before { background: var(--muted-2); }
.chip--status-extracting::before,
.chip--status-building::before,
.chip--status-rendering::before,
.chip--status-uploading::before {
  background: var(--accent);
  animation: chip-pulse 1.1s ease-in-out infinite;
}
.chip--status-done { color: var(--accent); border-color: var(--accent); }
.chip--status-done::before { background: var(--accent); animation: none; }
.chip--status-failed { color: var(--danger); border-color: var(--danger); background: var(--danger-tint); }
.chip--status-failed::before { background: var(--danger); }

.chip--anon {
  color: var(--muted);
  border-style: dashed;
}

@keyframes chip-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.spinner {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--hairline-strong);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── library ──────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  margin-bottom: var(--space-5);
}

.search-wrap {
  position: relative;
  flex: 1 1 260px;
  min-width: 220px;
}
.search-wrap svg {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.filter-chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.filter-chip {
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.filter-chip:hover { border-color: var(--ink); color: var(--ink); }
.filter-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.result-count {
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: var(--space-3);
}

.table-wrap {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.lib-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
  white-space: nowrap;
}

.lib-table tbody td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--hairline);
  font-size: 13.5px;
  vertical-align: middle;
}
.lib-table tbody tr:last-child td { border-bottom: none; }
.lib-table tbody tr:hover { background: var(--bg); }

.lib-table td.col-candidate { font-weight: 600; }
.lib-table td .row-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.row-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-actions .btn { padding: 6px 12px; font-size: 12.5px; }

.quiet-link {
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: none;
  border-bottom: 1px solid var(--hairline-strong);
}
.quiet-link:hover { color: var(--ink); border-color: var(--ink); }

.empty-state, .loading-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--muted);
}
.empty-state__title, .loading-state__title {
  font-family: var(--font-serif);
  color: var(--ink);
  font-size: 17px;
  margin-bottom: var(--space-2);
}
.loading-state .spinner {
  width: 22px; height: 22px;
  border-width: 2.5px;
  margin: 0 auto var(--space-4);
}

/* stacked card table for phones */
@media (max-width: 760px) {
  .lib-table thead { display: none; }
  .lib-table, .lib-table tbody, .lib-table tr, .lib-table td { display: block; width: 100%; }
  .lib-table tr {
    border-bottom: 1px solid var(--hairline);
    padding: var(--space-4);
  }
  .lib-table td {
    border-bottom: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    align-items: center;
  }
  .lib-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    flex: none;
  }
  .lib-table td.col-actions { justify-content: flex-start; padding-top: var(--space-3); }
  .lib-table td.col-actions::before { display: none; }
  .row-actions { justify-content: flex-start; }
}

/* ── review ───────────────────────────────────────────────────────────── */

.review-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

.review-savebar {
  position: sticky;
  top: 61px;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
  padding-block: var(--space-4);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.savebar__status {
  font-size: 12.5px;
  color: var(--muted);
  min-height: 1.2em;
}
.savebar__status[data-state="error"] { color: var(--danger); }
.savebar__status[data-state="ok"] { color: var(--accent); }

.review-section {
  padding: var(--space-6);
}
.review-section + .review-section { margin-top: var(--space-5); }

.review-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-3);
}

.header-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4) var(--space-5);
}
@media (max-width: 640px) { .header-grid { grid-template-columns: 1fr; } }

.repeat-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  margin-bottom: var(--space-3);
}
.repeat-row .input, .repeat-row .textarea { flex: 1; }
.repeat-row__remove {
  flex: none;
  margin-top: 2px;
}

.role-card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  background: var(--bg);
}
.role-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}
.role-card__label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.group-card {
  border-left: 2px solid var(--hairline-strong);
  padding-left: var(--space-4);
  margin-top: var(--space-4);
}
.group-card__head {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-3);
}
.group-card__head .input { flex: 1; }

.add-row-btn {
  margin-top: var(--space-2);
}

hr.section-rule {
  border: none;
  border-top: 1px solid var(--hairline);
  margin-block: var(--space-6);
}

/* utility */
.stack-4 > * + * { margin-top: var(--space-4); }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
