/* ===================================
   ResumeForge app UI. Resume template styles live in resume.css.
   =================================== */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --surface-3: #e9e6df;
  --border: #e3e0d8;
  --border-strong: #d2cec4;
  --text: #1c1b19;
  --text-2: #57544e;
  --text-3: #8b877f;
  --accent: #3552d6;
  --accent-hover: #2a44ba;
  --accent-soft: #e9edfc;
  --accent-text: #2a44ba;
  --on-accent: #ffffff;
  --success: #1f8a4c;
  --success-soft: #e5f4ea;
  --warn: #a8620a;
  --warn-soft: #fbf0dc;
  --danger: #c53b3b;
  --danger-soft: #fbe9e8;
  --preview-bg: #e7e4dc;
  --shadow-sm: 0 1px 2px rgba(28, 27, 25, 0.06);
  --shadow-md: 0 2px 6px rgba(28, 27, 25, 0.06), 0 8px 24px rgba(28, 27, 25, 0.08);
  --shadow-lg: 0 12px 48px rgba(28, 27, 25, 0.18);
  --paper-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 10px 40px rgba(0, 0, 0, 0.10);
  --focus: 0 0 0 3px rgba(53, 82, 214, 0.28);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --topbar-h: 56px;
  --tabbar-h: 60px;
  --editor-w: 480px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1b1b1f;
    --surface-2: #232328;
    --surface-3: #2c2c32;
    --border: #2e2e35;
    --border-strong: #3c3c44;
    --text: #ecebe8;
    --text-2: #b0aea8;
    --text-3: #7d7b76;
    --accent: #6d86f5;
    --accent-hover: #8297f7;
    --accent-soft: rgba(109, 134, 245, 0.16);
    --accent-text: #9aabf8;
    --on-accent: #0e1330;
    --success: #4cc27f;
    --success-soft: rgba(76, 194, 127, 0.14);
    --warn: #e5a54a;
    --warn-soft: rgba(229, 165, 74, 0.14);
    --danger: #f07171;
    --danger-soft: rgba(240, 113, 113, 0.14);
    --preview-bg: #0e0e10;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
    --paper-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 16px 48px rgba(0, 0, 0, 0.4);
    --focus: 0 0 0 3px rgba(109, 134, 245, 0.35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100dvh;
  overflow: hidden;
}

[hidden] { display: none !important; }

input, textarea, select, button { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: none; box-shadow: var(--focus); }

svg { width: 16px; height: 16px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }

/* ===================================
   Buttons
   =================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  transition: background 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), transform 80ms;
  border: 1px solid transparent;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 44px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; }

.btn.loading, .tab.loading { position: relative; color: transparent !important; }
.btn.loading::after, .tab.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: var(--on-accent) var(--on-accent) transparent transparent;
  animation: spin 700ms linear infinite;
}
.tab.loading::after { border-color: var(--accent) var(--accent) transparent transparent; top: 20px; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  transition: background 150ms, color 150ms;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }

.link-btn {
  color: var(--accent-text);
  font-weight: 600;
  padding: 0;
  text-align: left;
}
.link-btn:hover { text-decoration: underline; }

/* ===================================
   Forms
   =================================== */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field, .field-row + .field, .field + .field-row, .field-row + .field-row,
