/* App layout and A4 rendering rules */

:root {
    /* Resume Variables (Legacy/Internal) */
    --resume-font-body: -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    --resume-font-heading: "Source Serif 4",
        Georgia,
        serif;
    /* Updated to match UI vibe */
    --resume-base-font-pt: 11pt;
    --resume-heading-scale: 1.2;
    --resume-line-height: 1.6;
    --resume-paragraph-gap-pt: 8pt;
    --resume-font-weight-body: 400;
    --resume-font-weight-heading: 600;
    --resume-color-h1: #1a1a1a;
    --resume-color-h2: #2c3e50;
    --resume-color-h3: #1a1a1a;
    --resume-color-body: #1a1a1a;
    --resume-spacing-block-pt: 20pt;
    --resume-radius-card-px: 3px;
    --resume-line-width-pt: 1pt;

    /* --- Brillance UI System --- */

    /* Colors */
    --ui-bg-page: #ffffff;
    --ui-bg-surface: #fafafa;
    --ui-bg-panel: #ffffff;

    --ui-fg-primary: #171717;
    /* Deep Black-Gray */
    --ui-fg-secondary: #666666;
    /* Neutral Gray */
    --ui-fg-muted: #a3a3a3;
    /* Light Gray */
    --ui-fg-on-accent: #ffffff;

    --ui-border-light: #e5e5e5;
    --ui-border-hover: #d4d4d4;

    --ui-accent: #171717;
    /* Primary Action */
    --ui-accent-hover: #000000;

    /* Typography */
    --font-ui-sans: 'Inter',
        system-ui,
        -apple-system,
        sans-serif;
    --font-ui-serif: 'Source Serif 4',
        'Noto Serif SC',
        serif;

    /* Radius */
    --radius-pill: 9999px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

html {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    overflow-x: hidden;
    background-color: var(--ui-bg-page);
    color: var(--ui-fg-primary);
    font-family: var(--font-ui-sans);
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    height: 100vh;
    min-width: 0;
}

.gutter {
    cursor: col-resize;
    background: var(--ui-border-light);
    transition: background 0.2s;
    flex-shrink: 0;
}

.gutter:hover {
    background: color-mix(in srgb, var(--ui-accent, #9b6e46) 35%, transparent 65%);
}

#app > .gutter {
    width: 4px !important;
    min-width: 4px;
    flex: 0 0 4px;
    position: relative;
}

#app > .gutter::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 1px;
    height: 22px;
    border-radius: 999px;
    transform: translate(-50%, -50%);
    background: color-mix(in srgb, var(--ui-accent, #9b6e46) 40%, transparent 60%);
    opacity: 0.34;
}

#editor-pane {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--ui-border-light);
    background-color: var(--ui-bg-page);
    flex: 0 0 auto;
    width: 40%;
    min-width: 300px;
    overflow: hidden;
}

#preview-pane {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    width: 60%;
    min-width: 300px;
    overflow: hidden;
}

body.app-read-only #editor-pane {
    display: none !important;
}

body.app-read-only #preview-pane {
    flex: 1 1 auto;
    width: 100% !important;
    min-width: 0;
}

body.app-export-disabled #preview-pane .dropdown {
    display: none !important;
}

a.disabled,
.menu a.disabled {
    pointer-events: none;
    opacity: 0.45;
}

#paper-scroller {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: block;
    min-width: 0;
    background-color: #f8f5ef;
    background-image:
        linear-gradient(to right, rgba(112, 92, 68, 0.06) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(112, 92, 68, 0.06) 1px, transparent 1px);
    background-size: 22px 22px;
}

#paper-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: fit-content;
    min-width: 210mm;
    margin: 0 auto;
    padding-bottom: 40px;
}

