/* ════════════════════════════════════════════════════════
   CV Forge - Live CV Builder
   App chrome (toolbar, editor panel, preview) + CV document
   ════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }

:root {
    --app-bg:      #161513;
    --panel-bg:    #1e1c19;
    --panel-bg-2:  #26231e;
    --panel-line:  #3a352d;
    --panel-ink:   #ede9e1;
    --panel-muted: #a69d8d;
    --accent:      #e08e2e;
    --accent-soft: #7a4d15;
    --danger:      #c25563;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--app-bg);
    color: var(--panel-ink);
}

body { display: flex; flex-direction: column; }

/* ─── TOOLBAR ─────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 18px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--panel-line);
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

/* the brand gives up space first: it truncates, buttons never overflow */
.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
}

.brand svg { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }

.brand-name { overflow: hidden; text-overflow: ellipsis; }

.brand-sub {
    font-size: 11.5px;
    font-weight: 400;
    color: var(--panel-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-left: 2px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    position: relative;
}

/* on wide screens the overflow group is invisible: its buttons sit
   directly in the toolbar row (see the responsive section) */
.tb-overflow { display: contents; }

/* .tb-btn sets display below, so this needs the extra specificity to win */
.tb-btn.tb-more { display: none; }

.tb-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--panel-ink);
    background: var(--panel-bg-2);
    border: 1px solid var(--panel-line);
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.tb-btn:hover { background: var(--panel-line); }

.tb-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.tb-primary { background: var(--accent-soft); border-color: var(--accent); }
.tb-primary:hover { background: var(--accent); }

.tb-danger:hover { background: var(--danger); border-color: var(--danger); }

.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn:disabled:hover { background: var(--panel-bg-2); }

/* ─── WORKSPACE ───────────────────────────────────────── */
.workspace {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ─── EDITOR PANEL ────────────────────────────────────── */
.editor {
    width: 400px;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 14px 14px 40px;
    background: var(--panel-bg);
    border-right: 1px solid var(--panel-line);
    scrollbar-width: thin;
    scrollbar-color: var(--panel-line) transparent;
}

.editor details {
    margin-bottom: 8px;
    background: var(--panel-bg-2);
    border: 1px solid var(--panel-line);
    border-radius: 7px;
    overflow: hidden;
}

.editor summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.editor summary::-webkit-details-marker { display: none; }

.editor summary::before {
    content: '▸';
    color: var(--accent);
    font-size: 11px;
    transition: transform 0.15s;
}

.editor details[open] summary::before { transform: rotate(90deg); }

.editor summary .sum-actions {
    margin-left: auto;
    display: flex;
    gap: 4px;
}

.editor summary .mini-btn[disabled] {
    opacity: 0.35;
    cursor: default;
}

.add-btn.sec-add { margin: 2px 0 10px; }

/* link to the project's repository, at the bottom of the editor */
.source-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-top: 10px;
    padding: 9px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--panel-muted);
    text-decoration: none;
    background: var(--panel-bg-2);
    border: 1px solid var(--panel-line);
    border-radius: 7px;
    transition: color 0.15s, border-color 0.15s;
}

.source-link:hover { color: var(--accent); border-color: var(--accent); }

.source-link svg { width: 15px; height: 15px; flex-shrink: 0; }

.ed-body { padding: 4px 12px 14px; }

.ed-hint {
    font-size: 11px;
    color: var(--panel-muted);
    margin: 2px 0 10px;
    line-height: 1.4;
}

/* form controls */
.ed-field { margin-bottom: 9px; }

.ed-field label,
.ed-field .ed-label {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--panel-muted);
    margin-bottom: 3px;
}

.ed-field input[type="text"],
.ed-field textarea,
.ed-field select {
    width: 100%;
    padding: 7px 9px;
    font-family: inherit;
    font-size: 13px;
    color: var(--panel-ink);
    background: var(--panel-bg);
    border: 1px solid var(--panel-line);
    border-radius: 5px;
    outline: none;
}