.switch + .field, .field-row + .switch { margin-top: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.field-row > .field { margin-top: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.optional { font-weight: 500; color: var(--text-3); margin-left: 4px; }
.field-hint { font-size: 12px; color: var(--text-3); }

.input {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 150ms, box-shadow 150ms;
}
.input::placeholder { color: var(--text-3); opacity: 0.8; }
.input:hover:not(:disabled) { border-color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input:disabled { background: var(--surface-2); color: var(--text-3); }
textarea.input { resize: vertical; line-height: 1.55; min-height: 80px; }
input[type="month"].input { min-width: 0; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; color: var(--text-2); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background 150ms;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 180ms var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }

.form-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

/* ===================================
   Auth
   =================================== */
.auth {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(380px, 520px) 1fr;
  overflow: auto;
}
.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 48px clamp(24px, 6vw, 72px);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-mark { width: 28px; height: 28px; color: var(--accent); }
.auth-copy h1 { font-size: 28px; letter-spacing: -0.02em; line-height: 1.2; }
.auth-copy p { margin-top: 6px; color: var(--text-2); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .field + .field { margin-top: 0; }
.auth-form .btn { margin-top: 6px; }
.auth-switch { color: var(--text-2); font-size: 13.5px; }

.auth-showcase {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 48px;
  background: radial-gradient(1200px 600px at 70% 10%, var(--accent-soft), transparent 60%), var(--bg);
  overflow: hidden;
}
.showcase-copy { max-width: 460px; }
.showcase-copy h2 { font-size: 22px; line-height: 1.3; letter-spacing: -0.015em; }
.showcase-points { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; color: var(--text-2); font-size: 13.5px; }
.showcase-points li { display: flex; align-items: center; gap: 6px; }
.showcase-points svg { color: var(--success); }
.showcase-page { width: 408px; height: 420px; overflow: hidden; border-radius: 6px 6px 0 0; box-shadow: var(--paper-shadow); }
.showcase-paper { width: 816px; background: #fff; transform: scale(0.5); transform-origin: top left; pointer-events: none; }

/* ===================================
   App shell
   =================================== */
.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  flex-shrink: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-left .brand-mark { margin-right: 4px; }

.doc-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  max-width: 280px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-weight: 650;
  font-size: 14.5px;
  transition: background 150ms;
}
.doc-switcher:hover, .doc-switcher[aria-expanded="true"] { background: var(--surface-2); }
.doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-switcher svg { color: var(--text-3); }

.save-status { font-size: 12.5px; color: var(--text-3); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.save-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0; }
.save-status[data-kind="saved"]::before { opacity: 1; background: var(--success); }
.save-status[data-kind="saving"]::before, .save-status[data-kind="dirty"]::before { opacity: 1; background: var(--text-3); }
.save-status[data-kind="error"] { color: var(--danger); }
.save-status[data-kind="error"]::before { opacity: 1; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 14px;
  margin-left: 4px;
}
.avatar:hover { filter: brightness(0.97); }

/* Menus */
.menu-anchor { position: relative; min-width: 0; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  max-width: min(340px, calc(100vw - 24px));
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  animation: pop 140ms var(--ease);
}
.menu-right { left: auto; right: 0; min-width: 220px; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
.menu-label { padding: 6px 10px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.menu-list { max-height: 280px; overflow-y: auto; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
}
.menu-item:hover:not(:disabled) { background: var(--surface-2); }
.menu-item svg { color: var(--text-3); }
.menu-item:disabled { opacity: 0.45; }
.menu-item-danger { color: var(--danger); }
.menu-item-danger svg { color: currentColor; }
.menu-item-danger:hover:not(:disabled) { background: var(--danger-soft); }
.menu-doc-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.menu-doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-doc-meta { font-size: 12px; color: var(--text-3); }
.menu-doc.current { background: var(--accent-soft); }
.menu-check { color: var(--accent-text) !important; }
.menu-account { padding: 8px 10px; font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }

/* ===================================
   Workspace
   =================================== */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--editor-w) 1fr;
}

/* Editor column */
.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
}
.editor-top {
  flex-shrink: 0;
  padding: 14px 20px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.progress { padding: 2px 2px 12px; }
.progress-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; }
.progress-label { color: var(--text-2); font-weight: 600; }
.progress-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.progress-track { height: 6px; margin-top: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 400ms var(--ease), background 300ms; }
.progress-fill.complete { background: var(--success); }
.progress-tip { margin-top: 8px; font-size: 12.5px; color: var(--text-2); min-height: 18px; }

.steps {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -20px;
  padding: 0 14px;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 28px), transparent 100%);
}
.steps::-webkit-scrollbar { display: none; }
.step {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding: 10px 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color 150ms;
}
.step:hover { color: var(--text); }
.step.active { color: var(--text); }
.step.active::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--text-2);
}
.step-dot svg { width: 12px; height: 12px; }
.step.active .step-dot { background: var(--accent); color: var(--on-accent); }
.step.done .step-dot { background: var(--success-soft); color: var(--success); }
.step.done.active .step-dot { background: var(--success); color: #fff; }

.editor-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.panel { padding: 22px 20px 32px; animation: fadeUp 220ms var(--ease); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-head { display: flex; gap: 14px; margin-bottom: 18px; }
.panel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.panel-icon svg { width: 18px; height: 18px; }
.panel-head h2 { font-size: 18px; letter-spacing: -0.01em; }
.panel-head p { margin-top: 2px; color: var(--text-2); font-size: 13.5px; }

.card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px dashed var(--border-strong);
}

/* Entry cards */
.entries { display: flex; flex-direction: column; gap: 10px; }
.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms, box-shadow 150ms;
}
.entry-card.open { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.entry-head { display: flex; align-items: center; gap: 4px; padding: 6px 8px 6px 6px; }
.entry-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.entry-toggle:hover { background: var(--surface-2); }
.entry-chevron { color: var(--text-3); transition: transform 180ms var(--ease); }
.entry-card.open .entry-chevron { transform: rotate(90deg); }
.entry-text { display: flex; flex-direction: column; min-width: 0; }
.entry-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub:empty { display: none; }
.entry-actions { display: flex; gap: 2px; opacity: 0.85; }
.entry-body:empty { display: none; }
.entry-body { padding: 6px 18px 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.entry-body > .switch { margin-top: 14px; }

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--accent-text);
  font-weight: 600;
  transition: background 150ms, border-color 150ms;
}
.add-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.empty-note { padding: 18px; text-align: center; color: var(--text-3); font-size: 13.5px; }

