:root {
    --ink: #1b2027;
    --ink-soft: #4b5563;
    --line: #e2e5ea;
    --paper: #ffffff;
    --canvas: #f4f5f7;
    --accent: #1f4d3d;
    --accent-soft: #e7efe9;
    --danger: #a3372f;
    --radius: 6px;
    --mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--sans);
    background: var(--canvas);
    color: var(--ink);
}

header.topbar {
    background: var(--ink);
    color: #fff;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 50;
}

header.topbar .brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

header.topbar .brand .mark {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.14em;
    color: #9fd8bb;
    text-transform: uppercase;
    border: 1px solid #3a5a4c;
    padding: 3px 7px;
    border-radius: 4px;
}

header.topbar h1 {
    font-size: 16px;
    margin: 0;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: filter .12s ease, transform .12s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: #2f6b52;
    color: #fff;
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.btn-ghost {
    background: transparent;
    color: #fff;
    border-color: #3d4652;
}

.btn-ghost:hover {
    background: #262d36;
}

.btn-line {
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}

.btn-line:hover {
    background: #f1f2f4;
}

.btn-danger-line {
    background: #fff;
    color: var(--danger);
    border-color: #e2c3c0;
}

.btn-danger-line:hover {
    background: #fbf0ef;
}

input[type=file] {
    display: none;
}

.layout {
    display: grid;
    grid-template-columns: minmax(360px, 480px) 1fr;
    gap: 0;
    align-items: start;
}

.editor {
    padding: 22px;
    max-height: calc(100vh - 58px);
    overflow-y: auto;
    border-right: 1px solid var(--line);
    background: #fbfbfc;
}

.preview-pane {
    padding: 20px 24px 48px;
    max-height: calc(100vh - 58px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.section-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 14px;
    overflow: hidden;
}

.section-card>.head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    background: var(--accent-soft);
    border-bottom: 1px solid var(--line);
    gap: 8px;
}

.section-card>.head h2 {
    margin: 0;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    font-weight: 700;
}

.section-card>.body {
    padding: 14px;
}

label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 4px;
}

input[type=text],
textarea {
    width: 100%;
    font-family: inherit;
    font-size: 13.5px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--ink);
    background: #fff;
    margin-bottom: 10px;
    resize: vertical;
}

input[type=text]:focus,
textarea:focus {
    outline: 2px solid #2f6b52;
    outline-offset: 0;
    border-color: #2f6b52;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.entry {
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 10px;
    position: relative;
    background: #fcfcfd;
}

.entry .entry-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.include-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-soft);
    text-transform: none;
}

.include-toggle input {
    margin: 0;
}

.entry.excluded {
    opacity: 0.45;
}

.row-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: 1px solid var(--line);
    border-radius: 5px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    color: var(--ink-soft);
}

.icon-btn:hover {
    background: #f1f2f4;
    color: var(--ink);
}

.icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.icon-btn:disabled:hover {
    background: none;
    color: var(--ink-soft);
}

.icon-btn.danger:hover {
    background: #fbf0ef;
    color: var(--danger);
    border-color: #e2c3c0;
}

.bullets {
    margin-bottom: 6px;
}

.bullet-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    align-items: flex-start;
}

.bullet-row textarea {
    margin-bottom: 0;
    min-height: 38px;
}

.add-btn {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid #cfe3d7;
    border-radius: 5px;
    padding: 6px 10px;
    cursor: pointer;
    margin-top: 2px;
}

.add-btn:hover {
    filter: brightness(0.97);
}

.section-toggle-hint {
    font-size: 11.5px;
    color: var(--ink-soft);
    margin: 0 0 10px;
    line-height: 1.5;
}

.helptext {
    font-size: 11.5px;
    color: #8a8f98;
    margin: -6px 0 10px;
}

.section-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
    gap: 8px;
}

.section-row:last-of-type {
    border-bottom: none;
}

.tag-custom {
    font-size: 9px;
    background: #eef2ff;
    color: #3b4fae;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 700;
}

