/* ===========================================================
   21D-Translate — modern SaaS theme
   Near-white background, ink type, Inter throughout, oxblood
   accent for CTAs and active state. Grid-first, fully responsive.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  color-scheme: light;

  /* Palette */
  --ink:           #0a0a0a;
  --ink-2:         #1f1f1f;
  --ink-3:         #404040;
  --muted:         #737373;
  --muted-dim:     #a3a3a3;
  --dim:           #d4d4d4;

  --paper:         #fafaf8;
  --paper-2:       #ffffff;
  --paper-3:       #f5f5f4;

  --rule:          #e7e5e2;
  --rule-strong:   #d4d2cc;
  --rule-faint:    #f0eeea;

  --accent:        #7a1f1f;
  --accent-hover:  #5d1414;
  --accent-soft:   #fbeeea;
  --accent-ink:    #4a1212;

  --ok:            #166534;
  --ok-soft:       #ecfdf5;
  --warn:          #92400e;
  --warn-soft:     #fef3c7;
  --danger:        #b91c1c;
  --danger-soft:   #fde8e8;

  --font-sans:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'JetBrains Mono', 'SF Mono', Menlo, monospace;

  --nav-h:         58px;
  --sidebar-w:     228px;
  --container:     1280px;

  --ease:          cubic-bezier(.4, 0, .2, 1);
  --t-fast:        .12s;
  --t-base:        .22s;

  /* Doc-table grid template — wide → narrow
     Columns: Document | Type | Source | Pages | Targets · model | Status | Actions */
  --doc-cols: minmax(0, 1.6fr) 70px 70px 70px minmax(0, 1.7fr) minmax(150px, 1fr) 40px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  background: var(--paper);
  color: var(--ink-3);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
::selection { background: rgba(122,31,31,.16); color: var(--ink); }
code { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); }

/* Custom display rules (grid/flex) silently override the UA's
   [hidden]{display:none}. Force it back so the attribute works. */
[hidden] { display: none !important; }

/* ===========================================================
   App shell — sidebar + topbar + main
   =========================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--nav-h) minmax(0, 1fr);
  min-height: 100vh;
}

/* ===========================================================
   Top bar
   =========================================================== */
.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: var(--sidebar-w) auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 0 24px 0 20px;
  height: var(--nav-h);
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  position: sticky; top: 0; z-index: 30;
}
.brand {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  min-width: 0;
}
.brand-logo {
  height: 22px;
  width: auto;
  display: block;
}
.brand-mark {
  width: 28px; height: 28px;
  background: var(--ink); color: var(--paper-2);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: -.02em;
  border-radius: 6px;
}
.brand-name {
  font-size: 14px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap;
}
.brand-sub {
  color: var(--muted); font-weight: 400;
  margin-left: 4px; font-size: 13px;
  white-space: nowrap;
}

.topbar-crumbs {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  min-width: 0;
}
.topbar-crumbs .sep { color: var(--dim); }
.topbar-crumbs .curr { color: var(--ink); font-weight: 500; }
.topbar-crumbs span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 30px; height: 30px; padding: 0;
  display: inline-grid; place-items: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.icon-btn:hover { color: var(--ink); background: var(--paper-3); border-color: var(--rule-strong); }
.icon-btn svg { width: 14px; height: 14px; }

.user-tile {
  display: inline-grid; grid-auto-flow: column; align-items: center; gap: 8px;
  padding: 3px 12px 3px 3px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
  border-radius: 100px;
  max-width: 220px;
}
.user-tile .av {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--ink); color: var(--paper-2);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.user-tile .org {
  font-size: 12.5px; color: var(--ink); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}

/* ===========================================================
   Sidebar
   =========================================================== */
.sidebar {
  border-right: 1px solid var(--rule);
  padding: 16px 12px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 4px;
  position: sticky;
  top: var(--nav-h);
  align-self: start;
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  background: var(--paper-2);
}
.sidebar-group { display: grid; gap: 1px; align-content: start; }
.sidebar-bot {
  align-self: end;
  border-top: 1px solid var(--rule);
  padding-top: 8px;
  margin-top: 8px;
}

/* Signed-in identity tile at the top of the bottom sidebar group —
   doubles as the Account link. */
.sidebar-user {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  min-width: 0;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background var(--t-fast);
}
.sidebar-user:hover { background: var(--paper-3); }
.sidebar-user.active { background: var(--paper-3); }
.sidebar-user.active .email { color: var(--ink); }
.sidebar-user .av {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper-2);
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
}
.sidebar-user .email {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-label {
  font-size: 11px;
  letter-spacing: .01em;
  font-weight: 500;
  color: var(--muted);
  padding: 8px 10px 4px;
}
.snav-item {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  color: var(--ink-3);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  border-radius: 6px;
  text-decoration: none;
}
.snav-item:hover { color: var(--ink); background: var(--paper-3); }
.snav-item.active {
  background: var(--paper-3);
  color: var(--ink);
  font-weight: 500;
}
.snav-item.active svg { color: var(--accent); }
.snav-item svg { width: 15px; height: 15px; color: var(--muted); }
.snav-item:hover svg { color: var(--ink); }
.snav-item .count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.snav-item.active .count { color: var(--accent); }

/* ===========================================================
   Main layout
   =========================================================== */
.app-main {
  display: grid;
  align-content: start;
  gap: 24px;
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 28px 32px 56px;
  min-width: 0;
}

.page-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
}
.page-head .eyebrow {
  font-size: 12px; font-weight: 500;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 6px;
}
.page-head h1 {
  margin: 0; color: var(--ink);
  font-size: 28px; font-weight: 600;
  letter-spacing: -.025em; line-height: 1.15;
}
.page-head h1 em { font-style: normal; color: var(--muted); font-weight: 400; }
.page-head .sub {
  margin: 8px 0 0; color: var(--ink-3);
  font-size: 14.5px; line-height: 1.55;
  max-width: 64ch;
}
.page-head .sub code {
  font-family: var(--font-mono); font-size: 12.5px;
  color: var(--accent); background: var(--accent-soft);
  padding: 1px 6px; border-radius: 3px;
}
.page-head-actions {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 8px;
  align-items: center;
}