/* Skills tags */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  margin-bottom: 8px;
  padding: 8px;
  min-height: 48px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: text;
  transition: border-color 150ms, box-shadow 150ms;
}
.tags:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding: 0 4px 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
  animation: pop 140ms var(--ease);
}
.tag button { display: inline-flex; padding: 4px; border-radius: 50%; color: inherit; opacity: 0.7; }
.tag button:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }
.tag button svg { width: 12px; height: 12px; }
.tag-input { flex: 1; min-width: 140px; height: 30px; border: none; background: transparent; padding: 0 6px; font-size: 14px; }
.tag-input:focus { outline: none; box-shadow: none; }
.tag-input::placeholder { color: var(--text-3); }

/* ===================================
   Preview
   =================================== */
.preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--preview-bg); }
.preview-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
}
.page-status { font-size: 12.5px; font-weight: 600; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; }
.page-status:empty { visibility: hidden; }
.page-status.ok { background: var(--success-soft); color: var(--success); }
.page-status.warn { background: var(--warn-soft); color: var(--warn); }
.zoom { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow-sm); margin-left: auto; }
.zoom .icon-btn { width: 28px; height: 28px; }
.zoom-value { min-width: 52px; height: 28px; font-size: 12.5px; font-weight: 600; color: var(--text-2); border-radius: 4px; font-variant-numeric: tabular-nums; }
.zoom-value:hover { background: var(--surface-2); }
.zoom-value.active { color: var(--accent-text); }

.preview-scroll { flex: 1; min-height: 0; overflow: auto; padding: 8px 32px 48px; }
.page-frame { position: relative; margin: 0 auto; }
.paper {
  position: absolute;
  top: 0;
  left: 0;
  width: 816px;
  background: #fff;
  color: #222;
  box-shadow: var(--paper-shadow);
  transform-origin: top left;
  overflow: hidden;
}
.paper .section[data-section], .paper h1, .paper .resume-title, .paper .contact-row { cursor: pointer; }
.paper .section[data-section]:hover { outline: 2px dashed rgba(53, 82, 214, 0.35); outline-offset: 6px; border-radius: 2px; }
.page-break {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed #c9a25a;
  pointer-events: none;
}
.page-break::after {
  content: attr(data-label);
  position: absolute;
  right: 12px;
  top: 4px;
  font: 600 12px var(--font);
  color: #9a7432;
  background: #fff8e8;
  padding: 2px 8px;
  border-radius: 999px;
}
.paper-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 1056px;
  color: #9a968e;
  font: 500 22px var(--font);
  text-align: center;
  padding: 80px;
}
.paper-empty svg { width: 64px; height: 64px; opacity: 0.6; }

/* ===================================
   Templates drawer
   =================================== */