.toolbar {
    min-height: 52px;
    height: 52px;
    border-bottom: 1px solid var(--ui-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    flex-shrink: 0;
    user-select: none;
    gap: 8px;
}

.brand {
    font-family: var(--font-ui-serif, 'Source Serif 4', serif);
    font-size: 15px;
    font-weight: 600;
    color: var(--ui-fg-primary, #2f2a25);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
}

.actions {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: flex-end;
    flex-shrink: 0;
}

#editor-pane .actions-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

#editor-pane .actions {
    flex-wrap: wrap;
    flex-shrink: 1;
    min-width: 0;
}

.resume-page {
    width: 210mm;
    min-height: 297mm;
    height: 297mm;
    background: #ffffff;
    border: 1px solid rgba(47, 42, 37, 0.12);
    border-radius: var(--resume-radius-card-px, 3px);
    box-shadow: 0 10px 26px rgba(40, 30, 18, 0.12), 0 2px 8px rgba(40, 30, 18, 0.08);
    position: relative;
    overflow: hidden;
    color: #000;
    padding: 0;
}

.resume-content {
    height: 100%;
}

/* Margin Guides - button-triggered */
.margin-guide {
    position: absolute;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

body.margin-guides-active .margin-guide {
    opacity: 1;
    pointer-events: auto;
}

.margin-guide::before {
    content: '';
    position: absolute;
    background: #e74c3c;
    transition: background 0.15s;
}

.margin-guide:hover::before,
.margin-guide.dragging::before {
    background: #c0392b;
}

.margin-guide-top,
.margin-guide-bottom {
    left: var(--p-x, 30mm);
    right: var(--p-x, 30mm);
    height: 12px;
    cursor: ns-resize;
}

.margin-guide-top {
    top: var(--p-y, 35mm);
    transform: translateY(-50%);
}

.margin-guide-top::before {
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    transform: translateY(-50%);
}

.margin-guide-bottom {
    bottom: var(--p-y, 35mm);
    transform: translateY(50%);
}

.margin-guide-bottom::before {
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    transform: translateY(-50%);
}

.margin-guide-left,
.margin-guide-right {
    top: var(--p-y, 35mm);
    bottom: var(--p-y, 35mm);
    width: 12px;
    cursor: ew-resize;
}

.margin-guide-left {
    left: var(--p-x, 30mm);
    transform: translateX(-50%);
}

.margin-guide-left::before {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    transform: translateX(-50%);
}

.margin-guide-right {
    right: var(--p-x, 30mm);
    transform: translateX(50%);
}

.margin-guide-right::before {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    transform: translateX(-50%);
}

.render-error {
    margin: 0;
    padding: 14px 16px;
    border: 1px solid #f2a8b0;
    border-radius: 6px;
    background: #fff4f5;
    color: #8a1e2d;
    font: 13px/1.5 "Menlo", "Monaco", "Courier New", monospace;
    white-space: pre-wrap;
}

@media (max-width: 1280px) {
    .toolbar {
        gap: 6px;
    }
}

@media (max-width: 1024px) {
    body {
        height: auto;
        overflow: auto;
    }

    #app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    #app>.gutter {
        display: none;
    }

    #editor-pane,
    #preview-pane {
        width: 100% !important;
        flex: 1 1 auto;
        min-width: 0;
    }

    #editor-pane {
        min-height: 42vh;
        border-right: none;
        border-bottom: 1px solid var(--ui-border, #d8cfc2);
    }

    #preview-pane {
        min-height: 58vh;
    }

    .actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
        flex-shrink: 1;
    }

    #paper-scroller {
        padding: 12px;
    }
}

@media (max-width: 640px) {
    .toolbar {
        padding: 8px 10px;
    }

    #paper-scroller {
        padding: 10px;
    }
}

@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: none;
        height: auto;
        overflow: visible;
    }

    #editor-pane,
    .toolbar,
    .gutter,
    .split,
    .margin-guide {
        display: none !important;
    }

    #app,
    #preview-pane,
    #paper-scroller,
    #paper-container {
        display: block;
        height: auto;
        overflow: visible;
        background: none;
        padding: 0;
        margin: 0;
    }

    .resume-page {
        margin: 0;
        box-shadow: none;
        page-break-after: always;
        break-after: page;
        height: auto;
        min-height: 297mm;
        width: 100%;
        background: #ffffff !important;
    }

    .resume-page:last-child {
        page-break-after: auto;
    }
}

/* ===== Compact Theme Studio Controls ===== */

/* Design Pane Layout */
#design-pane {
    flex: 1 1 0%;
    overflow-y: auto;
    min-height: 0;
    padding: 8px 10px !important;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Collapsible Section (details/summary) */