.ed-field input:focus,
.ed-field textarea:focus,
.ed-field select:focus { border-color: var(--accent); }

.ed-field textarea { resize: vertical; min-height: 74px; line-height: 1.45; }

.ed-row { display: flex; gap: 8px; }
.ed-row .ed-field { flex: 1; min-width: 0; }

/* item cards (experience / education / …) */
.ed-item {
    position: relative;
    padding: 10px 10px 4px;
    margin-bottom: 10px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-line);
    border-radius: 6px;
}

.ed-item-bar {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-bottom: 6px;
}

.mini-btn {
    padding: 2px 8px;
    font-family: inherit;
    font-size: 12px;
    line-height: 1.4;
    color: var(--panel-muted);
    background: var(--panel-bg-2);
    border: 1px solid var(--panel-line);
    border-radius: 4px;
    cursor: pointer;
}

.mini-btn:hover { color: var(--panel-ink); border-color: var(--accent); }
.mini-btn.del:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

/* drag & drop */
.drag-handle {
    cursor: grab;
    color: var(--panel-muted);
    font-size: 13px;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
    /* the drag runs on pointer events: stop the browser from
       panning/scrolling when a drag starts on the handle */
    touch-action: none;
    padding: 4px 3px;
}

.drag-handle:hover { color: var(--panel-ink); }
.drag-handle:active { cursor: grabbing; color: var(--accent); }

.ed-contact .drag-handle { flex-shrink: 0; }

/* the block being dragged */
.editor .dragging { opacity: 0.5; }

.editor details.drop-above { box-shadow: 0 -3px 0 0 var(--accent); }
.editor details.drop-below { box-shadow: 0 3px 0 0 var(--accent); }
.ed-contact.drop-above { box-shadow: 0 -2px 0 0 var(--accent); }
.ed-contact.drop-below { box-shadow: 0 2px 0 0 var(--accent); }

/* flash after a click-to-edit jump from the preview */
.ed-flash { animation: ed-flash 1.4s ease; }

@keyframes ed-flash {
    0%, 55% { box-shadow: 0 0 0 2px var(--accent); }
    100%    { box-shadow: 0 0 0 2px transparent; }
}

.add-btn {
    width: 100%;
    padding: 8px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--accent);
    background: transparent;
    border: 1.5px dashed var(--panel-line);
    border-radius: 6px;
    cursor: pointer;
}

.add-btn:hover { border-color: var(--accent); background: rgba(224,142,46,0.08); }

/* contacts */
.ed-contact { display: flex; gap: 6px; align-items: center; margin-bottom: 7px; }
.ed-contact select { width: 92px; flex-shrink: 0; }
.ed-contact input { flex: 1; min-width: 0; }
.ed-contact input.contact-link { flex: 0.8; }
.ed-contact select, .ed-contact input {
    padding: 6px 7px;
    font-family: inherit;
    font-size: 12.5px;
    color: var(--panel-ink);
    background: var(--panel-bg);
    border: 1px solid var(--panel-line);
    border-radius: 5px;
    outline: none;
}
.ed-contact select:focus, .ed-contact input:focus { border-color: var(--accent); }

/* photo */
.photo-controls { display: flex; align-items: center; gap: 10px; }

.photo-thumb {
    width: 58px;
    height: 68px;
    border: 1px solid var(--panel-line);
    border-radius: 4px;
    background: var(--panel-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--panel-muted);
    overflow: hidden;
    flex-shrink: 0;
}

.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* themes */
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }

.swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}

.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* custom color picker swatch */
.theme-swatches label.swatch-custom {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin: 0;
}

.swatch-custom::after {
    content: '✎';
    position: absolute;
    color: #fff;
    font-size: 13px;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.swatch-custom input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    border: none;
    padding: 0;
    cursor: pointer;
}

