/* ============================================================
   Resume Builder — app chrome
   Design tokens → base → header → buttons → layout → cards →
   forms → entries → template switch → ATS gauge → JD matcher →
   preview → resume templates → responsive → print → reduced motion
   ============================================================ */

/* ---------- design tokens ---------- */
:root {
  /* color — refined professional palette, no gradient clichés */
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #182430;
  --ink-2: #3b4a5e;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-soft: #eef2f7;
  --field-bg: #fbfcfe;
  --accent: #1f5cc4;
  --accent-strong: #184ea8;
  --accent-soft: #e9effc;
  --accent-line: #c9d9f6;
  --ok: #15803d;
  --ok-soft: #e6f5eb;
  --ok-line: #c2e4cd;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --warn-line: #eed3a7;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --bad-line: #f2c9c9;

  /* spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  /* radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* type scale */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;

  /* motion tokens */
  --dur-fast: 150ms;
  --dur-med: 260ms;
  --dur-slow: 600ms;
  --ease-out: cubic-bezier(.22, .61, .36, 1);

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .07);
  --shadow-header: 0 1px 0 rgba(16, 24, 40, .05), 0 10px 28px -14px rgba(16, 24, 40, .22);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  animation: page-in var(--dur-med) var(--ease-out);
}
@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
::selection { background: var(--accent-soft); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  top: -48px;
  left: var(--s-4);
  z-index: 100;
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  text-decoration: none;
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus-visible { top: var(--s-3); }

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-5);
  padding-left: max(var(--s-5), env(safe-area-inset-left));
  padding-right: max(var(--s-5), env(safe-area-inset-right));
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-header);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px;
  flex: none;
  display: grid; place-items: center;
  background: var(--ink); color: #fff;
  border-radius: 9px; font-size: 17px;
}
.brand strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: var(--fs-xs); }
.header-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              transform 80ms var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.btn:hover { border-color: #b9c4d4; background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.dashed {
  width: 100%;
  border-style: dashed;
  color: var(--accent);
  margin-top: 10px;
  background: transparent;
}
.btn.dashed:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- filename hint ---------- */
.filename-hint {
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--muted);
  padding: var(--s-2) var(--s-3) 0;
}
.filename-hint code {
  font-family: var(--font-mono);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  font-size: var(--fs-xs);
  color: var(--ink);
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(380px, 480px) minmax(0, 1fr);
  gap: var(--s-5);
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--s-4) var(--s-5) 40px;
  align-items: start;
}