.section-title-input {
    background: transparent;
    border: none;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    font-weight: 700;
    margin: 0;
    padding: 0;
    width: auto;
    flex: 1;
}

.section-title-input:focus {
    outline: none;
    border: none;
}

/* ---- Preview Toolbar & Page Counter ---- */
.preview-toolbar {
    width: 794px;
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 9px 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
}

.page-count-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-soft);
}

.page-count-badge strong {
    color: var(--ink);
    font-weight: 700;
}

.page-count-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    letter-spacing: 0.02em;
}

.preview-toolbar-meta .preview-hint {
    font-size: 11.5px;
    color: #8c939d;
    font-weight: 500;
}

/* ---- Resume Preview Container ---- */
#resume {
    width: 794px;
    /* A4 standard width @96dpi (210mm) */
    min-height: 1123px;
    /* A4 standard height @96dpi (297mm) */
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07), 0 10px 28px rgba(0, 0, 0, 0.06);
    padding: 48px 56px;
    font-family: 'Calibri', 'Segoe UI', Arial, sans-serif;
    color: #111;
    line-height: 1.38;
    position: relative;
    box-sizing: border-box;
    border-radius: 3px;
    flex-shrink: 0;
}

.resume-print-table {
    width: 100%;
    border-collapse: collapse;
    border: none;
    margin: 0;
    padding: 0;
}

.resume-print-table thead,
.resume-print-table tfoot {
    display: none;
}

.resume-print-table td {
    padding: 0;
    border: none;
    vertical-align: top;
}

.r-name {
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.01em;
    margin: 0 0 4px;
    color: #111;
}

.r-contact {
    text-align: center;
    font-size: 11px;
    color: #333;
    margin: 0 0 16px;
}

h3.r-section {
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1.4px solid #111;
    padding-bottom: 2px;
    margin: 16px 0 8px;
    font-weight: 700;
    break-after: avoid;
    page-break-after: avoid;
    break-inside: avoid;
    page-break-inside: avoid;
}

h3.r-section:first-of-type {
    margin-top: 0;
}

p.r-profile {
    font-size: 12px;
    margin: 0 0 4px;
    orphans: 3;
    widows: 3;
}

.r-item {
    margin-bottom: 9px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.r-item:last-child {
    margin-bottom: 0;
}

.r-item-title-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    font-weight: 700;
}

.r-item-sub-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 11.5px;
    font-style: italic;
    color: #222;
    margin-bottom: 3px;
}

ul.r-bullets {
    margin: 2px 0 0 18px;
    padding: 0;
    font-size: 11.7px;
    break-inside: avoid;
    page-break-inside: avoid;
}

ul.r-bullets li {
    margin-bottom: 2px;
}

p.r-plain {
    font-size: 11.7px;
    margin: 2px 0 0;
}

.r-skills-row {
    font-size: 11.7px;
    margin-bottom: 3px;
    break-inside: avoid;
}

.r-skills-row b {
    font-weight: 700;
}

.r-langs {
    font-size: 11.7px;
    margin: 0;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }

    html,
    body {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    header.topbar,
    .editor,
    .preview-toolbar {
        display: none !important;
    }

    .layout {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .preview-pane {
        padding: 0 !important;
        margin: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        display: block !important;
    }

    #resume {
        box-shadow: none !important;
        border-radius: 0 !important;
        width: 100% !important;
        min-height: 0 !important;
        height: auto !important;
        padding: 0 16mm !important;
        margin: 0 !important;
        display: block !important;
    }

    .resume-print-table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    .resume-print-table thead {
        display: table-header-group !important;
    }

    .resume-print-table tfoot {
        display: table-footer-group !important;
    }

    .resume-page-top-spacer {
        height: 12mm;
    }

    .resume-page-bottom-spacer {
        height: 12mm;
    }
}

@media (max-width:900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .editor {
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .preview-pane {
        max-height: none;
    }

    .preview-toolbar,
    #resume {
        width: 100%;
    }

    #resume {
        padding: 28px;
    }
}