/* icons on/off checkbox */
.ed-field label.ed-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 12.5px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--panel-ink);
    cursor: pointer;
}

.ed-check input { accent-color: var(--accent); }

.ed-range { display: flex; align-items: center; gap: 10px; }
.ed-range input[type="range"] { flex: 1; accent-color: var(--accent); }
.ed-range output { font-size: 12px; color: var(--panel-muted); width: 40px; text-align: right; }

/* ─── PREVIEW ─────────────────────────────────────────── */
.preview {
    flex: 1;
    overflow: auto;
    padding: 26px 24px 60px;
    background: #121009;
}

.cv-scale {
    margin: 0 auto;
    transform-origin: top left;
    position: relative;
}

/* A4 page-break guides (screen only, one per printed page - see updatePageMarkers) */
.page-marker {
    position: absolute;
    left: -4px;
    right: -4px;
    border-top: 2px dashed rgba(194, 85, 99, 0.65);
    color: rgba(194, 85, 99, 0.9);
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding-top: 3px;
    text-align: right;
    pointer-events: none;
}

/* ════════════════════════════════════════════════════════
   CV DOCUMENT - theme colors set as CSS vars from app.js
   Base font size scales via --fs; child sizes are em-based.
   ════════════════════════════════════════════════════════ */
.cv-page {
    --navy:    #1a2744;
    --navy-mid:#2e4480;
    --cv-accent: #2e4480;
    --ink:     #1e1e1e;
    --muted:   #5a6070;
    --rule:    #c8ccda;
    --tag-bg:  #eef0f7;
    --fs:      13px;

    width: 794px;              /* A4 @ 96dpi */
    min-height: 1123px;
    padding: 38px 42px 36px;
    background: #ffffff;
    box-shadow: 0 6px 40px rgba(0, 0, 0, 0.45);
    font-size: var(--fs);
    font-weight: 400;
    line-height: 1.45;
    color: var(--ink);
}

/* header */
.cv-page header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 18px;
    margin-bottom: 24px;
    border-bottom: 2.5px solid var(--navy);
    gap: 20px;
}

.cv-page .header-info { flex: 1; min-width: 0; }

.cv-page h1 {
    margin: 0 0 6px;
    font-size: 2.31em;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: 0.5px;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.cv-page .contact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px 24px;
    font-size: 0.96em;
    color: var(--muted);
}

.cv-page .contact-grid span { display: flex; align-items: center; gap: 6px; }
.cv-page .contact-grid a { color: var(--navy-mid); text-decoration: none; }

.cv-page .contact-icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    color: var(--cv-accent);
}

.cv-page .photo-area {
    width: 110px;
    height: 130px;
    border: 2px solid var(--rule);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tag-bg);
    color: #aaa;
    font-size: 11px;
    text-align: center;
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}

.cv-page .photo-area img { width: 100%; height: 100%; object-fit: cover; }

/* sections */
.cv-page section { margin-bottom: 22px; }

