:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --fg: #1b1b18;
  --muted: #6b6b64;
  --card-bg: #ffffff;
  --border: #e2e0da;
  --accent: #2f6f4f;
  --danger: #a5342a;
  --unconfirmed-bg: #fff3cd;
  --unconfirmed-border: #d9a441;
  --done-bg: #e6f2ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --fg: #ece9e3;
    --muted: #9a978f;
    --card-bg: #201f1c;
    --border: #33322d;
    --accent: #5fb384;
    --danger: #e07a6e;
    --unconfirmed-bg: #4a3c14;
    --unconfirmed-border: #d9a441;
    --done-bg: #1f3a2b;
  }
}

/* Title font: Funnel Sans (latin) + HarmonyOS Sans SC (CJK fallback, no extra
   webfont download) - the lighter variant, since this is an internal
   single-user tool where a 1.5MB Heavy CJK webfont isn't worth it. Only
   applied to headings/brand, never to body text. */
:root {
  --title-font: "Funnel Sans", "HarmonyOS Sans SC", "PingFang SC",
    "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

h1, h2, .brand { font-family: var(--title-font); font-weight: 700; }

/* Left sidebar app shell. Mobile-first: the sidebar is a slim top bar with
   links wrapped in a row below 768px; desktop gets a fixed-width vertical
   column pinned to the full viewport height - a genuinely different layout
   at each breakpoint, not a scaled copy, matching this file's existing
   convention (see the repeatable-row comment further down). */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}
.sidebar-top { display: flex; align-items: center; }
.sidebar .brand { color: var(--fg); text-decoration: none; white-space: nowrap; }

.sidebar-links { display: flex; flex-direction: row; flex-wrap: wrap; gap: 4px; }
.sidebar-links a {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.sidebar-links a:hover { background: var(--bg); color: var(--fg); }
.sidebar-links a.active { background: var(--accent); color: #fff; }
.sidebar-divider { display: none; }

.account-area { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.account-area form { margin: 0; }
.account-area button { padding: 4px 10px; font-size: 12px; }
.sidebar .account-area { margin-left: auto; }

.main-content { flex: 1; min-width: 0; }
.container { max-width: 880px; margin: 0 auto; padding: 16px; }

.blurb { color: var(--muted); }

/* Mobile-first: single column by default; desktop (>=768px) gets the
   multi-column grid and more generous spacing - not just a scaled-down copy. */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 16px 0; }
.card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--card-bg); }
.card h2 { margin: 0 0 4px; font-size: 15px; }

@media (min-width: 768px) {
  .app-shell { flex-direction: row; }
  .sidebar {
    width: 220px;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 20px 16px;
  }
  .sidebar-links { flex-direction: column; gap: 2px; margin-top: 8px; }
  .sidebar-links a { padding: 8px 10px; }
  .sidebar-divider { display: block; border: none; border-top: 1px solid var(--border); margin: 10px 0; }
  .sidebar .account-area { margin-left: 0; margin-top: auto; flex-direction: column; align-items: flex-start; gap: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
  .container { padding: 24px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin: 20px 0; }
  .card { padding: 14px; }
}

form label { display: block; margin-bottom: 12px; }
form input[type="text"], form input[type="password"], form input[type="number"], form textarea, form select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
form .checkbox-label { display: flex; align-items: center; gap: 8px; }
form .checkbox-label input { width: auto; }

/* Custom chevron: native <select> arrows are inconsistent across browsers/OSes. */
form select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  cursor: pointer;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a919e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
}

button {
  padding: 8px 16px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer; font: inherit;
  white-space: nowrap; flex-shrink: 0;
}
button.danger { background: var(--danger); border-color: var(--danger); }
button[type="button"] { background: transparent; color: var(--accent); }

.inline-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 0; }

.new-entry { margin-bottom: 20px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--card-bg); }
.new-entry summary { cursor: pointer; font-weight: 600; }
.new-entry form { margin-top: 12px; }

.qa-list { display: flex; flex-direction: column; gap: 12px; }
.qa-entry { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--card-bg); }
.qa-question { font-weight: 600; margin-bottom: 8px; }
.qa-entry-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.qa-delete-form { margin-top: 8px; }
.qa-meta { color: var(--muted); font-size: 12px; margin-top: 6px; }

