:root {
  --bg: #f2f1ee;
  --surface: #fffefb;
  --surface-2: #f6f5f1;
  --surface-3: #e7e5df;
  --text: #1a1d23;
  --muted: #646b75;
  --muted-2: #8b919a;
  --border: #dddbd4;
  --border-strong: #c6c4bc;
  --primary: #2c4a7a;
  --primary-strong: #213a62;
  --primary-soft: #e3e9f4;
  --danger: #b93a48;
  --danger-soft: #fae8e9;
  --shadow: 0 28px 70px -42px rgb(26 36 60 / 45%);
  --shadow-sm: 0 15px 34px -24px rgb(26 36 60 / 45%);
  --scrim: rgb(18 22 30 / 38%);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #14161b;
  --surface: #1c1f26;
  --surface-2: #232731;
  --surface-3: #0f1115;
  --text: #edf0f5;
  --muted: #a3abb8;
  --muted-2: #788190;
  --border: #2e333e;
  --border-strong: #454c5a;
  --primary: #93b4ec;
  --primary-strong: #b5ccf4;
  --primary-soft: #26324a;
  --danger: #ff8b96;
  --danger-soft: #44272b;
  --shadow: 0 28px 70px -38px rgb(0 0 0 / 85%);
  --shadow-sm: 0 15px 34px -22px rgb(0 0 0 / 75%);
  --scrim: rgb(0 0 0 / 58%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .52; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
input, select, textarea { font-size: .92rem; font-weight: 450; letter-spacing: -0.005em; }
input, select { min-height: 42px; padding: 0 12px; }
input[type="range"] { min-height: 28px; padding: 0; border: 0; background: transparent; accent-color: var(--primary); }
input[type="color"] { padding: 0; }
textarea { resize: vertical; padding: 10px 12px; line-height: 1.5; min-height: 96px; }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}
button:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 30%, transparent); outline-offset: 2px; }
svg {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { margin-bottom: 0; letter-spacing: -.03em; }
h2 { font-size: 1.05rem; }
code { padding: 1px 5px; border-radius: 5px; background: var(--surface-3); font-size: .85em; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-shell {
  min-height: 100svh;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
body:has(.workspace:not([hidden])) { overflow: hidden; }
.app-shell:has(.workspace:not([hidden])) { height: 100svh; min-height: 0; overflow: hidden; }

.loading-view { min-height: calc(100svh - 48px); display: grid; place-content: center; }
.loading-brand { display: flex; align-items: center; gap: 14px; }
.loading-title { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -.04em; }
.loading-subtitle { margin: 3px 0 0; color: var(--muted); font-size: .88rem; font-weight: 600; }

.brand-mark {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border-radius: 18px 18px 6px;
  background: var(--primary-strong);
  color: #fff;
  box-shadow: 0 22px 38px -22px rgb(26 36 60 / 70%);
}
:root[data-theme="dark"] .brand-mark { background: #3b5f9c; }
.brand-mark svg { width: 30px; height: 30px; }

.auth-view { min-height: calc(100svh - 48px); display: grid; place-content: center; }
.auth-card {
  width: min(92vw, 430px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: clamp(22px, 5vw, 34px);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-heading { margin-bottom: 22px; }
.auth-heading .brand-mark { margin-bottom: 18px; }
.auth-heading h1 { font-size: 2.2rem; }
.auth-heading > p:last-child { margin: 10px 0 0; color: var(--muted); }
.eyebrow { margin: 0 0 7px; color: var(--primary); font-size: .7rem; font-weight: 850; letter-spacing: .16em; text-transform: uppercase; }
.auth-tabs, .view-tabs, .panel-tabs, .document-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border-radius: 12px;
  padding: 4px;
  background: var(--surface-2);
}
.auth-tabs { margin-bottom: 20px; }
.tab-button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.tab-button.is-active { background: var(--surface); color: var(--primary-strong); box-shadow: var(--shadow-sm); }
.auth-form { display: grid; gap: 14px; }
label, legend { display: grid; gap: 6px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.form-message { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: .8rem; font-weight: 700; }
.form-message:empty { min-height: 0; margin: 0; }

.primary-button, .secondary-button, .danger-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 11px;
  padding: 0 16px;
  font-weight: 800;
  white-space: nowrap;
}
.primary-button { background: var(--primary-strong); color: #fff; }
:root[data-theme="dark"] .primary-button { background: #3b5f9c; }
.secondary-button { border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); }
.danger-button { border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); background: var(--danger-soft); color: var(--danger); }
.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--primary);
}
.icon-button.small { width: 32px; height: 32px; border-color: transparent; border-radius: 8px; background: transparent; color: var(--muted); }
.icon-button.small:hover { background: var(--surface-2); color: var(--primary); }
.icon-button.small.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-button.small svg { width: 1rem; height: 1rem; }
.icon-button.is-disabled { opacity: .3; cursor: default; pointer-events: none; }
.text-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  padding: 7px 9px;
  background: transparent;
  color: var(--primary);
  font-weight: 750;
  font-size: .86rem;
}
.text-button:hover { background: var(--primary-soft); }
.hint { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }

/* Workspace */
.workspace { display: grid; height: 100%; min-height: 0; grid-template-rows: auto auto minmax(0, 1fr); gap: 12px; }
.topbar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-mark { width: 42px; height: 42px; border-radius: 13px 13px 5px; box-shadow: none; }
.topbar-mark svg { width: 22px; height: 22px; }
.resume-picker { min-width: 0; flex: 0 1 300px; }
.resume-picker select { font-weight: 750; color: var(--text); }
.save-status { flex: 1 1 auto; min-width: 0; overflow: hidden; color: var(--muted); font-size: .78rem; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.save-status[data-state="offline"] { color: var(--danger); }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  display: grid;
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.menu-panel button { border: 0; border-radius: 8px; padding: 10px 12px; background: transparent; color: var(--text); font-weight: 650; text-align: left; }
.menu-panel button:hover { background: var(--surface-2); }
.menu-panel .danger-text { color: var(--danger); }

.view-tabs { display: none; }
.workspace-tabs { display: flex; gap: 12px; align-items: center; }
.document-tabs { width: min(100%, 340px); }
.view-tabs { flex: 1; }
.workspace-body { display: grid; min-height: 0; grid-template-columns: minmax(360px, 520px) minmax(0, 1fr); gap: 14px; }
.editor-pane, .preview-pane {
  display: grid;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  overflow: hidden;
}
.editor-pane { grid-template-rows: auto minmax(0, 1fr); }
.panel-tabs { margin: 12px 12px 0; }
.editor-scroll { overflow-y: auto; padding: 12px; overscroll-behavior: contain; }
#content-panel { display: grid; align-content: start; gap: 12px; }
.letter-editor { display: grid; gap: 12px; }
.letter-editor textarea[data-bind="coverLetter.body"] { min-height: 320px; }
.letter-options summary { cursor: pointer; color: var(--muted); font-size: .8rem; font-weight: 700; }
.letter-options[open] summary { margin-bottom: 8px; }

.card { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: var(--surface-2); }
.card.is-hidden { opacity: .6; }
.card-head { display: flex; align-items: center; gap: 6px; }
.basics-card .card-head { margin-bottom: 10px; }
.card-body { display: grid; gap: 8px; margin-top: 10px; }
.card-tools { display: flex; flex: none; gap: 2px; margin-left: auto; }
.section-title-input { min-height: 36px; border-color: transparent; background: transparent; font-weight: 800; font-size: 1rem; padding: 0 8px; }
.section-title-input:hover { border-color: var(--border); }
.collapse-toggle, .item-toggle { display: flex; align-items: center; border: 0; background: transparent; color: var(--muted); }
.collapse-toggle { width: 30px; height: 30px; justify-content: center; border-radius: 8px; flex: none; }
.collapse-toggle svg, .item-toggle > svg { transition: transform .15s ease; }
.collapse-toggle.is-open svg, .item-card.is-open .item-toggle > svg { transform: rotate(90deg); }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: grid; gap: 5px; min-width: 0; margin: 0; border: 0; padding: 0; }
.field-wide { grid-column: 1 / -1; }
fieldset.field { gap: 8px; }
.links { display: grid; gap: 8px; margin-top: 10px; }
.links:empty { display: none; }
.link-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; align-items: end; gap: 8px; }
.link-row .icon-button { margin-bottom: 5px; }
.basics-card > .text-button { margin-top: 6px; }

.items { display: grid; gap: 8px; }
.item-card { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.item-head { display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 6px; }
.item-toggle { flex: 1; min-width: 0; gap: 8px; border-radius: 8px; padding: 6px; text-align: left; }
.item-summary { display: grid; min-width: 0; }
.item-summary strong, .item-summary small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-summary strong { color: var(--text); font-size: .9rem; }
.item-summary small { color: var(--muted); font-size: .76rem; }
.item-summary small:empty { display: none; }
.item-body { padding: 4px 12px 12px; }

.add-section { display: flex; align-items: end; gap: 8px; border: 1px dashed var(--border-strong); border-radius: 14px; padding: 12px; }
.add-section .field { flex: 1; }

.design-panel { display: grid; align-content: start; gap: 18px; }
.design-panel output { color: var(--text); font-weight: 750; }
.template-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.template-option {
  display: grid;
  gap: 6px;
  justify-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
}
.template-option[aria-pressed="true"] { border-color: var(--primary); color: var(--primary-strong); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.template-thumb { position: relative; display: block; width: 100%; aspect-ratio: 0.72; border-radius: 4px; background: #fff; box-shadow: inset 0 0 0 1px #0001; overflow: hidden; }
.template-thumb i { position: absolute; display: block; border-radius: 2px; background: #c8ccd4; }
.template-thumb i:nth-child(1) { top: 12%; height: 7%; background: var(--primary); }
.template-thumb i:nth-child(2) { top: 28%; height: 4%; }
.template-thumb i:nth-child(3) { top: 40%; bottom: 10%; background: repeating-linear-gradient(#dfe2e7 0 3px, transparent 3px 8px); }
.template-thumb-classic i { left: 22%; right: 22%; }
.template-thumb-classic i:nth-child(3) { left: 12%; right: 12%; }
.template-thumb-modern i { left: 12%; right: 30%; }
.template-thumb-modern i:nth-child(3) { right: 12%; }
.template-thumb-sidebar i { left: 10%; right: 40%; }
.template-thumb-sidebar i:nth-child(3) { left: 42%; right: 10%; box-shadow: -34px 0 0 -6px #e7ebf3; }
.template-thumb-compact i { left: 10%; right: 45%; }
.template-thumb-compact i:nth-child(3) { left: 34%; right: 10%; }
.accent-options { display: flex; flex-wrap: wrap; gap: 8px; }
.accent-swatch { width: 32px; height: 32px; border: 3px solid var(--surface); border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px var(--border-strong); }
.accent-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--primary); }
.accent-custom { display: block; width: 32px; height: 32px; overflow: hidden; border-radius: 50%; box-shadow: 0 0 0 1px var(--border-strong); }
.accent-custom input { width: 48px; height: 48px; margin: -8px; border: 0; cursor: pointer; }

.preview-pane { grid-template-rows: auto minmax(0, 1fr); background: var(--surface-3); }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.page-count { font-size: .82rem; font-weight: 800; }
.page-count[data-over="true"] { color: var(--danger); }
.preview-scroll { overflow: auto; padding: 16px; }
.preview-stage { position: relative; margin: 0 auto; }
.preview { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.preview .resume-page { position: relative; box-shadow: 0 14px 40px -18px rgb(0 0 0 / 40%); }
.page-guides { position: absolute; inset: 0; pointer-events: none; }
.page-guide { position: absolute; left: -6px; right: -6px; border-top: 1.5px dashed color-mix(in srgb, var(--primary) 70%, transparent); }
.page-guide::after {
  content: attr(data-label);
  position: absolute;
  top: -10px;
  right: 10px;
  border-radius: 99px;
  padding: 1px 8px;
  background: var(--primary-strong);
  color: #fff;
  font-size: .66rem;
  font-weight: 800;
}

.sheet-backdrop { position: fixed; inset: 0; z-index: 55; background: var(--scrim); backdrop-filter: blur(4px); }
.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 60;
  width: min(100%, 520px);
  max-height: min(90svh, 850px);
  margin: auto;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 22px max(18px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: var(--surface);
  box-shadow: 0 -24px 70px -30px rgb(0 0 0 / 60%);
}
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.profile-block { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; border-radius: 16px; padding: 13px; background: var(--surface-2); }
.profile-block > span { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 14px; background: var(--primary-strong); color: #fff; font-size: 1.1rem; font-weight: 850; }
:root[data-theme="dark"] .profile-block > span { background: #3b5f9c; }
.profile-block p { margin: 0; }
#profile-name { font-weight: 800; }
#profile-email { margin-top: 3px; color: var(--muted); font-size: .78rem; }
.settings-section { display: grid; gap: 12px; margin-bottom: 20px; border-top: 1px solid var(--border); padding-top: 18px; }
.settings-section p { margin: 5px 0 0; color: var(--muted); font-size: .8rem; }
.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; border-radius: 13px; padding: 4px; background: var(--surface-2); }
.theme-options button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 750; }
.theme-options button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.account-sheet .danger-button { width: 100%; }

.dialog {
  width: min(92vw, 440px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(4px); }
.dialog form { display: grid; gap: 16px; }
.dialog h2 { font-size: 1.3rem; }
.choice { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; color: var(--muted); font-weight: 500; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { width: auto; min-height: 0; margin-top: 3px; accent-color: var(--primary); }
.choice strong { display: block; color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-body { display: grid; gap: 14px; }
.history-dialog { width: min(92vw, 520px); }
.history-list { display: grid; gap: 8px; max-height: min(60svh, 480px); margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.history-list li { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.history-list li > div { display: grid; flex: 1; min-width: 0; gap: 2px; }
.history-list strong { font-size: .9rem; }
.history-list small { overflow: hidden; color: var(--muted); font-size: .76rem; text-overflow: ellipsis; }
.history-empty { color: var(--muted); font-size: .86rem; }

.app-message {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 80;
  display: flex;
  width: min(92vw, 520px);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transform: translateX(-50%);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 10px 10px 10px 14px;
  background: var(--surface);
  color: var(--text);
  font-size: .84rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.app-message #app-message-text { flex: 1; }
.app-message .text-button { flex: none; }
.app-message #dismiss-app-message { width: 32px; height: 32px; flex: none; border: 0; border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: 1.2rem; }
.app-update-button {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 58px));
  left: 50%;
  z-index: 90;
  min-height: 44px;
  transform: translateX(-50%);
  border: 0;
  border-radius: 99px;
  padding: 0 18px;
  background: var(--primary-strong);
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.print-root { display: none; }

@media (max-width: 979px) {
  .view-tabs { display: grid; }
  .workspace-tabs { display: grid; gap: 8px; }
  .document-tabs { width: 100%; }
  .workspace-body { grid-template-columns: minmax(0, 1fr); }
  .workspace-body[data-view="edit"] .preview-pane, .workspace-body[data-view="preview"] .editor-pane { display: none; }
  .preview-toolbar .hint { display: none; }
}

@media (max-width: 560px), (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 560px) {
  .app-shell { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .topbar { flex-wrap: wrap; }
  .topbar-mark { display: none; }
  .resume-picker { flex: 1 1 100%; order: 2; }
  #new-resume-button span { display: none; }
  #new-resume-button { width: 42px; padding: 0; }
  .field-grid { grid-template-columns: minmax(0, 1fr); }
  .template-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .link-row { grid-template-columns: minmax(0, 1fr) auto; }
  .link-row .field:first-child { grid-column: 1 / -1; }
}

@media (min-width: 980px) {
  .sheet { top: 50%; bottom: auto; border-radius: 24px; transform: translateY(-50%); }
}

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

@media print {
  html, body { background: #fff !important; overflow: visible !important; }
  body { min-height: 0; }
  .app-shell, .app-update-button { display: none !important; }
  .print-root { display: block; }
}
