/* Application UI (not the CV itself — see cv.css). */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dde1e7;
  --text: #1c2330;
  --muted: #5c6675;
  --primary: #1f4e79;
  --primary-ink: #ffffff;
  --primary-soft: #e6eef6;
  --danger: #b42318;
  --focus: #2f6fb3;
  --preview-bg: #e3e6eb;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-2: #22272f;
    --border: #333a45;
    --text: #e7eaef;
    --muted: #9aa4b2;
    --primary: #6aa6dc;
    --primary-ink: #0d1520;
    --primary-soft: #1f2d3c;
    --danger: #f97066;
    --focus: #8cbcf0;
    --preview-bg: #0f1216;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.noscript { padding: 16px; }
code { font-size: 0.92em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; min-height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.divider { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }

/* Chooser */
.chooser { max-width: 1200px; margin: 0 auto; padding: 32px 16px 64px; }
.chooser-intro { max-width: 640px; margin-bottom: 24px; }
.chooser-intro h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; }
.chooser-intro p { margin: 0 0 12px; color: var(--muted); }
.support-note { margin: 40px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.support-note a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.support-note a:hover { color: var(--text); }
@media print { .support-note { display: none; } }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.tpl-card {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tpl-card:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgb(0 0 0 / 0.08); }
.tpl-card.current { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.tpl-thumb {
  height: 300px; overflow: hidden; border-radius: 6px;
  background: var(--preview-bg); display: flex; justify-content: center; padding-top: 10px;
  pointer-events: none;
}
.tpl-thumb .cv-page { zoom: 0.33; box-shadow: 0 2px 8px rgb(0 0 0 / 0.2); flex: none; }
.tpl-name { font-weight: 700; font-size: 16px; margin-top: 4px; }
.tpl-desc { font-size: 13.5px; color: var(--muted); }
.tpl-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--text); }

/* Editor layout */
.editor {
  display: grid; grid-template-columns: minmax(340px, 460px) 1fr;
  height: calc(100vh - 57px);
}
.form-pane { overflow-y: auto; padding: 16px; border-right: 1px solid var(--border); background: var(--bg); }
.preview-pane { overflow: auto; background: var(--preview-bg); display: flex; flex-direction: column; min-width: 0; }
.preview-meta {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px; font-size: 13px; color: var(--muted);
}
.preview-host { flex: 1; padding: 0 16px 32px; display: flex; justify-content: center; align-items: flex-start; min-width: 0; }
.preview-host .cv-page {
  box-shadow: 0 2px 12px rgb(0 0 0 / 0.18);
  /* approximate page-break guides */
  background-image: repeating-linear-gradient(to bottom,
    transparent 0, transparent calc(var(--page-h) - 1px),
    #9aa5b1 calc(var(--page-h) - 1px), #9aa5b1 var(--page-h));
}

/* Form cards */
.tip { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 12px;
}
.card > summary {
  display: flex; align-items: baseline; gap: 8px; padding: 12px 14px;
  cursor: pointer; list-style: none; user-select: none;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; display: inline-block; }
.card[open] > summary::before { transform: rotate(90deg); }
.card-title { font-weight: 600; font-size: 15px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.card-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.add-section { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.add-section .btn { align-self: flex-start; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 500; }
.field-hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.field input[type="text"], .field input[type="email"], .field input[type="tel"], .field textarea, .field select, .add-section input {
  width: 100%; padding: 7px 10px; font: inherit; font-size: 14px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px;
}
.field textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
.field input[type="color"] { width: 64px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.links { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.link-row { display: flex; align-items: flex-end; gap: 6px; width: 100%; }
.link-row .field { flex: 1; }
.photo-box { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.photo-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.photo-actions { display: flex; gap: 6px; }
.photo-box .field-hint { flex-basis: 100%; }

.section-tools, .item-tools { display: flex; gap: 4px; flex-wrap: wrap; }
.items { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.items > .btn { align-self: flex-start; }
.item { border: 1px solid var(--border); border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.item .field input, .item .field textarea { background: var(--surface); }
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-title { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Dialog + toast */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; max-width: min(480px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-body { padding: 20px 22px; }
.dialog-body h2 { margin: 0 0 8px; font-size: 19px; }
.dialog-body ol { padding-left: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Small screens: stack form above preview */
@media (max-width: 900px) {
  .editor { display: block; height: auto; }
  .form-pane { border-right: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  .preview-pane { overflow: visible; }
  .topbar { position: static; }
  .divider { display: none; }
}
@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
}

/* ---- Print: only the CV page ---- */
@media print {
  body { background: #fff; }
  .topbar, .form-pane, .preview-meta, .toast, dialog, #view-chooser { display: none !important; }
  .editor, .preview-pane, .preview-host { display: block !important; height: auto !important; overflow: visible !important; padding: 0 !important; background: none !important; }
  .preview-host .cv-page {
    zoom: 1 !important; width: auto !important; min-height: 0 !important;
    padding: 0 !important; box-shadow: none !important; background-image: none !important;
  }
}