.template-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
}

.changelog-body { white-space: pre-wrap; background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; overflow-x: auto; }

.unconfirmed {
  background: var(--unconfirmed-bg);
  border: 1px dashed var(--unconfirmed-border);
  border-radius: 4px;
  padding: 0 4px;
}

#test-api-key-result, #test-oss-result, #test-lark-result { margin-left: 8px; color: var(--muted); }

.profile-actions { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

/* Mobile-first: each repeatable-group row stacks vertically (simplest layout,
   every field fully readable on a narrow screen). Desktop (>=768px) switches
   to a compact single-line row - a genuinely different layout, not a scaled
   copy, per the mobile-simpler-than-desktop convention. */
.repeatable-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.repeatable-row { display: flex; flex-direction: column; gap: 6px; align-items: stretch; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.repeatable-row input, .repeatable-row textarea { flex: 1; min-width: 0; }
.repeatable-row .remove-row { align-self: flex-end; }

@media (min-width: 768px) {
  .repeatable-row { flex-direction: row; align-items: flex-start; padding: 0; border: none; border-radius: 0; }
  .repeatable-row-wide { flex-wrap: wrap; }
  .repeatable-row-wide textarea { flex-basis: 100%; }
  .repeatable-row .remove-row { align-self: auto; }
}

.add-row { margin: 8px 0 24px; background: transparent; color: var(--accent); }

.form-submit-row { margin-top: 24px; }

.score-table { border-collapse: collapse; margin: 8px 0 16px; width: 100%; max-width: 360px; }
.score-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.score-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.flash-messages { margin-bottom: 16px; }
.flash-message { border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0; }

dialog { border: 1px solid var(--border); border-radius: 10px; padding: 20px; max-width: 480px; background: var(--card-bg); color: var(--fg); }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

/* Per-job workspace: summary header on top, then a section nav on the left
   and the selected section's detail on the right. Mobile-first: the nav is
   a horizontal scrolling tab row above the panel; desktop (>=768px) turns it
   into a vertical column beside the panel. */
.main-content.workspace-main { max-width: 1200px; }
.ws-header { margin-bottom: 16px; }
.ws-header h1 { margin-bottom: 4px; }
/* One flat strip, not four boxes: a single bordered container, cells divided
   by hairlines; a finished step gets a light-green fill (no dots, accent bars or nested
   cards - see Little Jelly pref-visual-avoid-nested-containers). */
.ws-steps { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--border); border-radius: 10px; background: var(--card-bg); overflow: hidden; }
.ws-steps li { min-width: 0; border-bottom: 1px solid var(--border); }
.ws-steps li:nth-child(odd) { border-right: 1px solid var(--border); }
.ws-steps li:nth-last-child(-n+2) { border-bottom: none; }
.ws-step { display: block; padding: 10px 14px; color: var(--fg); text-decoration: none; }
.ws-step:hover { background: var(--bg); }
.ws-step-label { display: block; color: var(--muted); font-size: 12px; }
.ws-step-value { display: block; font-weight: 600; white-space: nowrap; }
.ws-step.done { background: var(--done-bg); }
.ws-step.bad .ws-step-value { color: var(--danger); }
.ws-step.todo .ws-step-value { color: var(--muted); font-weight: 500; }

.ws-body { display: flex; flex-direction: column; gap: 16px; }
.ws-nav { display: flex; flex-direction: row; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.ws-nav a { color: var(--muted); text-decoration: none; white-space: nowrap; padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.ws-nav a:hover { background: var(--card-bg); color: var(--fg); }
.ws-nav a.active { background: var(--accent); color: #fff; }
.ws-panel { min-width: 0; flex: 1; }

@media (min-width: 768px) {
  .ws-steps { grid-template-columns: repeat(4, 1fr); }
  .ws-steps li, .ws-steps li:nth-last-child(-n+2) { border-bottom: none; }
  .ws-steps li:not(:last-child) { border-right: 1px solid var(--border); }
  .ws-body { flex-direction: row; align-items: flex-start; }
  .ws-nav { flex-direction: column; width: 180px; flex-shrink: 0; overflow-x: visible; border-bottom: none; border-right: 1px solid var(--border); padding: 0 12px 0 0; position: sticky; top: 24px; }
}

/* Materials: one card per document, a segmented control picks how to attach it. */
.mat-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 16px 0; }
.mat-card { border: 1px solid var(--border); border-radius: 10px; padding: 16px; background: var(--card-bg); min-width: 0; }
.mat-card h2 { margin: 0 0 10px; font-size: 18px; }
.mat-current { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 14px; border-radius: 8px; background: var(--bg); color: var(--muted); }
.mat-current.set { background: var(--done-bg); color: var(--fg); }
.mat-current-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.mat-current a { white-space: nowrap; font-size: 13px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; margin-bottom: 14px; border-radius: 8px; background: var(--bg); }
.seg button, .seg button[type="button"] { padding: 5px 12px; border: none; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; }
.seg button.active, .seg button[type="button"].active { background: var(--card-bg); color: var(--fg); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.mat-card form label { margin-bottom: 12px; }
.mat-card input[type="file"] { width: 100%; }

@media (min-width: 768px) {
  .mat-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

/* PDF preview: side by side on desktop; on phones just the "open" link - inline
   PDF frames are unusable on small screens (mobile shows less, not a shrunken copy). */
.pdf-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 20px; }
.pdf-pane { min-width: 0; }
.pdf-pane-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.pdf-pane-head a { white-space: nowrap; font-size: 13px; }
.pdf-frame { display: none; width: 100%; height: 760px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

@media (min-width: 768px) {
  .pdf-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .pdf-frame { display: block; }
}
.file-table { border-collapse: collapse; width: 100%; margin: 8px 0 16px; }
.file-table th, .file-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.file-table th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.file-table td { overflow-wrap: anywhere; }

/* "Submit as" file-name field: the name an employer sees, shown with a fixed .pdf suffix. */
.name-field { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.name-field input { flex: 1; min-width: 0; }
.submit-as-ext, .submit-as-label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.submit-as { display: flex; align-items: center; gap: 6px; width: 100%; margin: 6px 0 0; }
.submit-as input[type="text"] { flex: 1; min-width: 0; padding: 4px 8px; background: var(--card-bg); }
.submit-as button { padding: 4px 10px; font-size: 12px; }

.rerun-form { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0 16px; }

/* Live Step 1-9 autofill progress. */
.steps-table { border-collapse: collapse; width: 100%; margin: 8px 0 20px; }
.steps-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.steps-table .step-n { white-space: nowrap; color: var(--muted); width: 1%; }
.steps-table .step-title { font-weight: 600; }
.steps-table .step-status { white-space: nowrap; }
.steps-table .step-detail { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.step-row.pending .step-title, .step-row.pending .step-status { color: var(--muted); font-weight: 400; }
.step-row.running .step-status { font-weight: 600; }
.step-row.complete { background: var(--done-bg); }
.step-row.failed .step-status, .step-row.failed .step-detail { color: var(--danger); }
.step-row.manual .step-status { color: var(--unconfirmed-border); }

@media (max-width: 767px) {
  .steps-table .step-detail { display: none; }  /* phones: step + status only; details live on desktop */
}

/* Settings: keep Save in view however long the page gets. */
.save-bar { position: sticky; bottom: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 24px -16px 0; padding: 12px 16px; background: var(--bg); border-top: 1px solid var(--border); }
.save-bar .blurb { margin: 0; font-size: 13px; }

.rec-list { margin: 8px 0 12px; padding-left: 22px; font-size: 13px; color: var(--muted); }
.rec-list li { margin: 2px 0; overflow-wrap: anywhere; }

/* Company application-form editor. */
.form-section { margin: 20px 0; }
.field-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.rep-row { border-top: 1px solid var(--border); padding-top: 10px; margin-bottom: 12px; }
.req { color: var(--danger); }
.add-row { margin: 4px 0 8px; }
.remove-row { font-size: 12px; padding: 3px 10px; }
@media (min-width: 768px) { .field-grid { grid-template-columns: repeat(2, 1fr); } }

/* Questions read from the live form (application profile). */
.q-block { border: none; border-top: 1px solid var(--border); margin: 0; padding: 12px 0; }
.q-block legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.q-block .checkbox-label { margin-bottom: 4px; }
