:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --canvas: #e9ecf1;
  --text: #141b26;
  --text-2: #4d5868;
  --text-3: #6f7a8a;
  --border: #e1e5eb;
  --border-strong: #c9d0da;
  --accent: #1f4fd8;
  --accent-hover: #1a43b8;
  --accent-soft: #edf2fe;
  --on-accent: #ffffff;
  --good: #14713f;
  --good-soft: #e7f5ed;
  --warn: #8a5a00;
  --warn-soft: #fdf5e3;
  --warn-border: #f0dfb6;
  --danger: #b3261e;
  --danger-soft: #fdeeed;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgb(20 27 38 / 0.06);
  --shadow-md: 0 8px 24px rgb(20 27 38 / 0.12);
  --shadow-paper: 0 1px 3px rgb(20 27 38 / 0.12), 0 14px 36px rgb(20 27 38 / 0.14);
  --appbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12161d;
    --surface: #1a2029;
    --canvas: #0d1116;
    --text: #edf0f5;
    --text-2: #b4bdca;
    --text-3: #909baa;
    --border: #2b333f;
    --border-strong: #3d4756;
    --accent: #7ea2ff;
    --accent-hover: #9ab7ff;
    --accent-soft: #1e2a47;
    --on-accent: #0b1220;
    --good: #6fd29c;
    --good-soft: #15291f;
    --warn: #eabf66;
    --warn-soft: #2a2312;
    --warn-border: #4d3f1c;
    --danger: #ff9d97;
    --danger-soft: #36191a;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 8px 24px rgb(0 0 0 / 0.5);
    --shadow-paper: 0 1px 3px rgb(0 0 0 / 0.5), 0 14px 36px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  display: flex;
  flex-direction: column;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; }