.drawer-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(15, 15, 20, 0.35); animation: fade 160ms; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  width: min(440px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 260ms var(--ease), visibility 0s 260ms;
}
.drawer.open { transform: none; visibility: visible; transition: transform 260ms var(--ease); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 20px 14px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 17px; }
.drawer-head p { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.template-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 20px; align-content: start; }
.template-card { display: flex; flex-direction: column; gap: 10px; text-align: left; padding: 8px; border-radius: var(--radius); border: 2px solid transparent; transition: border-color 150ms, background 150ms; }
.template-card:hover { background: var(--surface-2); }
.template-card.active { border-color: var(--accent); background: var(--accent-soft); }
.template-thumb { display: block; position: relative; width: 100%; aspect-ratio: 816 / 1056; overflow: hidden; border-radius: 4px; background: #fff; box-shadow: 0 0 0 1px var(--border), var(--shadow-sm); }
.template-paper { position: absolute; top: 0; left: 0; width: 816px; transform: scale(var(--thumb-scale, 0.21)); transform-origin: top left; pointer-events: none; background: #fff; }
.template-meta { display: flex; flex-direction: column; padding: 0 2px; }
.template-name { display: flex; align-items: center; gap: 6px; font-weight: 650; }
.template-check { color: var(--accent-text); width: 14px; height: 14px; }
.template-blurb { font-size: 12px; color: var(--text-3); }

/* ===================================
   Modal
   =================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 15, 20, 0.45);
  animation: fade 140ms;
}
.modal {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop 160ms var(--ease);
}
.modal h3 { font-size: 17px; letter-spacing: -0.01em; }
.modal-body { margin-top: 16px; }
.modal-note { color: var(--text-2); font-size: 13.5px; margin-top: 10px; }
.modal-body > .modal-note:first-child { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.choice-group { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
}
.choice:hover { background: var(--surface-2); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice span { display: flex; flex-direction: column; }
.choice strong { font-size: 13.5px; font-weight: 600; }
.choice small { font-size: 12.5px; color: var(--text-3); }

/* ===================================
   Toasts
   =================================== */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px 10px 16px;
  border-radius: var(--radius);
  background: #1f1f24;
  color: #f3f2ef;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 200ms var(--ease);
}
.toast-error { background: #7d2222; }
.toast button { color: #a9b8ff; font-weight: 700; padding: 4px 6px; border-radius: 4px; }
.toast button:hover { background: rgba(255, 255, 255, 0.1); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 180ms, transform 180ms; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ===================================
   Mobile tab bar
   =================================== */
.tabbar { display: none; }
.show-mobile { display: none; }

/* ===================================
   Responsive
   =================================== */
@media (max-width: 1180px) {
  :root { --editor-w: 420px; }
}

@media (max-width: 1000px) {
  .auth { grid-template-columns: 1fr; }
  .auth-showcase { display: none; }
  .auth-panel { border-right: none; max-width: 480px; margin: 0 auto; width: 100%; background: transparent; }
}

@media (max-width: 899px) {
  :root { --topbar-h: 52px; }
  .hide-mobile { display: none !important; }
  .show-mobile { display: inline-flex; }
  .topbar { padding: 0 8px 0 12px; }
  .topbar-left .brand-mark { display: none; }
  .doc-switcher { max-width: 52vw; padding: 0 8px; }
  .save-status { font-size: 0; gap: 0; }
  .save-status::before { width: 8px; height: 8px; }

  .workspace { grid-template-columns: 1fr; }
  .workspace[data-view="edit"] .preview { display: none; }
  .workspace[data-view="preview"] .editor { display: none; }
  .editor { border-right: none; }
  .editor-top { padding: 12px 16px 0; }
  .steps { margin: 0 -16px; padding: 0 10px; }
  .panel { padding: 18px 16px 28px; }
  .card { padding: 14px; }
  .entry-body { padding: 14px 14px 16px; }
  .preview-scroll { padding: 4px 12px 32px; }
  .preview-toolbar { padding: 8px 12px; }
  .zoom { margin-left: 0; }
  .input { font-size: 16px; } /* prevent iOS zoom on focus */
  .tag-input { font-size: 16px; }

  .tabbar {
    display: flex;
    flex-shrink: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tab {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-3);
  }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { color: var(--accent-text); }
  #downloadBtnMobile { color: var(--accent-text); }

  .toasts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
  .drawer { width: 100vw; }
  .template-grid { gap: 12px; padding: 16px; }
  .menu { position: fixed; top: calc(var(--topbar-h) + 4px); left: 8px; right: 8px; max-width: none; min-width: 0; }
  .menu-right { left: auto; width: 240px; }
}

@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; gap: 14px; }
  .step-label { display: none; }
  .step.active .step-label { display: inline; }
  .step { padding: 10px 6px 12px; }
  .panel-head { gap: 12px; }
  .panel-icon { width: 34px; height: 34px; }
  .panel-nav .btn { flex: 1; }
  .entry-actions .icon-btn { width: 30px; }
}

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

/* ===================================
   Print (browser Ctrl+P). The Download PDF button uses the server renderer.
   =================================== */
.print-only { display: none; }

@media print {
  @page { margin: 0; size: letter; }
  body { height: auto; overflow: visible; background: #fff !important; }
  .auth, .app, .drawer, .drawer-backdrop, .modal-backdrop, .toasts { display: none !important; }
  .print-only { display: block !important; }
  .print-only * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .print-only .entry { break-inside: avoid; }
}