/* ===========================================================
   Buttons (single .btn family — no <button> default styling)
   =========================================================== */
button { font: inherit; cursor: pointer; background: none; border: 0; padding: 0; color: inherit; }
.btn {
  /* Secondary by default: transparent, black border, black text. */
  display: inline-grid; grid-auto-flow: column; align-items: center; gap: 7px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  border-radius: 6px;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  white-space: nowrap;
  font-family: var(--font-sans);
}
.btn:hover { background: var(--ink); color: var(--paper-2); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* Primary + accent (legacy alias): solid black with white text. */
.btn-primary,
.btn-accent {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-2);
}
.btn-primary:hover,
.btn-accent:hover {
  background: var(--ink-2);
  border-color: var(--ink-2);
  color: var(--paper-2);
}
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn-ghost:hover { color: var(--ink); background: var(--paper-3); border-color: var(--rule); }
.btn-danger { background: var(--paper-2); border-color: var(--rule); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-success { background: var(--ok); border-color: var(--ok); color: var(--paper-2); }
.btn-success:hover { background: #14532d; border-color: #14532d; color: var(--paper-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; gap: 5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===========================================================
   Cards
   =========================================================== */
.card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
}
.card-h {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--rule);
}
.card-h h2 {
  margin: 0; color: var(--ink);
  font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  display: inline-flex; gap: 10px; align-items: baseline;
}
.card-h h2 em { font-style: normal; color: var(--muted); font-weight: 400; font-size: 13px; }
.card-h-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--muted);
  align-self: center;
}
.card-body { padding: 16px 18px; display: grid; gap: 12px; }
.divider { height: 1px; background: var(--rule); border: 0; margin: 8px 0; }

/* ===========================================================
   Form controls
   =========================================================== */
label { font-size: 11.5px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number] {
  width: 100%;
  padding: 9px 11px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: inherit; font-size: 13.5px;
  border-radius: 6px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input[type=file] {
  width: 100%; padding: 9px 11px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink);
  font: inherit; font-size: 13px;
  border-radius: 6px;
}
input:focus, select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10,10,10,.06); }

.lang-input {
  height: 30px;
  padding: 0 11px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  width: 100%;
}
.lang-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10,10,10,.06); }

/* Custom language combobox — used in place of native <datalist> so the
   suggestion list can be height-capped. The hidden `.lang-pick` input
   inside lets existing form code read the picked code unchanged. */
.lang-combo {
  position: relative;
  min-width: 0;
}
.lang-combo-input {
  /* Inherits the .lang-select look (chevron, padding, height). */
  cursor: text;
}
.lang-combo-list {
  /* `position: fixed` + `top`/`left`/`min-width` are set inline by
     buildLangCombo so the list can escape any ancestor overflow. */
  max-height: 60vh;
  overflow-y: auto;
  z-index: 1000;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 12px 32px rgba(10, 10, 10, .12), 0 2px 6px rgba(10, 10, 10, .04);
  display: grid;
  gap: 1px;
}
.lang-combo-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  color: var(--ink-2);
  font-family: var(--font-sans);
}
.lang-combo-item:hover {
  background: var(--paper-3);
  color: var(--ink);
}
.lang-combo-empty {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
}

select, .lang-select {
  height: 34px; padding: 0 28px 0 11px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  font-family: inherit; font-size: 13px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 9px center;
  cursor: pointer;
}
select:hover, .lang-select:hover { border-color: var(--rule-strong); }

textarea, .textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
  resize: vertical;
  border-radius: 6px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10,10,10,.06); }
textarea::placeholder, input::placeholder { color: var(--muted-dim); }

.field { display: grid; gap: 6px; }
.field-row { display: grid; gap: 12px; padding: 16px 18px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* ===========================================================
   Upload zone
   =========================================================== */
.upload {
  border: 1.5px dashed var(--rule-strong);
  background: var(--paper-2);
  border-radius: 10px;
  padding: 22px 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
  transition: border-color var(--t-base), background var(--t-base);
}
.upload.dragover { border-color: var(--accent); background: var(--accent-soft); }

.upload-left {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-width: 0;
}
.upload-icon {
  width: 48px; height: 48px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--ink-3);
}
.upload-icon svg { width: 22px; height: 22px; }
.upload h3 {
  margin: 0 0 4px; color: var(--ink);
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
}
.upload h3 em { font-style: normal; color: var(--muted); font-weight: 400; }
.upload p {
  margin: 0; color: var(--ink-3); font-size: 13px;
  line-height: 1.5;
}
.upload p code {
  font-family: var(--font-mono); font-size: 12px; color: var(--accent);
  background: var(--accent-soft); padding: 1px 5px; border-radius: 3px;
}
.upload-right {
  display: grid;
  justify-content: end;
  align-items: center;
}
.upload-right .btn { height: 34px; }

.upload-progress {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
}
progress {
  width: 100%; height: 6px;
  appearance: none;
  border: 0; border-radius: 100px;
  background: var(--rule-faint);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--rule-faint); border-radius: 100px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 100px; transition: width .3s var(--ease); }
progress::-moz-progress-bar { background: var(--accent); border-radius: 100px; }

.log {
  padding: 9px 11px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
  white-space: pre-wrap;
  min-height: 1.2rem;
}

