/* Civetta: mobile first, no framework. --accent follows the colour picked for the CV. */

:root {
    --accent: #00a889;
    --band: #0b161c;
    --ink: #121416;
    --muted: #5b6770;
    --line: #dfe5e3;
    --bg: #f4f6f5;
    --card: #ffffff;
    --danger: #c0392b;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(11, 22, 28, .06), 0 4px 16px rgba(11, 22, 28, .05);
    color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }

svg { fill: currentColor; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--band);
    color: #fff;
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { background: #fff; border-radius: 10px; padding: 2px; }
.brand-name { font-weight: 700; font-size: 1.2rem; letter-spacing: .01em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.save-state { font-size: .8rem; color: #93a6b0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state.save-failed { color: #ffb4a8; white-space: normal; }
.lang-switch {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: .85rem;
    border: 1px solid rgba(255, 255, 255, .3);
    border-radius: 8px;
    padding: 4px 9px;
}
.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .3); background: transparent; }

/* ---------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 20px; height: 20px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .5; cursor: default; filter: none; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-link { background: none; color: var(--accent); padding-left: 4px; padding-right: 4px; text-decoration: underline; text-underline-offset: 3px; }
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible, .swatch:focus-visible, .ink:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
    outline-offset: 2px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.icon-btn-danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ------------------------------------------------------------------ upload */

.view { padding: 24px 16px 40px; }

.view-upload { max-width: 640px; margin: 0 auto; }
.hero { text-align: center; margin: 12px 0 24px; }
.eyebrow { color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; margin: 0 0 8px; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 0; }

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 32px 16px;
    border: 2px dashed color-mix(in srgb, var(--accent) 55%, var(--line));
    border-radius: var(--radius);
    background: var(--card);
    text-align: center;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.dropzone.is-over { background: color-mix(in srgb, var(--accent) 8%, #fff); border-color: var(--accent); }
.dropzone-icon { width: 44px; height: 44px; color: var(--accent); }
.dropzone-title { font-weight: 600; font-size: 1.1rem; }
.dropzone-formats { color: var(--muted); font-size: .85rem; }

.hint { color: var(--muted); font-size: .92rem; }
.view-upload > .hint { text-align: center; margin: 16px 0; }

.upload-alt { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 8px 0 24px; }

.privacy-note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: .85rem;
    color: var(--muted);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.privacy-note svg { flex: 0 0 18px; width: 18px; height: 18px; color: var(--accent); margin-top: 2px; }

.alert { border-radius: 10px; padding: 12px 14px; margin: 16px 0; font-size: .95rem; }
.alert-error { background: #fdecea; color: #8a1f12; border: 1px solid #f5c2bb; }

/* ----------------------------------------------------------------- reading */

.view-reading { text-align: center; padding-top: 18vh; }
.reading-owl { animation: owl-blink 1.6s ease-in-out infinite; }
@keyframes owl-blink {
    0%, 100% { transform: translateY(0) rotate(0); }
    25% { transform: translateY(-6px) rotate(-6deg); }
    75% { transform: translateY(-6px) rotate(6deg); }
}
@media (prefers-reduced-motion: reduce) { .reading-owl { animation: none; } }

/* ------------------------------------------------------------------ editor */

.view-editor { padding: 16px 16px 110px; }
.editor-layout { max-width: 1320px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.editor-head { margin: 4px 0 16px; }
.editor-head .hint { margin: 0; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
.card-title { font-size: 1.05rem; margin-bottom: 12px; }

.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label, .label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field-help { font-size: .82rem; color: var(--muted); margin: 0 0 4px; }

.input {
    width: 100%;
    font: inherit;
    font-size: 16px; /* 16px: iOS does not zoom into the field */
    color: var(--ink);
    background: #fbfcfc;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 10px 12px;
    min-height: 44px;
}
.input:focus { border-color: var(--accent); background: #fff; outline: none; }
textarea.input { resize: vertical; line-height: 1.45; }

.photo-row { flex-direction: row; align-items: center; gap: 14px; }
.photo-preview {
    width: 84px;
    height: 84px;
    flex: 0 0 84px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--accent);
    background: #eef2f1;
}
.photo-empty { display: grid; place-items: center; color: #b9c4c9; }
.photo-empty svg { width: 46px; height: 46px; }
.photo-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.photo-actions .field-help { flex-basis: 100%; margin: 0; }

.card-section { border-left: 4px solid var(--accent); }
.section-head { display: flex; align-items: center; gap: 8px; }
.section-title-input {
    flex: 1;
    min-width: 0;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px 8px;
    margin-left: -8px;
    background: transparent;
}
.section-title-input::placeholder { color: var(--ink); opacity: 1; }
.section-title-input:hover { border-color: var(--line); }
.section-title-input:focus { border-color: var(--accent); outline: none; background: #fff; }
.section-tools { display: flex; gap: 6px; }
.section-col { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.section-empty { margin-top: 8px; font-style: italic; }

.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: #fcfdfd; }
.item-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.item-num {
    margin-right: auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: .8rem;
    font-weight: 700;
    color: #fff;
    background: var(--accent);
}
.btn-add { width: 100%; border-style: dashed; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.swatch {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 0 0 1px var(--line);
    background: var(--swatch);
    cursor: pointer;
    padding: 0;
}
.swatch.is-on { box-shadow: 0 0 0 3px var(--swatch); }
.swatch-custom {
    background: conic-gradient(#e74c3c, #f1c40f, #2ecc71, #3498db, #9b59b6, #e74c3c);
    display: inline-block;
}
.swatch-custom.is-on { background: var(--swatch); }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }

.card .field + .field { margin-top: 12px; }

/* --------------------------------------------------------------- signature */

.sig-pad-wrap {
    position: relative;
    margin: 8px 0 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    background-image: radial-gradient(#e7ecea 1px, transparent 1px);
    background-size: 14px 14px;
}
.sig-pad { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; border-radius: 12px; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 36px; border-bottom: 1px dashed #b9c4c9; pointer-events: none; }
.sig-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ink-group { display: inline-flex; align-items: center; gap: 6px; margin-right: auto; }
.ink {
    font: inherit;
    font-size: .85rem;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 999px;
    padding: 5px 12px 5px 26px;
    position: relative;
    cursor: pointer;
    min-height: 36px;
}
.ink::before {
    content: "";
    position: absolute;
    left: 9px;
    top: 50%;
    width: 11px;
    height: 11px;
    margin-top: -5.5px;
    border-radius: 50%;
    background: var(--ink);
}
.ink.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sig-current {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.sig-current img { max-height: 64px; max-width: 220px; object-fit: contain; }

/* ---------------------------------------------------------------- preview */

.preview-col { display: none; min-width: 0; }
.preview-sticky { position: sticky; top: 76px; padding: 2px; }
.preview-scale { position: relative; width: 100%; overflow: hidden; border-radius: 6px; box-shadow: 0 10px 40px rgba(11, 22, 28, .18); }
.preview-note { text-align: center; font-size: .8rem; }

/* The preview mirrors src/pdf.php at A4 width (794px) and is scaled down to fit. */
.cvp {
    --accent: #00a889;
    width: 794px;
    min-height: 1123px;
    transform-origin: top left;
    display: flex;
    background: #fff;
    font-family: "DejaVu Sans", Verdana, sans-serif;
    font-size: 12.2px;
    line-height: 1.42;
    color: #121416;
}
.cvp {
    --cvp-band: #0b161c;
    --cvp-band-fg: #e8eef2;
    --cvp-band-muted: #93a6b0;
    --cvp-band-strong: #ffffff;
}
.cvp-side { width: 257px; flex: 0 0 257px; background: var(--cvp-band); color: var(--cvp-band-fg); padding: 42px 26px; font-size: 10.9px; }
.cvp-photo { display: block; width: 151px; height: 151px; border-radius: 50%; object-fit: cover; margin: 0 auto 18px; box-shadow: 0 0 0 3px var(--accent); }
.cvp-side-name { color: var(--cvp-band-strong); font-weight: bold; font-size: 20.6px; text-align: center; line-height: 1.3; }
.cvp-side-role { color: var(--cvp-band-muted); text-align: center; margin-top: 4px; }
.cvp-side-h {
    color: var(--cvp-band-strong);
    font-weight: bold;
    font-size: 12.2px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 4px;
    margin: 22px 0 10px;
}
.cvp-side-row { position: relative; padding-left: 15px; margin-bottom: 4px; overflow-wrap: anywhere; }
.cvp-side-row::before { content: ""; position: absolute; left: 0; top: 4px; width: 7px; height: 7px; background: var(--accent); }
.cvp-side-p { margin: 0 0 8px; }
.cvp-main { flex: 1; padding: 42px 38px 38px 34px; min-width: 0; }
.cvp-name { font-size: 25px; font-weight: bold; }
.cvp-role { color: var(--accent); font-weight: bold; font-size: 13.3px; margin: 4px 0 22px; }
.cvp-main-h {
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 5px;
    margin: 22px 0 18px;
}
.cvp-timeline { border-left: 2px solid #e2e8e6; margin-left: 7px; }
.cvp-entry { position: relative; padding: 0 0 15px 24px; }
.cvp-dot { position: absolute; left: -9px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.cvp-entry-title { font-weight: bold; font-size: 13.3px; }
.cvp-entry-org { color: #4d5960; font-size: 11.7px; }
.cvp-entry-date { color: var(--accent); font-weight: bold; font-size: 10.7px; margin-top: 2px; }
.cvp-bullet { position: relative; color: #4d5960; font-size: 11.6px; margin-top: 5px; padding-left: 15px; text-align: justify; }
.cvp-bullet::before { content: ""; position: absolute; left: 0; top: 5px; width: 6px; height: 6px; background: var(--accent); }
.cvp-privacy { margin-top: 22px; padding-top: 11px; border-top: 1px solid #e2e8e6; font-size: 9.6px; color: #97a0ad; font-style: italic; text-align: justify; }
.cvp-sign { text-align: right; margin-top: 14px; }
.cvp-sign img { height: 60px; }

/* -------------------------------------------------------------- action bar */

.actionbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
}
.btn-download { flex: 1; max-width: 420px; }

/* Phone/tablet: the preview replaces the editor on demand. */
body.show-preview .editor-col { display: none; }
body.show-preview .preview-col { display: block; }

@media (min-width: 1100px) {
    .editor-layout { grid-template-columns: minmax(0, 1fr) minmax(380px, 520px); }
    .preview-col, body.show-preview .preview-col { display: block; }
    .preview-sticky { max-height: calc(100vh - 160px); overflow-y: auto; }
    body.show-preview .editor-col { display: block; }
    .btn-preview-toggle { display: none; }
    .actionbar { justify-content: flex-end; padding-right: max(16px, calc((100vw - 1320px) / 2 + 16px)); }
}

/* ------------------------------------------------------------------ footer */

.footer { padding: 24px 16px; text-align: center; font-size: .8rem; color: var(--muted); }
.footer p { margin: 4px 0; }
body.is-editor .footer { padding-bottom: 100px; }

/* Narrow phones: the "saved" note gives way to the buttons (errors still show). */
@media (max-width: 479px) {
    .save-state:not(.save-failed) { display: none; }
}
.topbar .btn { white-space: nowrap; }

/* ------------------------------------------------- consent, Turnstile, legal */

.consent { text-align: center; font-size: .82rem; color: var(--muted); margin: 10px 0 0; }
.consent a, .privacy-note a, .footer a { color: var(--accent); }
.turnstile { display: flex; justify-content: center; margin-top: 14px; min-height: 65px; }

.legal { max-width: 780px; margin: 0 auto; padding: 24px 16px 40px; }
.legal-card { padding: 24px 20px; }
.legal-card h1 { font-size: clamp(1.5rem, 4.5vw, 2rem); }
.legal-card h2 { margin-top: 1.6rem; }
.legal-card p, .legal-card li { color: #2c3439; }
.legal-card li { margin-bottom: .4rem; }
.legal-card a { color: var(--accent); }
.legal-card code { background: #eef2f1; border-radius: 4px; padding: 1px 5px; font-size: .9em; }
.legal-updated { margin-top: 2rem; font-size: .85rem; color: var(--muted); }
.legal-back { text-align: center; }

.stats-month { display: flex; align-items: center; gap: 10px; margin: 8px 0 16px; }
.stats-month .input { width: auto; }
.stats-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stats-tiles div { background: #f4f6f5; border-radius: 10px; padding: 10px 12px; }
.stats-tiles span { display: block; font-size: .8rem; color: var(--muted); }
.stats-tiles strong { font-size: 1.25rem; }
.stats-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.stats-table th, .stats-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.stats-table th { color: var(--muted); font-weight: 600; }

/* ------------------------------------------------ 0.2.1: columns, details */

.col-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin: 2px 0 12px; background: #f4f6f5; }
.col-opt {
    font: inherit;
    font-size: .82rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 6px 12px;
    min-height: 32px;
    cursor: pointer;
}
.col-opt.is-on { background: var(--accent); color: #fff; font-weight: 600; }

.pair-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 8px; margin-bottom: 10px; align-items: center; }
.pair-tools { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; }
@media (min-width: 640px) {
    .pair-row { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; }
    .pair-tools { grid-column: auto; }
}

.cvp-legal { color: #4d5960; font-size: 12px; margin-top: 2px; }
.cvp-p { margin: 0 0 8px; text-align: justify; }
.cvp-pair { margin-bottom: 4px; }
.cvp-side-entry { margin-bottom: 12px; }
.cvp-side-entry .cvp-entry-title { color: var(--cvp-band-strong); font-size: 11.5px; }
.cvp-side-entry .cvp-entry-org { color: var(--cvp-band-muted); font-size: 10.7px; }
.cvp-side-entry .cvp-entry-date { font-size: 10px; margin-bottom: 4px; }
.cvp-side-row b { color: var(--cvp-band-strong); }