.cs {
    background: var(--ui-bg-surface, #ffffff);
    border: 1px solid var(--ui-border, #d8cfc2);
    border-radius: 6px;
    transition: box-shadow 0.2s ease;
}

.cs:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.cs+.cs {
    margin-top: 0;
    /* gap handled by parent flex */
}

/* Section Header */
.cs-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-family: var(--ui-font-display, serif);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ui-text-muted, #7b7268);
    border-bottom: 1px solid transparent;
    transition: color 0.15s, background 0.15s;
}

.cs-header::-webkit-details-marker {
    display: none;
}

.cs-header::marker {
    display: none;
    content: "";
}

.cs[open]>.cs-header {
    border-bottom-color: var(--ui-border, #d8cfc2);
    color: var(--ui-text-primary, #2f2a25);
}

.cs-header:hover {
    background: rgba(0, 0, 0, 0.02);
}

/* Chevron */
.cs-chevron {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.2s ease;
    color: var(--ui-text-muted, #999);
}

.cs[open]>.cs-header .cs-chevron {
    transform: rotate(180deg);
}

/* Section Body */
.cs-body {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* --- Compact Control Row (inline flex) --- */
.cv {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
}

.cv-label {
    flex-shrink: 0;
    width: 76px;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--ui-text-primary, #2f2a25);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cv-range {
    flex: 1;
    min-width: 0;
    height: 14px !important;
    accent-color: var(--ui-accent, #9b6e46);
    cursor: pointer;
}

.cv-num {
    width: 48px !important;
    min-width: 48px;
    height: 24px !important;
    min-height: 24px !important;
    padding: 0 4px !important;
    text-align: center;
    font-size: 11px !important;
    border: 1px solid var(--ui-border, #d8cfc2) !important;
    border-radius: 4px !important;
    background: var(--ui-bg-input, #fff);
    color: var(--ui-text-primary);
    box-shadow: none !important;
    outline-offset: 1px;
}

.cv-num:focus {
    border-color: var(--ui-accent, #9b6e46) !important;
    outline: 1px solid var(--ui-focus-ring, rgba(155, 110, 70, 0.3));
}

.cv-select {
    flex: 1;
    min-width: 0;
    height: 26px !important;
    min-height: 26px !important;
    padding: 0 22px 0 6px !important;
    font-size: 11.5px !important;
    border: 1px solid var(--ui-border, #d8cfc2) !important;
    border-radius: 4px !important;
    background: var(--ui-bg-input, #fff);
    color: var(--ui-text-primary);
    box-shadow: none !important;
    cursor: pointer;
    background-size: 3px 3px, 3px 3px !important;
    background-position: calc(100% - 10px) calc(1px + 50%), calc(100% - 7px) calc(1px + 50%) !important;
}

.cv-select:focus {
    border-color: var(--ui-accent, #9b6e46) !important;
    outline: 1px solid var(--ui-focus-ring, rgba(155, 110, 70, 0.3));
}

/* --- Color Swatch Row --- */
.color-row {
    display: flex;
    justify-content: space-around;
    padding: 4px 0;
}

.color-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.color-swatch input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--ui-border, #d8cfc2);
    padding: 0;
    cursor: pointer;
    background: none;
    transition: border-color 0.15s, transform 0.15s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.color-swatch input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 50%;
}

.color-swatch input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.color-swatch input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 50%;
}

.color-swatch input[type="color"]:hover {
    border-color: var(--ui-accent, #9b6e46);
    transform: scale(1.1);
}

.color-swatch span {
    font-size: 10px;
    color: var(--ui-text-muted, #7b7268);
    font-weight: 500;
}

/* --- Subsection Header (inside advanced panel) --- */
.cs-sub {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ui-text-muted, #7b7268);
    padding: 4px 0 2px;
    margin-top: 2px;
}

/* --- Advanced Mode Toggle --- */
.cs-toggle-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    cursor: pointer;
}

.cs-toggle-row .toggle {
    --tglbg: var(--ui-border, #d8cfc2);
}

.cs-toggle-row span {
    font-size: 11.5px;
    font-weight: 500;
    color: var(--ui-text-muted, #7b7268);
}

/* --- Divider inside sections --- */
.cs-divider {
    height: 1px;
    background: var(--ui-border, #d8cfc2);
    margin: 4px 0;
    opacity: 0.5;
}

/* --- Custom font upload compact --- */
.cs-file-upload {
    font-size: 11px;
}

.cs-file-upload .file-input {
    height: 28px !important;
    min-height: 28px !important;
    font-size: 11px !important;
}

.cs-file-hint {
    font-size: 10px;
    color: var(--ui-text-muted, #999);
    margin-top: 2px;
}

/* --- Studio Status --- */
#studio-status {
    font-size: 11px;
    text-align: center;
    opacity: 0.6;
    padding: 4px 0;
}

/* ── Help Tooltip ── */

.help-tip-wrap {
    position: relative;
    display: flex;
    align-items: center;
    align-self: center;
    height: 34px;
}

.btn-help-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--ui-text-muted, #7b7268);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 0;
    flex-shrink: 0;
}

.btn-help-tip:hover {
    color: var(--ui-accent, #9b6e46);
    background: rgba(0, 0, 0, 0.04);
}

.btn-help-tip .ui-icon {
    width: 16px;
    height: 16px;
}

.help-tip-card {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: var(--z-help, 90);
    min-width: 380px;
    background: var(--ui-bg-surface, #fffdf8);
    border: 1px solid var(--ui-border, #d8cfc2);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    padding: 14px 16px;
    pointer-events: none;
    animation: helpTipIn 0.15s ease-out;
}

@keyframes helpTipIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Arrow */
.help-tip-card::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 14px;
    width: 10px;
    height: 10px;
    background: var(--ui-bg-surface, #fffdf8);
    border-top: 1px solid var(--ui-border, #d8cfc2);
    border-left: 1px solid var(--ui-border, #d8cfc2);
    transform: rotate(45deg);
}

.help-tip-wrap:hover .help-tip-card {
    display: block;
    pointer-events: auto;
}

.help-tip-card h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--ui-text-primary, #2f2a25);
    margin: 0 0 10px 0;
    letter-spacing: 0.03em;
}

.help-tip-card table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
    line-height: 1.4;
}

.help-tip-card th {
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ui-text-muted, #7b7268);
    padding: 0 6px 6px 6px;
    border-bottom: 1px solid var(--ui-border, #d8cfc2);
}

.help-tip-card td {
    padding: 5px 6px;
    color: var(--ui-text-primary, #2f2a25);
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.help-tip-card tr:last-child td {
    border-bottom: none;
}

.help-tip-card code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 10.5px;
    background: rgba(0, 0, 0, 0.05);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--ui-accent, #9b6e46);
}

.help-tip-note {
    font-size: 10.5px;
    color: var(--ui-text-muted, #7b7268);
    margin: 10px 0 0 0;
    line-height: 1.5;
}