/* ---------- editor cards ---------- */
.editor {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
  counter-reset: card-step;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: 18px;
  animation: card-in var(--dur-med) var(--ease-out);
  animation-fill-mode: backwards;
}
/* gentle stagger so the form reads top-to-bottom on load */
.editor .card:nth-child(2) { animation-delay: 40ms; }
.editor .card:nth-child(3) { animation-delay: 80ms; }
.editor .card:nth-child(4) { animation-delay: 120ms; }
.editor .card:nth-child(5) { animation-delay: 160ms; }
.editor .card:nth-child(n+6) { animation-delay: 200ms; }
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.card h2 {
  margin: 0 0 var(--s-1);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.card h2::before {
  counter-increment: card-step;
  content: counter(card-step, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  padding: 2px 7px;
  border-radius: var(--r-pill);
  flex: none;
}
.card h2 .count { margin-left: auto; }
.count {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  background: var(--line-soft);
  padding: 2px 9px;
  border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}
.tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--line-soft);
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.hint { font-size: var(--fs-sm); color: var(--muted); margin: 0 0 var(--s-3); }

/* ---------- forms ---------- */
label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 10px;
}
input[type="text"], input[type="email"], input[type="tel"], input[type="url"], textarea {
  width: 100%;
  margin-top: 5px;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 400;
  color: var(--ink);
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
input:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}
textarea { resize: vertical; line-height: 1.55; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-3); }
.grid2 .span2 { grid-column: 1 / -1; }
label.check {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  padding-top: 24px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
label.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* ---------- dynamic entries ---------- */
.entry {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: var(--s-4);
  margin-bottom: var(--s-3);
  background: var(--field-bg);
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.entry.is-entering { animation: entry-in var(--dur-med) var(--ease-out); }
@keyframes entry-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.entry.is-leaving { opacity: 0; transform: translateY(-6px) scale(.985); }
.entry-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.entry-head strong { font-size: 13.5px; }
.entry-head .remove {
  border: none;
  background: none;
  color: var(--bad);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.entry-head .remove:hover { background: var(--bad-soft); }
.entry-head .remove:focus-visible {
  outline: 2px solid var(--bad);
  outline-offset: 1px;
}
.date-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0 var(--s-3); align-items: end; }
.date-row input:disabled { background: var(--line-soft); color: var(--muted); }

/* ---------- template switcher ---------- */
.template-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); }
.template-switch button {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 8px;
  cursor: pointer;
  touch-action: manipulation;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              transform 80ms var(--ease-out);
}
.template-switch button strong { font-size: 13.5px; }
.template-switch button span { font-size: 11.5px; color: var(--muted); text-align: center; }
.template-switch button:hover { border-color: #b9c4d4; }
.template-switch button:active { transform: scale(.98); }
.template-switch button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.template-switch button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.template-switch button[aria-pressed="true"] strong { color: var(--accent-strong); }

/* ---------- ATS score gauge ---------- */
.ats-score-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  margin: var(--s-3) 0 var(--s-2);
}
.ats-gauge {
  position: relative;
  width: 104px;
  height: 104px;
  flex: none;
}
.ats-gauge svg { display: block; transform: rotate(-90deg); }
.gauge-track { fill: none; stroke: #e8edf4; stroke-width: 10; }
.gauge-fill {
  fill: none;
  stroke: var(--ok);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset var(--dur-slow) var(--ease-out),
              stroke var(--dur-med) var(--ease-out);
}
.ats-number {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.ats-meta { min-width: 0; }
.ats-verdict { font-size: var(--fs-base); font-weight: 700; line-height: 1.4; }
.ats-checks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.ats-checks li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 13.5px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  background: #f8fafc;
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.ats-checks .mark {
  font-weight: 800;
  flex: none;
  width: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ats-checks li.pass .mark { color: var(--ok); }
.ats-checks li.fail .mark { color: var(--bad); }
.ats-checks li .advice { display: block; color: var(--muted); font-size: var(--fs-xs); margin-top: 2px; line-height: 1.45; }
.ats-checks li.pass { border-color: var(--ok-line); background: var(--ok-soft); }
.ats-checks li.fail { border-color: var(--bad-line); background: var(--bad-soft); }

/* ---------- JD matcher ---------- */
.jd-results { margin-top: var(--s-4); animation: card-in var(--dur-med) var(--ease-out); }
.jd-results h3 { font-size: var(--fs-sm); margin: var(--s-3) 0 6px; }
.jd-results h3 small { font-weight: 400; color: var(--muted); }
.jd-score {
  font-size: var(--fs-base);
  font-weight: 700;
  background: var(--line-soft);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-variant-numeric: tabular-nums;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span {
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  border: 1px solid;
  overflow-wrap: break-word;
}
.chips-ok span { color: var(--ok); border-color: var(--ok-line); background: var(--ok-soft); }
.chips-miss span { color: var(--warn); border-color: var(--warn-line); background: var(--warn-soft); }
#btn-jd { margin-top: 10px; }

/* ---------- preview column ---------- */
.preview-wrap { position: sticky; top: 84px; min-width: 0; }
.preview-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
  padding: 0 4px;
}
.print-note { font-size: var(--fs-sm); color: var(--muted); text-align: center; margin-top: var(--s-3); }
#resume {
  transition: opacity var(--dur-med) var(--ease-out),
              transform var(--dur-med) var(--ease-out);
}
#resume.is-switching { opacity: 0; transform: translateY(8px); }

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
  padding: 0 var(--s-4) max(28px, env(safe-area-inset-bottom));
}

/* ============================================================
   RESUME — base (shared by all templates)
   ATS rules: single column, real text, standard fonts,
   "•" bullets, no tables / text boxes / graphics.
   ============================================================ */
.resume {
  background: #fff;
  color: #111;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-size: 11pt;
  line-height: 1.45;
  padding: 46px 50px;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  max-width: 850px;
  margin: 0 auto;
  overflow-wrap: break-word;
}
.resume h1.r-name {
  font-size: 22pt;
  margin: 0;
  line-height: 1.2;
  color: #111;
}
.resume .r-title { font-size: 12pt; color: #333; margin-top: 2px; }
.resume .r-contact { font-size: 10pt; color: #333; margin-top: 6px; line-height: 1.5; }
.resume .r-contact a { color: #333; text-decoration: none; }
.resume .r-section { margin-top: 16px; }
.resume .r-section h2 {
  font-size: 12pt;
  margin: 0 0 8px;
  color: #111;
}
.resume .r-section p { margin: 0 0 6px; }
.resume .r-job { margin-bottom: 12px; }
.resume .r-job:last-child { margin-bottom: 0; }
.resume .r-job-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.resume .r-job-title { font-weight: bold; }
.resume .r-dates { font-size: 10pt; color: #333; white-space: nowrap; }
.resume .r-job-sub { font-style: italic; font-size: 10.5pt; color: #333; margin: 1px 0 4px; }
.resume ul { margin: 4px 0 0; padding-left: 20px; }
.resume ul li { margin-bottom: 3px; }
.resume ul li::marker { content: "•  "; }
.resume .r-edu-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.resume .r-edu { margin-bottom: 8px; }
.resume .r-notes { font-size: 10.5pt; color: #333; margin: 2px 0 0; }
.resume .r-proj-head { font-weight: bold; }
.resume .r-cert { margin-bottom: 4px; }

/* ---------- Classic: centered header, serif name ---------- */
.template-classic .r-header { text-align: center; }
.template-classic h1.r-name { font-family: Georgia, "Times New Roman", serif; font-size: 24pt; letter-spacing: .01em; }
.template-classic .r-section h2 {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 11pt;
  border-bottom: 1px solid #111;
  padding-bottom: 4px;
}

/* ---------- Modern: left aligned, single subtle accent ---------- */
.template-modern h1.r-name { font-size: 24pt; font-weight: 800; letter-spacing: -.01em; }
.template-modern .r-title { color: #1f5fa8; font-weight: 700; }
.template-modern .r-section h2 {
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: 11pt;
  color: #1f5fa8;
  border-bottom: 2px solid #1f5fa8;
  padding-bottom: 4px;
}
.template-modern .r-name-row { border-left: 4px solid #1f5fa8; padding-left: 14px; }

/* ---------- Compact: tighter, one-page oriented ---------- */
.template-compact { font-size: 10.5pt; line-height: 1.38; padding: 34px 38px; }
.template-compact h1.r-name { font-size: 19pt; }
.template-compact .r-title { font-size: 11pt; }
.template-compact .r-contact { font-size: 9.5pt; margin-top: 4px; }
.template-compact .r-section { margin-top: 11px; }
.template-compact .r-section h2 {
  font-size: 10.5pt;
  text-transform: uppercase;
  letter-spacing: .09em;
  border-bottom: 1px solid #111;
  padding-bottom: 3px;
  margin-bottom: 6px;
}
.template-compact .r-job { margin-bottom: 8px; }
.template-compact ul li { margin-bottom: 2px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; }
  .preview-wrap { position: static; }
  .resume { max-width: 100%; }
}
@media (max-width: 560px) {
  .app-header { flex-direction: column; align-items: stretch; }
  .header-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .date-row { grid-template-columns: 1fr 1fr; }
  label.check { padding-top: 0; }
  .template-switch { grid-template-columns: 1fr; }
  .resume { padding: 28px 22px; }
  .ats-score-row { gap: var(--s-3); }
}

/* ============================================================
   PRINT — A4, black text, app chrome hidden.
   This is what makes the PDF ATS-readable: real selectable
   text, single column, standard fonts, ≥0.6in margins.
   ============================================================ */
@media print {
  @page { size: A4; margin: 0.65in 0.7in; }
  .no-print { display: none !important; }
  body { background: #fff; animation: none; font-size: 11pt; }
  .layout { display: block; max-width: none; padding: 0; margin: 0; }
  .preview-wrap { position: static; }
  #resume {
    box-shadow: none;
    border-radius: 0;
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
    transition: none;
  }
  #resume, #resume * { color: #000 !important; border-color: #000 !important; }
  #resume a { text-decoration: none; color: #000 !important; }
  #resume .r-section { break-inside: avoid-page; }
  #resume ul li::marker { color: #000 !important; }
}

/* ---------- reduced motion: instant state, no animation ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