h1 { font-size: 1.55rem; line-height: 1.22; font-weight: 650; letter-spacing: -0.015em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.93rem; font-weight: 650; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
main { position: relative; display: flex; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; }
kbd {
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: 0.85em;
}
.muted { color: var(--text-2); }
.small { font-size: 0.87rem; }
.center { text-align: center; }
.lead { margin-top: 6px; color: var(--text-2); font-size: 1rem; }
.lead.small { font-size: 0.92rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { flex: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 26px; height: 26px; }

:is(button, a, input, textarea, summary, .dropzone:focus-within):focus-visible,
.dropzone:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.sm { min-height: 32px; padding: 4px 11px; font-size: 0.87rem; }
.primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.secondary { background: var(--surface); border-color: var(--border-strong); }
.secondary:hover:not(:disabled) { border-color: var(--text-3); background: var(--bg); }
.ghost { color: var(--text-2); font-weight: 500; }
.ghost:hover:not(:disabled) { background: var(--border); color: var(--text); }
.danger-text { color: var(--danger); font-weight: 500; }
.danger-text:hover:not(:disabled) { background: var(--danger-soft); }
.btn.is-danger { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.is-danger { color: #1a0b0a; } }
.icon-btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-3);
  cursor: pointer;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.remove:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Inputs ---------- */
input[type="text"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input[type="text"]:hover, input[type="search"]:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input[type="text"]:focus, input[type="search"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
::placeholder { color: var(--text-3); }
textarea { display: block; resize: vertical; }
.field { display: block; min-width: 0; }
.field > span { display: block; margin-bottom: 4px; color: var(--text-2); font-size: 0.83rem; font-weight: 500; }
.field-error { margin-top: 6px; color: var(--danger); font-size: 0.87rem; }
.invalid { border-color: var(--danger) !important; }

/* ---------- App bar ---------- */
.appbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  flex: none;
  align-items: center;
  gap: 16px;
  min-height: var(--appbar-h);
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { display: inline-flex; align-items: center; gap: 10px; justify-self: start; color: inherit; font-weight: 650; text-decoration: none; border-radius: 6px; }
.logo-mark {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(var(--on-accent), var(--on-accent)) 7px 7px / 12px 2.5px no-repeat,
    linear-gradient(var(--on-accent), var(--on-accent)) 7px 12px / 12px 2.5px no-repeat,
    linear-gradient(var(--on-accent), var(--on-accent)) 7px 17px / 7px 2.5px no-repeat,
    var(--accent);
}
.steps { display: flex; grid-column: 2; align-items: center; gap: 6px; }
.steps li { display: flex; align-items: center; gap: 7px; color: var(--text-3); font-size: 0.87rem; font-weight: 500; }
.steps li + li::before { content: ""; width: 26px; height: 1px; margin-right: 1px; background: var(--border-strong); }
.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 0.76rem;
  font-weight: 600;
}
.steps li.active { color: var(--text); font-weight: 600; }
.steps li.active .step-dot { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps li.done .step-dot { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

.appbar-right { display: flex; grid-column: 3; justify-self: end; align-items: center; gap: 6px; }
.switcher { position: relative; }
.switcher-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 4px 8px 4px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.switcher-btn:hover { border-color: var(--border-strong); background: var(--bg); }
.switcher-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
}
.menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  width: 290px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.menu-label { padding: 6px 9px 4px; color: var(--text-3); font-size: 0.76rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); outline: none; }
.menu-item-text { display: flex; flex: 1; min-width: 0; flex-direction: column; line-height: 1.3; }
.menu-item-text > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item-text small { color: var(--text-3); }
.menu-check { color: var(--accent); }
.menu hr { margin: 6px 0; border: 0; border-top: 1px solid var(--border); }

/* ---------- Upload ---------- */
.page-center { width: 100%; max-width: 740px; margin: 0 auto; padding: clamp(28px, 7vh, 72px) 20px 48px; }
.hero { margin-bottom: 26px; text-align: center; }
.hero h1 { font-size: clamp(1.6rem, 3.4vw, 2.15rem); }
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 44px 24px;
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.dropzone strong { font-size: 1.05rem; font-weight: 600; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.busy { border-style: solid; cursor: progress; background: var(--surface); border-color: var(--border-strong); }
.drop-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
#drop-spinner { margin-bottom: 14px; }
.how { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 28px; }
.how li { display: flex; gap: 10px; color: var(--text-2); font-size: 0.88rem; }
.how .icon { margin-top: 1px; color: var(--accent); }
.how strong { display: block; color: var(--text); font-weight: 600; }
.privacy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 0.83rem;
  text-align: center;
}
.privacy .icon { flex: none; }
#cancel-upload { margin-top: 12px; }

/* ---------- Details form ---------- */
.page-form { width: 100%; max-width: 820px; margin: 0 auto; padding: 32px 20px 0; }
.page-head { margin-bottom: 20px; }
.card { margin-bottom: 14px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head p { color: var(--text-3); font-size: 0.85rem; }
.fields { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-6 { grid-column: 1 / -1; }
.row { display: flex; align-items: flex-start; gap: 8px; padding: 14px 0; border-top: 1px solid var(--border); }
.row:first-child { padding-top: 0; border-top: 0; }
.row .fields { flex: 1; min-width: 0; }
.row .icon-btn { margin-top: 23px; }
.add-row { margin-top: 6px; }
.source-view summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; font-weight: 650; font-size: 1.02rem; }
.source-view summary::-webkit-details-marker { display: none; }
.source-view summary .icon { color: var(--text-3); transition: transform 0.15s; }
.source-view[open] summary .icon { transform: rotate(180deg); }
.source-view p { margin-top: 4px; color: var(--text-3); font-size: 0.85rem; }
.source-view pre {
  max-height: 280px;
  margin: 12px 0 0;
  padding: 12px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font: 0.84rem/1.5 inherit;
  font-family: inherit;
  white-space: pre-wrap;
}
.form-bar {
  position: sticky;
  z-index: 5;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px -20px 0;
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.form-bar > div { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Workspace ---------- */
.workspace { display: grid; flex: 1; grid-template-columns: minmax(340px, 430px) minmax(0, 1fr); min-height: 0; }
.side { display: flex; min-height: 0; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); }
.side-scroll { flex: 1; min-height: 0; padding: 22px 22px 26px; overflow-y: auto; }
.side-foot { flex: none; padding: 12px 22px; border-top: 1px solid var(--border); background: var(--surface); }
#jd { min-height: 280px; height: 42vh; margin-top: 14px; }
.job-actions { display: flex; gap: 8px; margin-top: 12px; }
.hint { margin-top: 10px; color: var(--text-3); font-size: 0.82rem; text-align: center; }

.job-card { display: flex; flex-direction: column; padding: 14px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.eyebrow { color: var(--text-3); font-size: 0.74rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.job-role { margin-top: 3px; font-size: 1.05rem; font-weight: 650; line-height: 1.3; }
.job-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

#results { margin-top: 22px; }
.results-title { font-size: 1.05rem; }
.fit-line { margin-top: 3px; color: var(--text-2); font-size: 0.92rem; }
.fit-line b { color: var(--text); font-weight: 650; }
.fit-bar { height: 6px; margin-top: 9px; overflow: hidden; border-radius: 99px; background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn-border); }
.fit-bar span { display: block; height: 100%; border-radius: 99px; background: var(--good); transition: width 0.4s ease; }
.result-group { margin-top: 20px; }
.gap { margin-top: 8px; padding: 10px 12px; background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: var(--radius-sm); }
.gap > strong { display: block; font-weight: 600; line-height: 1.35; }
.gap > p { margin-top: 2px; color: var(--text-2); font-size: 0.86rem; }
.gap-add { margin-top: 6px; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 0.86rem; font-weight: 600; cursor: pointer; }
.gap-add:hover { text-decoration: underline; }
.gap textarea { margin-top: 8px; font-size: 0.88rem; }
#matches summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; font-size: 0.93rem; font-weight: 650; }
#matches summary::-webkit-details-marker { display: none; }
#matches summary .icon { color: var(--text-3); transition: transform 0.15s; }
#matches[open] summary .icon { transform: rotate(180deg); }
.match-list { margin-top: 8px; }
.match-list li { display: flex; gap: 8px; padding: 3px 0; font-size: 0.9rem; }
.match-list .icon { margin-top: 3px; color: var(--good); }
.fact { display: flex; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.fact-icon { margin-top: 1px; }
.fact-icon.good { color: var(--good); }
.fact-icon.warn { color: var(--warn); }
.fact-body { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.fact-body strong { font-size: 0.92rem; font-weight: 600; }
#removed { margin-top: 5px; font-size: 0.86rem; color: var(--text-2); }
#removed summary { color: var(--accent); font-weight: 600; cursor: pointer; }
#removed ul { margin-top: 5px; padding-left: 16px; list-style: disc; }
#removed li { margin-top: 3px; overflow-wrap: anywhere; }

.canvas { display: flex; min-width: 0; min-height: 0; flex-direction: column; background: var(--canvas); }
.toolbar {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.toolbar-info { display: flex; min-width: 0; align-items: center; gap: 7px; color: var(--text-2); font-size: 0.88rem; }
.toolbar-info .icon { color: var(--text-3); }
.badge { padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 0.76rem; font-weight: 600; }
.stage { flex: 1; min-height: 0; padding: 26px 24px 40px; overflow: auto; }
.paper { position: relative; width: 100%; max-width: 816px; margin: 0 auto; overflow: hidden; }
/* Fixed at Letter width plus room for page shadows, then scaled, so line breaks never depend on window size. */
#sheet { display: block; width: 848px; border: 0; background: transparent; transform-origin: top left; }
#sheet.offstage { position: absolute; left: -9999px; visibility: hidden; }
.blank-state { position: relative; aspect-ratio: 8.5 / 11; background: #fff; border-radius: 3px; box-shadow: var(--shadow-paper); }

.tabs { display: flex; gap: 2px; margin-bottom: 12px; padding: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tab { flex: 1; padding: 5px 8px; border: 0; border-radius: 5px; background: none; color: var(--text-2); font: inherit; font-size: 0.9rem; font-weight: 500; cursor: pointer; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.count { margin-left: 5px; padding: 0 6px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-size: 0.76rem; font-weight: 600; }

#refine-list { margin-top: 8px; }
.refine-parts-title { margin-top: 20px; }
.stretch { margin-bottom: 14px; padding: 12px 14px; background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: var(--radius-sm); }
.stretch strong { display: block; font-weight: 600; }
.stretch p { margin: 3px 0 8px; color: var(--text-2); font-size: 0.87rem; }
.title-changes { margin-top: 16px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.88rem; }
.title-changes h3 { margin-bottom: 2px; }
.title-changes > p { color: var(--text-2); font-size: 0.84rem; }
.title-change { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.title-change div { min-width: 0; }
.title-change s { color: var(--text-3); }
.title-change small { display: block; color: var(--text-3); }
.title-change .btn { flex: none; }
.section-toggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
.section-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.section-toggle input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
#order-list { margin-top: 10px; }
.order-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: grab; }
.order-row + .order-row { margin-top: 6px; }
.order-row:hover { background: var(--bg); }
.order-row.dragging { opacity: 0.5; }
.order-row.drop-target { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.order-row > .icon { flex: none; color: var(--text-3); }
.order-row > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-row .icon-btn:disabled { opacity: 0.3; cursor: default; background: none; }
.order-up .icon { transform: rotate(180deg); }
.refine-row { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.refine-row + .refine-row { margin-top: 6px; }
.refine-row.open { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.refine-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 8px 11px; border: 0; border-radius: var(--radius-sm); background: none; color: inherit; font: inherit; font-size: 0.92rem; font-weight: 500; text-align: left; cursor: pointer; }
.refine-head:hover { background: var(--bg); }
.refine-head span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.refine-head .icon { color: var(--text-3); transition: transform 0.15s; }
.refine-row.open .refine-head .icon { transform: rotate(180deg); }
.refine-body { padding: 2px 11px 11px; }
.refine-body.whole { padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.chip { padding: 2px 9px; border: 1px solid var(--border-strong); border-radius: 99px; background: var(--surface); color: var(--text-2); font: inherit; font-size: 0.8rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.refine-body textarea { font-size: 0.9rem; }
.refine-fact { display: flex; align-items: flex-start; gap: 7px; margin: 8px 0; color: var(--text-2); font-size: 0.84rem; cursor: pointer; }
.refine-fact input { flex: none; margin: 3px 0 0; accent-color: var(--accent); }
.refine-note { margin-top: 8px; padding: 7px 9px; background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: 6px; font-size: 0.84rem; }
.refine-note ul { margin-top: 3px; padding-left: 16px; list-style: disc; }
.refine-note li { overflow-wrap: anywhere; }

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

.segmented { display: inline-flex; flex: none; padding: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 4px 10px; border-radius: 5px; color: var(--text-2); font-size: 0.84rem; font-weight: 500; }
.segmented input:checked + span { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.toolbar { gap: 10px 14px; }
.toolbar-info { flex: 1; flex-wrap: wrap; }
.page-count { color: var(--text); font-weight: 600; }
.length-note { color: var(--warn); }
.ghost-sheet { display: flex; flex-direction: column; gap: 9px; padding: 7%; }
.ghost-sheet i { display: block; width: 100%; height: 8px; border-radius: 4px; background: #e9ecf1; }
.ghost-sheet i.h { height: 20px; }
.ghost-sheet i.strong { background: #d9dee6; }
.ghost-sheet b { display: block; width: 100%; height: 1.5px; margin-top: 14px; background: #d9dee6; }
.ghost-sheet .w25 { width: 25%; } .ghost-sheet .w40 { width: 40%; } .ghost-sheet .w50 { width: 50%; }
.ghost-sheet .w60 { width: 60%; } .ghost-sheet .w70 { width: 70%; } .ghost-sheet .w80 { width: 80%; }
.ghost-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: min(380px, 86%);
  padding: 20px 22px;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 1px solid #e1e5eb;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(20 27 38 / 0.1);
  color: #141b26;
  text-align: center;
}
.ghost-msg strong { font-weight: 650; }
.ghost-msg .muted { color: #4d5868; font-size: 0.88rem; }
.ghost-msg .spinner { margin-bottom: 8px; border-color: #dbe4fb; border-top-color: #1f4fd8; }
.blank-state.loading .ghost-sheet i, .blank-state.loading .ghost-sheet b { animation: shimmer 1.4s ease-in-out infinite; }
@keyframes shimmer { 50% { opacity: 0.45; } }

.spinner {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner.lg { width: 34px; height: 34px; border-width: 3px; }
.spinner.on-primary { width: 15px; height: 15px; border-color: rgb(255 255 255 / 0.35); border-top-color: var(--on-accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast and dialog ---------- */
.toast {
  position: fixed;
  z-index: 40;
  bottom: 22px;
  left: 50%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: max-content;
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 10px 10px 14px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: rise 0.18s ease-out;
}
.toast.error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.toast-icon { margin-top: 1px; }
.toast:not(.error) .toast-icon { color: var(--good); }
#toast-text { flex: 1; padding-top: 1px; overflow-wrap: anywhere; }
.toast.error .icon-btn { color: inherit; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }

.dialog {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  color: var(--text);
}
.dialog::backdrop { background: rgb(13 17 22 / 0.45); }

/* ---------- Settings ---------- */
.settings-dialog { width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.settings-head h2 { font-size: 1.25rem; }
.settings-dialog h3 { margin: 18px 0 8px; }
.provider-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.provider-option {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.provider-option:hover { border-color: var(--text-3); }
.provider-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.provider-option:has(input:disabled) { background: var(--bg); color: var(--text-3); cursor: not-allowed; }
.provider-option:has(input:disabled):hover { border-color: var(--border-strong); }
.provider-option:has(input:disabled) small { color: var(--text-3); }
.key-included { color: var(--text-2); font-size: 0.86rem; }
.provider-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.provider-option input { position: absolute; opacity: 0; pointer-events: none; }
.provider-option strong { font-weight: 600; }
.provider-option small { overflow: hidden; color: var(--text-2); text-overflow: ellipsis; white-space: nowrap; }
.check-row { display: flex; align-items: flex-start; gap: 9px; margin-top: 12px; cursor: pointer; }
.check-row input { flex: none; width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); }
.check-row strong { display: block; font-weight: 500; }
.check-row small { display: block; color: var(--text-2); font-size: 0.85rem; }
.key-row { padding: 12px 0; border-top: 1px solid var(--border); }
.key-row:first-child { padding-top: 0; border-top: 0; }
.key-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.key-row-head strong { font-weight: 600; }
.key-row-head a { margin-left: auto; color: var(--accent); font-size: 0.85rem; }
.pill { padding: 1px 8px; border-radius: 99px; font-size: 0.76rem; font-weight: 600; }
.pill.on { background: var(--good-soft); color: var(--good); }
.pill.off { background: var(--border); color: var(--text-2); }
#key-rows { margin-top: 12px; }
.key-input-row { display: flex; flex-wrap: wrap; gap: 6px; }
.key-input-row input { min-width: 0; flex: 1 1 190px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; }
.key-input-row input:hover { border-color: var(--text-3); }
.key-input-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.key-input-row .btn { flex: none; }
.key-result { display: flex; align-items: center; gap: 5px; margin-top: 6px; font-size: 0.86rem; }
.key-result.ok { color: var(--good); }
.key-result.bad { color: var(--danger); }
.settings-note { display: flex; gap: 7px; margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 0.83rem; }
.settings-note .icon { margin-top: 2px; }
.settings-note code { font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 0.92em; }

.key-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
}
.key-banner > .icon { color: var(--warn); }
.key-banner > div { flex: 1; min-width: 0; font-size: 0.9rem; color: var(--text-2); }
.key-banner strong { display: block; color: var(--text); font-weight: 600; }
.key-banner .btn { flex: none; }
.written-by { margin-top: 4px; color: var(--text-3); font-size: 0.82rem; }
.toast.warn .toast-icon { color: var(--warn); }
#toast-action { flex: none; }
.dialog p { margin-top: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Sign in ---------- */
.login-body { align-items: center; justify-content: center; padding: 24px 16px; }
.login-main { display: flex; flex: none; width: min(400px, 100%); flex-direction: column; gap: 18px; overflow: visible; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.05rem; font-weight: 650; }
.login-card { display: flex; flex-direction: column; gap: 14px; padding: 26px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-sm); }
.login-card h1 { font-size: 1.4rem; }
.login-card p.small { margin-top: -10px; }
.login-card input { width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; }
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .field-error { margin-top: -4px; }
.login-card .btn { min-height: 40px; }

/* ---------- Small screens ---------- */
@media (max-width: 960px) {
  main { overflow-y: visible; }
  html, body { height: auto; }
  body { min-height: 100%; }
  .workspace { display: block; }
  .side { border-right: 0; border-bottom: 1px solid var(--border); }
  .side-scroll { overflow: visible; }
  #jd { height: 240px; min-height: 200px; }
  .side-foot { position: sticky; z-index: 5; bottom: 0; }
  .toolbar { position: sticky; z-index: 5; top: 0; }
  .stage { overflow: hidden; padding: 16px; }
}
@media (max-width: 640px) {
  .appbar { grid-template-columns: 1fr auto; padding: 8px 16px; }
  .steps { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
  .appbar-right { grid-column: 2; }
  .logo > span:last-child { display: none; }
  #open-settings { white-space: nowrap; }
  .switcher-name { max-width: 100px; }
  .step-label { display: none; }
  .steps li.active .step-label { display: inline; }
  .how { grid-template-columns: minmax(0, 1fr); }
  .page-center, .page-form { padding-left: 16px; padding-right: 16px; }
  .form-bar { margin-left: -16px; margin-right: -16px; padding: 10px 16px; }
  .span-2, .span-3 { grid-column: 1 / -1; }
  .side-scroll { padding: 18px 16px; }
  .side-foot { padding: 10px 16px; }
  .toolbar { padding: 8px 16px; }
  .menu { width: min(290px, calc(100vw - 32px)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .spinner { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
}

/* ---------- Role tabs ---------- */

.role-shell { height: 100dvh; overflow: hidden; }
.role-bar { display: flex; flex: none; align-items: flex-end; gap: 6px; padding: 6px 12px 0; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--bg); }
.role-tabs { display: flex; gap: 2px; min-width: 0; }
.role-tab { display: flex; flex: none; align-items: center; max-width: 250px; margin-bottom: -1px; border: 1px solid transparent; border-bottom: 0; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.role-tab:hover { background: var(--border); }
.role-tab.active { border-color: var(--border); background: var(--surface); }
.role-tab-name { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 7px 4px 7px 11px; border: 0; background: none; color: var(--text-2); font: inherit; font-size: 0.87rem; cursor: pointer; }
.role-tab.active .role-tab-name { color: var(--text); font-weight: 600; }
.role-tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-tab .spinner { flex: none; width: 12px; height: 12px; border-width: 2px; border-color: var(--border-strong); border-top-color: var(--accent); }
.role-tab-status { display: none; flex: none; width: 8px; height: 8px; border-radius: 50%; }
.role-tab-status.ready { display: block; background: var(--accent); }
.role-tab-status.failed { display: block; background: var(--danger); }
.role-tab-close { flex: none; width: 24px; height: 24px; margin-right: 4px; padding: 0; border: 0; border-radius: 5px; background: none; color: var(--text-3); font: inherit; font-size: 1rem; line-height: 1; cursor: pointer; }
.role-tab-close:hover { background: var(--border-strong); color: var(--text); }
.role-new { flex: none; margin-bottom: 4px; padding: 4px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--accent); font: inherit; font-size: 0.87rem; font-weight: 600; white-space: nowrap; cursor: pointer; }
.role-new:hover:not(:disabled) { background: var(--accent-soft); }
.role-new:disabled { color: var(--text-3); cursor: default; }
.role-frames { position: relative; flex: 1; min-height: 0; }
.role-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; visibility: hidden; }
.role-frame.shown { visibility: visible; }

/* ---------- Saved resumes ---------- */

.resume-filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; margin-bottom: 14px; }
.resume-group { margin-bottom: 14px; }
.resume-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--border); }
.resume-row-text { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.resume-row-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.order-prompt { margin-bottom: 14px; padding: 12px 14px; background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.order-prompt p { margin: 0 0 8px; font-size: 0.9rem; }
.order-prompt strong { font-weight: 600; }
.order-prompt-actions { display: flex; flex-wrap: wrap; gap: 6px; }