.cv-page h2 {
    font-size: 1.04em;
    font-weight: 600;
    color: var(--navy);
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 1.5px solid var(--rule);
    padding-bottom: 4px;
    margin: 0 0 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cv-page h2 svg { width: 15px; height: 15px; color: var(--cv-accent); flex-shrink: 0; }

.cv-page .summary-text { font-size: 1em; color: #2e2e2e; margin: 0; }

/* items */
.cv-page .item { margin-bottom: 14px; }
.cv-page .item + .item { border-top: 1px dashed var(--rule); padding-top: 12px; }

.cv-page .item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 600;
    font-size: 1.115em;
    color: var(--navy);
    gap: 8px;
}

.cv-page .item-header .tech {
    font-weight: 400;
    font-size: 0.83em;
    color: var(--muted);
}

.cv-page .item-header .date {
    font-size: 0.83em;
    font-weight: 400;
    color: var(--muted);
    white-space: nowrap;
    font-style: italic;
}

.cv-page .item-subheader {
    display: flex;
    justify-content: space-between;
    font-style: italic;
    font-size: 0.923em;
    color: var(--cv-accent);
    margin-bottom: 5px;
    font-weight: 400;
}

.cv-page .item-subheader .location {
    color: var(--muted);
    font-style: normal;
    font-size: 0.96em;
    display: flex;
    align-items: center;
    gap: 3px;
}

.cv-page ul { margin: 0 0 0 16px; padding: 0; }

.cv-page li { margin-bottom: 2px; font-size: 1em; color: #2e2e2e; }

/* skills */
.cv-page .skills-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 32px;
    font-size: 0.96em;
}

.cv-page .skill-cat { display: flex; gap: 6px; align-items: flex-start; }

.cv-page .skill-cat strong {
    color: var(--navy-mid);
    font-weight: 600;
    white-space: nowrap;
}

/* click-to-edit affordance (screen only - hover never prints) */
.cv-page h1:hover,
.cv-page h2:hover,
.cv-page .photo-area:hover,
.cv-page .contact-grid span:hover,
.cv-page .summary-text:hover,
.cv-page .item:hover,
.cv-page .skill-cat:hover {
    outline: 1.5px dashed var(--rule);
    outline-offset: 3px;
    border-radius: 2px;
    cursor: pointer;
}

/* ─── RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 900px) {
    .workspace { flex-direction: column; }
    .editor {
        width: 100%;
        max-height: 46vh;
        border-right: none;
        border-bottom: 1px solid var(--panel-line);
    }
}

/* toolbar shrinks in three steps as the window narrows:
   1. buttons drop their labels, 2. secondary actions move into the
   "..." menu, 3. the brand keeps only its icon */
@media (max-width: 860px) {
    .toolbar { padding: 10px 12px; }
    .brand-sub { display: none; }
    .tb-btn { padding: 7px 10px; }
    .tb-label { display: none; }
}

@media (max-width: 560px) {
    .tb-btn.tb-more { display: inline-flex; }

    .tb-overflow {
        display: none;
        position: absolute;
        top: calc(100% + 9px);
        right: 0;
        z-index: 30;
        flex-direction: column;
        gap: 5px;
        min-width: 168px;
        padding: 6px;
        background: var(--panel-bg-2);
        border: 1px solid var(--panel-line);
        border-radius: 8px;
        box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
    }

    .tb-overflow.open { display: flex; }

    /* inside the menu there is room for labels again */
    .tb-overflow .tb-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 8px 11px;
        background: transparent;
        border-color: transparent;
    }

    .tb-overflow .tb-btn:hover { background: var(--panel-line); }
    .tb-overflow .tb-label { display: inline; }
}

@media (max-width: 420px) {
    .brand-name { display: none; }
}

/* fingers need a bigger grab area than a mouse pointer */
@media (pointer: coarse) {
    .drag-handle { padding: 8px 7px; font-size: 16px; }
}

/* ─── PRINT ───────────────────────────────────────────── */
@media print {
    @page { size: A4; margin: 10mm 12mm; }

    html, body { background: #fff; height: auto; display: block; }

    .toolbar, .editor { display: none !important; }

    .workspace, .preview { display: block; overflow: visible; padding: 0; background: #fff; }

    .cv-scale { transform: none !important; width: auto !important; height: auto !important; }
    .page-marker { display: none; }

    .cv-page {
        width: auto;
        min-height: 0;
        box-shadow: none;
        padding: 0;
    }

    .cv-page .photo-area.empty { display: none; }

    .cv-page a { color: var(--navy-mid); }

    /* keep entries and headings whole across page breaks */
    .cv-page header,
    .cv-page .item,
    .cv-page h2 { break-inside: avoid; page-break-inside: avoid; }
    .cv-page h2 { break-after: avoid; page-break-after: avoid; }
}