/* ===========================================================
   Documents — grid table (no <table>)
   =========================================================== */
.doc-table { display: grid; }
.doc-row {
  display: grid;
  grid-template-columns: var(--doc-cols);
  gap: 16px;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--rule);
  position: relative;
}
.doc-row:last-child { border-bottom: 0; }
.doc-row.head {
  padding: 9px 18px;
  background: var(--paper);
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.doc-name { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; align-items: center; min-width: 0; }
.doc-thumb {
  width: 32px; height: 40px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 4px;
  display: grid; place-items: center;
  color: var(--muted);
}
.doc-thumb svg { width: 15px; height: 15px; }
.doc-thumb.idml { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-soft); }
.doc-thumb.pdf  { color: var(--ink-2); }
.doc-meta-stack { min-width: 0; display: grid; gap: 2px; }
.doc-fn {
  color: var(--ink); font-weight: 500; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  letter-spacing: -.005em;
}
.doc-sub { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: var(--paper-3);
  color: var(--ink-3);
}
.chip-idml { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.chip-pdf  { background: var(--paper-3); color: var(--ink-2); }

.doc-mono    { font-family: var(--font-mono); color: var(--ink-2); font-size: 12.5px; }
.doc-mono-sm { font-family: var(--font-mono); color: var(--muted); font-size: 11.5px; }

/* Target language chip cluster (per-doc) */
.targets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  position: relative;
}
.target-chip {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 8px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 100px;
  font-size: 11.5px;
  color: var(--ink);
  transition: border-color var(--t-fast), background var(--t-fast);
  cursor: default;
}
.target-chip:hover { border-color: var(--rule-strong); }
/* Amber dot in the top-right corner of any chip whose translation has
   at least one editor-saved chunk. Tooltip on the chip itself carries
   the precise count; this is just the visual cue. */
.target-chip { position: relative; }
.target-chip.has-edits::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d9a93e;
  box-shadow: 0 0 0 2px var(--paper);
}
.target-chip .model {
  display: inline-grid;
  place-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--paper-2);
  color: var(--ink-2);
  border: 1px solid var(--rule);
}
.target-chip .model img {
  width: 40px;
  height: auto;
  display: block;
}
.target-chip .x {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px;
  border-radius: 100px;
  color: var(--muted);
  border: 0; background: transparent; padding: 0;
  cursor: pointer;
}
.target-chip .x:hover { color: var(--accent); background: var(--accent-soft); }
.target-chip .x svg { width: 9px; height: 9px; }
.target-chip .play,
.target-chip .dl,
.target-chip .stop,
.target-chip .edit {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px;
  border-radius: 100px;
  color: var(--accent);
  background: transparent;
  border: 0; padding: 0;
  cursor: pointer;
}
.target-chip .play:hover { background: var(--accent-soft); }
.target-chip .play svg { width: 9px; height: 9px; }
.target-chip .dl { color: var(--ok); }
.target-chip .dl:hover { background: rgba(22,101,52,.12); }
.target-chip .dl svg { width: 11px; height: 11px; }
.target-chip .dl:disabled { opacity: .5; cursor: not-allowed; }
.target-chip .edit { color: var(--ink-3); }
.target-chip .edit:hover { color: var(--ink); background: var(--paper-3); }
.target-chip .edit svg { width: 10px; height: 10px; }

/* Stop is only meaningful while running — hide it otherwise. When
   running we also swap × out so the chip's primary action reads as
   "stop", not "stop or remove". */
.target-chip .stop { display: none; color: var(--danger); }
.target-chip .stop svg { width: 8px; height: 8px; }
.target-chip .stop:hover { background: var(--danger-soft); }
.target-chip.translating .stop { display: inline-grid; }
.target-chip.translating .x { display: none; }
.target-chip.ready {
  border-color: var(--rule-strong);
  background: var(--paper-2);
  color: var(--ink-2);
}
.target-chip.ready .model {
  background: var(--paper-3);
  color: var(--muted);
}
.target-chip.translating {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.target-chip.translating .lbl::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: chipPulse 1.2s infinite;
  vertical-align: middle;
}
@keyframes chipPulse { 50% { opacity: .35; } }
.target-chip.done {
  border-color: rgba(22,101,52,.35);
  background: var(--ok-soft);
  cursor: pointer;
}
.target-chip.done .model { background: rgba(22,101,52,.12); color: var(--ok); }
.target-chip.error {
  border-color: rgba(185,28,28,.35);
  background: var(--danger-soft);
  color: var(--danger);
}
.target-chip.error .model { background: rgba(185,28,28,.12); color: var(--danger); }

.add-lang-btn {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 8px;
  background: transparent;
  border: 1px dashed var(--rule-strong);
  border-radius: 100px;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.add-lang-btn:hover {
  border-style: solid;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.add-lang-btn svg { width: 10px; height: 10px; }

/* Add-language popover */
.addlang-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 10;
  width: 320px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  box-shadow:
    0 8px 24px rgba(10,10,10,.06),
    0 2px 6px rgba(10,10,10,.04);
}
.addlang-h {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}
.addlang-grid {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}
.addlang-grid label { font-size: 11.5px; color: var(--muted); }
.addlang-grid .lang-select { height: 30px; font-size: 12px; }
.addlang-dropdown {
  max-height: none;
  overflow: visible;
}
.addlang-dropdown .lang-combo-item {
  grid-template-columns: auto 1fr auto;
  padding: 8px 10px;
}
.addlang-provider-logo {
  height: 16px;
  width: auto;
  opacity: .85;
  justify-self: end;
}
.addlang-provider-label {
  font-size: 12px;
  color: var(--muted);
  justify-self: end;
}
.addlang-foot {
  display: grid;
  grid-auto-flow: column;
  justify-content: end;
  gap: 6px;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
}

/* Per-doc aggregate status column */
.doc-status {
  display: grid;
  gap: 5px;
  min-width: 0;
  font-size: 12.5px;
  color: var(--ink-3);
}
.doc-status .stat-row {
  display: grid;
  grid-template-columns: 6px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
}
.doc-status .sd { width: 6px; height: 6px; border-radius: 50%; }
.doc-status .text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-status .progress {
  width: 100%; height: 3px;
  background: var(--rule-faint);
  border-radius: 100px;
  overflow: hidden;
}
.doc-status .bar {
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  transition: width .4s var(--ease);
}
.doc-status.idle .sd, .doc-status.idle { color: var(--muted); }
.doc-status.idle .sd { background: var(--muted-dim); }
.doc-status.queued .sd { background: var(--muted); }
.doc-status.translating .sd { background: var(--accent); animation: chipPulse 1.4s infinite; }
.doc-status.translating { color: var(--accent); }
.doc-status.done .sd { background: var(--ok); }
.doc-status.done { color: var(--ok); }
.doc-status.error .sd { background: var(--danger); }
.doc-status.error { color: var(--danger); }

.row-action {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 6px;
  transition: all var(--t-fast);
  justify-self: end;
}
.row-action:hover { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-soft); }
.row-action svg { width: 14px; height: 14px; }

/* Pills (used by chips' status states inherited; kept for any inline use) */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--paper-3);
  color: var(--ink-3);
  border: 1px solid var(--rule);
}
.pill.pending  { background: var(--paper-3); color: var(--muted); }
.pill.running  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.pill.done     { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-soft); }
.pill.error    { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }


/* ===========================================================
   Settings actions
   =========================================================== */
.settings-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}
.settings-suggest {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.settings-suggest label { white-space: nowrap; }

/* ===========================================================
   Banners
   =========================================================== */
.banner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
}
.banner-ok   { background: var(--ok-soft); border-color: rgba(22,101,52,.2); color: var(--ok); }
.banner-warn { background: var(--warn-soft); border-color: rgba(146,64,14,.2); color: var(--warn); }
.banner-err  { background: var(--danger-soft); border-color: rgba(185,28,28,.2); color: var(--danger); }
.banner strong { font-weight: 600; }

/* ===========================================================
   Auth pages
   =========================================================== */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: var(--paper);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 28px;
  display: grid;
  gap: 18px;
}
.auth-brand {
  display: grid; grid-auto-flow: column; justify-content: start;
  align-items: center; gap: 10px;
}
.auth-card h1 {
  margin: 0; color: var(--ink);
  font-size: 22px; font-weight: 600; letter-spacing: -.02em;
}
.auth-card .sub { margin: -8px 0 0; color: var(--muted); font-size: 13.5px; }
.auth-card form { display: grid; gap: 14px; }
.auth-links { font-size: 13px; text-align: center; color: var(--muted); }
.auth-links a { color: var(--ink-2); font-weight: 500; }
.auth-links a:hover { color: var(--accent); }
.auth-card .field-back {
  background: none; border: 0; padding: 0;
  color: var(--ink-2); font: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.auth-card .field-back:hover { color: var(--accent); }
.auth-code {
  font-family: var(--font-mono);
  font-size: 22px;
  letter-spacing: 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 14px 10px;
}
.auth-sent-to { font-size: 13px; color: var(--muted); margin: -4px 0 0; }
.auth-sent-to strong { color: var(--ink); font-weight: 600; }
.auth-invite-banner {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--paper-3);
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
}
.auth-invite-banner strong { color: var(--ink); font-weight: 600; }

/* ===========================================================
   Workspace context indicator (sidebar) + account list + team page
   =========================================================== */
.ws-switcher { margin: 2px 10px 8px; }
.ws-role-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--paper-3);
  color: var(--ink-2);
  text-decoration: none;
}
.ws-role-pill:hover { filter: brightness(0.95); }
.ws-role-pill.role-owner  { background: #f1e4e2; color: #6b1f17; }
.ws-role-pill.role-admin  { background: #f5e8d0; color: #6a4710; }
.ws-role-pill.role-editor { background: #e3eedb; color: #2f5d24; }

.ws-list { display: grid; gap: 8px; padding: 0 18px 18px; }
.ws-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-2);
}
.ws-row.is-active { border-color: var(--ink-3); }
.ws-row-main { display: grid; gap: 2px; }
.ws-row-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.ws-row-role {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.ws-row-active {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ok);
  padding: 4px 10px;
  border-radius: 100px;
  background: rgba(33, 132, 76, 0.08);
}

.team-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.team-table th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
}
.team-table td {
  padding: 12px;
  border-bottom: 1px solid var(--rule-faint);
  vertical-align: middle;
}
.team-table tr:last-child td { border-bottom: 0; }
.team-table th:first-child,
.team-table td:first-child { padding-left: 18px; }
.team-table th:last-child,
.team-table td:last-child  { padding-right: 18px; }
.team-table .row-actions { text-align: right; }
.role-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--paper-3);
  color: var(--ink-2);
}
.role-chip.role-admin  { background: #f5e8d0; color: #6a4710; }
.role-chip.role-editor { background: #e3eedb; color: #2f5d24; }
.btn-link {
  background: none; border: 0; padding: 0;
  color: var(--ink-2); font: inherit;
  cursor: pointer; text-decoration: underline;
}
.btn-link.danger { color: #a3322a; }
.btn-link:hover  { color: var(--accent); }
.invite-form { display: grid; gap: 12px; padding: 16px 18px 18px; }
.invite-form .field { display: grid; gap: 4px; }
.invite-form-actions { display: flex; justify-content: flex-end; margin-top: 4px; }

.members-list { display: grid; gap: 12px; padding: 14px 18px 18px; }
.members-empty { padding: 4px 0; }
.member-card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  overflow: hidden;
}
.member-card-h {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}
.member-card-id {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  min-width: 0;
}
.member-card-email {
  font-size: 14px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.member-card-joined { font-size: 12px; color: var(--muted); }
.member-assignments {
  border-top: 1px solid var(--rule-faint);
  padding: 10px 14px 12px;
  background: var(--paper-2);
}
.member-assignments-pills {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.assign-pill {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  background: var(--paper-3);
  border-radius: 100px;
  font-size: 12px;
  color: var(--ink-2);
}
.assign-pill-doc { font-weight: 500; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-pill-sep { color: var(--muted); }
.assign-pill .x {
  width: 18px; height: 18px;
  background: transparent; border: 0; padding: 0;
  cursor: pointer; color: var(--muted);
  display: grid; place-items: center;
}
.assign-pill .x:hover { color: var(--accent); }
.assign-pill .x svg { width: 11px; height: 11px; }
.member-assign-add {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 8px;
  border: 1px dashed var(--rule);
  border-radius: 100px;
  background: transparent;
  font: inherit; font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
}
.member-assign-add:hover { border-color: var(--ink-3); color: var(--ink); }
.member-assign-form {
  display: grid;
  grid-template-columns: 2fr 1fr auto auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
  padding: 10px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  background: var(--paper);
}
.member-assign-form .field { display: grid; gap: 4px; }
.member-assign-form label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.member-assign-form select {
  padding: 7px 9px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper-2);
  font: inherit;
  color: var(--ink);
}
.invite-form select {
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  font: inherit;
  color: var(--ink);
}
/* Hide owner-only sidebar items when the active workspace is one the
   user is a member of (not the owner). Switcher writes body.ws-member. */
body.ws-member .snav-owner-only { display: none !important; }

/* Editor lockdown: editors don't start, stop, download, remove, or
   add translations; they don't upload new projects; they don't open
   the project-settings drawer. They only open the preview and edit
   chunks they've been assigned. Phase 3 will enforce these gates
   server-side; for now we just take the controls off the page. */
body.ws-editor .target-chip .play,
body.ws-editor .target-chip .stop,
body.ws-editor .target-chip .dl,
body.ws-editor .target-chip .x,
body.ws-editor .add-lang-btn,
body.ws-editor .open-btn,
body.ws-editor #upload-form { display: none !important; }

/* ===========================================================
   Settings tabs (Global + per-language)
   =========================================================== */
.settings-tabs {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--rule);
  background: var(--paper-2);
  border-radius: 6px;
  padding: 2px;
  gap: 0;
  overflow-x: auto;
  max-width: 100%;
}
.settings-tab {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  transition: all var(--t-fast);
  white-space: nowrap;
}
.settings-tab:hover { color: var(--ink); }
.settings-tab.active { background: var(--ink); color: var(--paper-2); }
.settings-tab .dot { width: 5px; height: 5px; background: var(--accent); border-radius: 50%; }
.settings-tab.active .dot { background: var(--paper-2); }

.flag-pill {
  display: inline-grid;
  place-items: center;
  height: 16px;
  min-width: 22px;
  padding: 0 5px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.settings-tab.active .flag-pill { background: var(--paper-2); border-color: transparent; }

/* ===========================================================
   Your-languages list (Languages & models page)
   =========================================================== */
.user-lang-list { display: grid; }
.user-lang-empty {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.user-lang-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--rule);
}
.user-lang-row > .user-lang-name,
.user-lang-row > .user-lang-provider,
.user-lang-row > .user-lang-model { justify-self: start; }
.user-lang-row:last-child { border-bottom: 0; }
.user-lang-row.editing {
  background: var(--paper);
}

.user-lang-name {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 10px;
  justify-content: start;
  font-size: 14px;
  color: var(--ink);
}
.user-lang-name .flag-pill {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: 0;
}
.flag-img {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  display: block;
  flex-shrink: 0;
}

/* Display-mode provider: logo + label, no chrome. */
.user-lang-provider {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 7px;
  color: var(--ink-2);
  font-size: 13px;
  min-width: 0;
}
.user-lang-provider img {
  height: 16px;
  width: auto;
  display: block;
}

/* Display-mode model: mono text, no box. */
.user-lang-model {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
}

.user-lang-actions {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  justify-self: end;
}
.user-lang-actions .row-action svg { width: 13px; height: 13px; }
.user-lang-actions .user-lang-done { color: var(--ok); }
.user-lang-actions .user-lang-done:hover { background: var(--ok-soft); border-color: rgba(22,101,52,.25); color: var(--ok); }

@media (max-width: 760px) {
  .user-lang-row,
  .user-lang-row.editing {
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }
  .user-lang-name { grid-column: 1 / -1; }
  .user-lang-actions { grid-column: 1 / -1; justify-self: start; }
}

/* Per-card descriptive paragraph (renders directly under .card-h). */
.card-sub {
  margin: 0;
  padding: 14px 18px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  border-bottom: 1px solid var(--rule);
}
.card-sub strong { color: var(--ink-2); font-weight: 600; }

/* ===========================================================
   Second-opinion picks (Languages & models page)
   =========================================================== */
.so-lang-list { display: grid; }
.so-lang-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--rule);
}
.so-lang-row:last-child { border-bottom: 0; }
.so-lang-row.editing {
  grid-template-columns: 1fr 1fr 1fr auto;
  background: var(--paper);
}
.so-pick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.so-pick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 7px;
  border: 1px solid var(--rule);
  border-radius: 100px;
  background: var(--paper-2);
  font-size: 12px;
  color: var(--ink-2);
}
.so-pick-chip-logo {
  width: 14px;
  height: 14px;
  object-fit: contain;
  border-radius: 3px;
}
.so-pick-chip-model {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
}
.so-pick-chip-x {
  background: transparent;
  border: 0;
  padding: 2px;
  border-radius: 100px;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.so-pick-chip-x:hover { background: var(--paper-3); color: var(--ink); }
.so-pick-chip-x svg { width: 10px; height: 10px; }

.so-pick-edit {
  grid-column: 2 / 3;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.so-lang-actions {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 6px;
  align-items: center;
  justify-self: end;
}
.so-lang-actions .row-action svg { width: 13px; height: 13px; }

@media (max-width: 760px) {
  .so-lang-row,
  .so-lang-row.editing {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .so-pick-edit { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
  .so-lang-actions { justify-self: start; }
}

/* ===========================================================
   Segmented control (used by the preview view-mode toggle and
   any future tab-style switchers).
   =========================================================== */
.seg {
  display: inline-grid;
  grid-auto-flow: column;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.seg button {
  background: transparent;
  border: 0;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button:hover { color: var(--ink); }
.seg button.active {
  background: var(--ink);
  color: var(--paper-2);
}

/* ===========================================================
   Translation preview — side-by-side reader
   =========================================================== */
.preview-list {
  display: grid;
  gap: 1px;
  background: var(--rule);
}
.preview-empty {
  padding: 24px 18px;
  background: var(--paper-2);
  color: var(--muted);
  font-size: 13.5px;
}
.preview-section {
  grid-column: 1 / -1;
  padding: 10px 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  background: var(--paper);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}
.preview-section-key { color: var(--ink-3); }
.preview-section-meta { color: var(--muted); }
.preview-section-totals {
  padding: 0 5px;
  border-radius: 4px;
  cursor: default;
}
.preview-section-totals.overrun-warn,
.preview-section-totals.underrun-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.preview-section-totals.overrun-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.preview-chunk {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) minmax(0, 1fr);
  gap: 0;
  background: var(--paper-2);
  border-top: 1px solid var(--rule);
}
.preview-chunk.empty { background: var(--warn-soft); }
.preview-chunk.errored { background: var(--danger-soft); }

.preview-meta {
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 12px 14px;
  border-right: 1px solid var(--rule);
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.preview-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.preview-meta-row .preview-seq {
  color: var(--ink-3);
}
.preview-chars {
  white-space: nowrap;
  padding: 0 5px;
  border-radius: 4px;
  width: max-content;
  cursor: default;
}
.preview-chars.overrun-warn,
.preview-chars.underrun-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.preview-chars.overrun-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.preview-status {
  display: inline-grid;
  place-items: center;
  width: max-content;
  padding: 1px 7px;
  border-radius: 100px;
  font-size: 10px;
  letter-spacing: .02em;
  text-transform: uppercase;
  background: var(--paper-3);
  color: var(--ink-3);
  border: 1px solid var(--rule);
}
.preview-status.status-running  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.preview-status.status-done     { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok-soft); }
.preview-status.status-error    { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }
.preview-status.status-pending  { background: var(--paper-3);     color: var(--muted); }

.preview-pane {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  border-right: 1px solid var(--rule);
}
.preview-pane:last-child { border-right: 0; }
.preview-pane.src { color: var(--ink-3); }
.preview-pane.dst { color: var(--ink); }
.preview-pane em { color: var(--muted-dim); font-style: italic; font-size: 13px; }
.preview-text { white-space: pre-wrap; word-wrap: break-word; }

/* Editable target: only switches into edit mode when the user clicks
   the pencil button. The text element itself doesn't suggest clickability. */
.preview-pane.dst { position: relative; }
.preview-pane.dst .preview-text[contenteditable] {
  cursor: text;
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
  transition: background var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}
.preview-pane.dst .preview-text[contenteditable="true"]:focus {
  background: var(--paper-2);
  box-shadow: 0 0 0 2px rgba(10, 10, 10, .08), 0 0 0 3px var(--accent-soft);
}
.preview-pane.dst .preview-text[contenteditable="true"]:empty::before {
  content: "Type a translation…";
  color: var(--muted-dim);
  font-style: italic;
  pointer-events: none;
}

.preview-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: .55;
  transition: opacity var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.preview-chunk:hover .preview-edit,
.preview-edit:hover,
.preview-edit:focus-visible {
  opacity: 1;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.preview-edit svg { width: 13px; height: 13px; }

/* Revert: same shape as .preview-edit, sits to its left so the pair
   reads pencil → arrow-back. Only rendered for edited chunks. */
.preview-revert {
  position: absolute;
  top: 8px;
  right: 38px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: .55;
  transition: opacity var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.preview-chunk:hover .preview-revert,
.preview-revert:hover,
.preview-revert:focus-visible {
  opacity: 1;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.preview-revert svg { width: 13px; height: 13px; }

/* Second opinion: sits directly below the edit button. Same chrome so
   the three buttons (revert, edit, second opinion) read as a stack. */
.preview-second-opinion {
  position: absolute;
  top: 38px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: .55;
  transition: opacity var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.preview-chunk:hover .preview-second-opinion,
.preview-second-opinion:hover,
.preview-second-opinion:focus-visible {
  opacity: 1;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.preview-second-opinion svg { width: 13px; height: 13px; }

/* Edited indicator: a small pill next to the status pill, plus a
   left-border accent on the chunk itself for at-a-glance scanning. */
.preview-edited-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 100px;
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 600;
  background: #f5e8d0;
  color: #6a4710;
  margin-left: 4px;
}
.preview-chunk.edited { box-shadow: inset 3px 0 0 #d9a93e; }

/* AI baseline reveal: hidden by default; surfaced when the user
   ticks "Show changes" (the list root gets .show-changes). Sits under
   the dst pane's editable text as muted strikethrough so reviewers can
   compare without leaving the page. */
.preview-ai-original {
  display: none;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--paper-3);
  border: 1px dashed var(--rule);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.preview-list.show-changes .preview-chunk.edited .preview-ai-original {
  display: block;
}
.preview-ai-original-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted-dim);
  margin-bottom: 3px;
}
.preview-ai-original-text { text-decoration: line-through; color: var(--ink-3); }

.preview-save-hint {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: 100px;
  font-size: 10px;
  letter-spacing: .02em;
  text-transform: uppercase;
  background: var(--paper-3);
  color: var(--muted);
  border: 1px solid var(--rule);
}
.preview-save-hint.saving { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.preview-save-hint.saved  { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok-soft); }
.preview-save-hint.error  { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }

.preview-error {
  grid-column: 1 / -1;
  padding: 8px 16px;
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--paper-2);
  border-top: 1px dashed var(--rule);
}

/* View-mode variants: hide the column we don't want to see. */
.preview-list.view-src .preview-pane.dst { display: none; }
.preview-list.view-src .preview-chunk { grid-template-columns: 110px minmax(0, 1fr); }
.preview-list.view-dst .preview-pane.src { display: none; }
.preview-list.view-dst .preview-chunk { grid-template-columns: 110px minmax(0, 1fr); }

.preview-filter-label {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
}

@media (max-width: 760px) {
  .preview-chunk,
  .preview-list.view-src .preview-chunk,
  .preview-list.view-dst .preview-chunk {
    grid-template-columns: 1fr;
  }
  .preview-meta { border-right: 0; border-bottom: 1px solid var(--rule); }
  .preview-pane { border-right: 0; border-bottom: 1px solid var(--rule); }
  .preview-pane:last-child { border-bottom: 0; }
}

/* ===========================================================
   Provider status row (Languages & models page) — slim version
   =========================================================== */
.providers-line {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 18px;
}
.providers-line.providers-inline {
  padding: 0;
  gap: 6px;
}

/* Strip variant — floats above the "Your languages" card, right-aligned,
   with the .app-main row gap (24px) collapsed to ~10px just below it. */
.providers-strip {
  display: flex;
  justify-content: flex-end;
  margin-bottom: -14px;
}
.providers-strip-inner { padding: 0; gap: 6px; }
.provider-pill {
  position: relative;
  display: inline-grid;
  place-items: center;
  height: 48px;
  min-width: 130px;
  padding: 0 22px;
  background: var(--paper-2);
  border: 1.5px solid var(--rule);
  border-radius: 100px;
  transition: border-color var(--t-fast);
}
.provider-pill img {
  height: 24px;
  width: auto;
}
/* Compact variant for the card-header row */
.providers-inline .provider-pill,
.providers-strip-inner .provider-pill {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  height: 28px;
  min-width: 0;
  padding: 0 11px 0 9px;
  border-width: 1px;
}
.providers-inline .provider-pill img,
.providers-strip-inner .provider-pill img {
  height: 14px;
}
/* Inline "online"-style dot. Green when connected, red when not.
   Placed via ::before so we don't need a JS-rendered span. */
.providers-inline .provider-pill::before,
.providers-strip-inner .provider-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
}
.providers-inline .provider-pill.connected::before,
.providers-strip-inner .provider-pill.connected::before {
  background: var(--ok);
}
.providers-inline .provider-pill.disconnected::before,
.providers-strip-inner .provider-pill.disconnected::before {
  background: var(--danger);
}
.provider-pill.disconnected {
  opacity: .45;
  filter: grayscale(1);
}
/* Hide the static dot span — we use the border as the indicator now. */
.provider-pill .dot { display: none; }

/* ===========================================================
   Project drawer (right side, slides in)
   =========================================================== */
.row-actions {
  display: grid;
  grid-auto-flow: column;
  gap: 4px;
  align-items: center;
  justify-content: end;
}

.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, .35);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-base);
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

/* Confirm / alert modals — replacement for native confirm()/alert(). */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, .42);
  display: grid; place-items: center;
  z-index: 2000;
  animation: modal-fade-in .12s ease-out;
}
.modal {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 18px 20px 16px;
  min-width: 320px;
  max-width: min(480px, 92vw);
  box-shadow: 0 24px 60px rgba(10, 10, 10, .18), 0 4px 12px rgba(10, 10, 10, .06);
  display: grid;
  gap: 12px;
}
.modal-h {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.modal-body {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
  white-space: pre-wrap;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Second-opinion modal: a wider variant that holds the source plus one
   suggestion card per provider. Cards are scrollable so a long chunk
   doesn't blow out the viewport. */
.modal.so-modal {
  max-width: min(820px, 96vw);
  width: 820px;
  padding: 16px 18px 14px;
}
.so-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.so-h-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.so-h-icon {
  display: inline-grid;
  place-items: center;
  color: var(--muted);
}
.so-h-icon svg { width: 16px; height: 16px; }
.so-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.so-close:hover { color: var(--ink); background: var(--paper-3); }
.so-close svg { width: 14px; height: 14px; }

.so-body {
  display: grid;
  gap: 12px;
  max-height: 72vh;
  overflow: auto;
}
.so-source {
  padding: 10px 12px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.so-source-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 4px;
}
.so-source-label em {
  font-style: normal;
  color: var(--muted-dim);
}
.so-source-text {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
  white-space: pre-wrap;
}

.so-list {
  display: grid;
  gap: 8px;
}
.so-loading,
.so-empty {
  padding: 16px;
  text-align: center;
}
.so-card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-2);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}
.so-card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.so-card-h-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.so-logo {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: contain;
  flex: 0 0 auto;
}
.so-logo-fallback {
  background: var(--paper-3);
  border: 1px solid var(--rule);
}
.so-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.so-model {
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}
.so-delta {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.so-delta.overrun-warn   { color: #a06012; }
.so-delta.overrun-danger { color: #a32a2a; font-weight: 600; }
.so-delta.underrun-warn  { color: #5a6a85; }
.so-text {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
  white-space: pre-wrap;
}
.so-error {
  font-size: 12.5px;
  color: #a32a2a;
  background: var(--danger-soft, #fbebe8);
  border: 1px dashed #e3b9b3;
  border-radius: 6px;
  padding: 6px 8px;
}
.so-card-foot {
  display: flex;
  justify-content: flex-end;
}
.so-use {
  font-size: 12px;
  padding: 4px 10px;
}

/* Pending state for the streaming version — card is rendered but the
   provider hasn't replied yet. The spinner is a tiny rotating border. */
.so-card.pending {
  opacity: .85;
}
.so-pending-hint {
  font-style: italic;
}
.so-text-pending {
  display: flex;
  align-items: center;
  min-height: 22px;
}
.so-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--rule);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: so-spin .8s linear infinite;
}
@keyframes so-spin { to { transform: rotate(360deg); } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(640px, 95vw);
  background: var(--paper-2);
  border-left: 1px solid var(--rule);
  z-index: 41;
  transform: translateX(100%);
  transition: transform .32s var(--ease);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  box-shadow: -16px 0 48px rgba(10,10,10,.12);
  max-height: 100%;
}
.drawer.open { transform: translateX(0); }

.drawer-h {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--rule);
  align-items: start;
}
.drawer-h .crumb {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.drawer-h h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--ink);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-h .meta {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  justify-content: start;
}

.drawer-tabs {
  display: grid;
  grid-auto-flow: column;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--rule);
  justify-content: start;
}
.drawer-tabs button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 11px 0;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: -1px;
  font-weight: 500;
}
.drawer-tabs button.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
.drawer-tabs button:hover:not(.active) { color: var(--ink-2); }

.drawer-body {
  padding: 18px 22px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  background: var(--paper);
}
.drawer-body .field { gap: 8px; }
.drawer-body textarea { min-height: 180px; }

.drawer-foot {
  padding: 12px 22px;
  border-top: 1px solid var(--rule);
  background: var(--paper-2);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.field-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.drawer-foot .hint {
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-danger {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}
.drawer-danger-h {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

/* Scope picker inside the drawer — pinned tabs + add */
.scope-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.scope-tab {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  background: var(--paper-2);
  color: var(--ink-3);
  border: 1px solid var(--rule);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.scope-tab:hover { color: var(--ink); border-color: var(--rule-strong); }
.scope-tab.active {
  background: var(--ink);
  color: var(--paper-2);
  border-color: var(--ink);
}
.scope-tab.active .flag-pill { background: var(--paper-2); border-color: transparent; color: var(--ink); }
.scope-tab .dot { width: 5px; height: 5px; background: var(--accent); border-radius: 50%; }
.scope-tab.active .dot { background: var(--paper-2); }
.scope-tab .x {
  width: 14px; height: 14px;
  display: inline-grid; place-items: center;
  color: var(--muted);
  background: transparent;
  border: 0; padding: 0;
  border-radius: 100px;
  cursor: pointer;
}
.scope-tab .x:hover { color: var(--accent); background: var(--accent-soft); }
.scope-tab.active .x { color: var(--paper-2); }
.scope-tab .x svg { width: 9px; height: 9px; }

/* ===========================================================
   Responsive
   =========================================================== */
@media (max-width: 1024px) {
  :root { --doc-cols: minmax(0, 1.5fr) 60px 70px minmax(0, 1.4fr) minmax(140px, 1fr) 36px; }
  .doc-row .col-pages { display: none; }
  .page-head h1 { font-size: 26px; }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .app-shell { grid-template-columns: 1fr; }
  .topbar { grid-template-columns: auto auto 1fr; padding: 0 16px; }
  .sidebar { display: none; }
  .app-main { padding: 24px 20px 56px; }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: auto 1fr; padding: 0 16px; }
  .topbar .topbar-crumbs,
  .topbar .icon-btn { display: none; }
  .app-main { padding: 20px 16px 48px; gap: 18px; }
  .page-head { grid-template-columns: 1fr; align-items: start; }
  .page-head-actions { justify-content: start; }
  .page-head h1 { font-size: 24px; }

  .upload { grid-template-columns: 1fr; padding: 18px; gap: 16px; }
  .upload-right { justify-content: stretch; }
  .upload-right .btn { width: 100%; justify-content: center; }

  /* Stack the docs grid as cards on small screens */
  .doc-row.head { display: none; }
  .doc-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px 16px;
  }
  .doc-row .col-source::before { content: "Source · "; color: var(--muted); font-family: var(--font-sans); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
  .doc-row .col-pages::before  { content: "Pages · ";  color: var(--muted); font-family: var(--font-sans); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
  .doc-row .col-pages { display: block; }
  .row-action { justify-self: start; }
  .row-actions { justify-content: start; }
  .addlang-pop { left: auto; right: 0; }
  .drawer { width: 100vw; }
  .drawer-foot { grid-template-columns: 1fr auto; }
  .drawer-foot .hint { white-space: normal; }

  .settings-actions, .settings-suggest { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .user-tile .org { max-width: 100px; }
  .topbar .brand-sub { display: none; }
}
