/* ============================================================
   FORM A.I.R — PDF Template Creator  |  Design System
   ============================================================ */

:root {
    /* Color Palette — Dark Sophisticated */
    --bg-deep:        #0B0E14;
    --bg-surface:     #111620;
    --bg-card:        #171C28;
    --bg-elevated:    #1E2436;
    --bg-hover:       #252D40;
    --border-subtle:  #2A3348;
    --border-default: #3A4560;
    --text-primary:   #E8ECF4;
    --text-secondary: #8B95AD;
    --text-muted:     #5A6478;
    --accent-primary: #6C5CE7;
    --accent-light:   #A29BFE;
    --accent-glow:    rgba(108, 92, 231, .25);
    --success:        #00B894;
    --success-glow:   rgba(0, 184, 148, .20);
    --warning:        #FDCB6E;
    --danger:         #FF6B6B;
    --gradient-brand: linear-gradient(135deg, #6C5CE7, #00B894);
    --gradient-card:  linear-gradient(180deg, #171C28, #111620);
    --shadow-sm:      0 1px 3px rgba(0,0,0,.35);
    --shadow-md:      0 4px 16px rgba(0,0,0,.45);
    --shadow-lg:      0 8px 32px rgba(0,0,0,.55);
    --shadow-glow:    0 0 24px var(--accent-glow);
    --radius-sm:      6px;
    --radius-md:      10px;
    --radius-lg:      16px;
    --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono:      'JetBrains Mono', 'Fira Code', monospace;
    --transition:     .22s cubic-bezier(.4,0,.2,1);
}

/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar Styling ─────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

/* ── Top Navigation Bar ────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
    z-index: 100;
}
.topbar::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0; right: 0;
    height: 1px;
    background: var(--gradient-brand);
    opacity: .5;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo-mark {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}
.topbar-title {
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: -.3px;
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-divider {
    width: 1px; height: 24px;
    background: var(--border-subtle);
    margin: 0 4px;
}

/* ── Buttons ───────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-family: var(--font-sans);
    font-size: .82rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-primary {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}
.btn-primary:hover {
    background: #7C6DF7;
    transform: translateY(-1px);
    box-shadow: 0 0 32px var(--accent-glow);
}
.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-default);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--accent-light);
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}
.btn-icon {
    width: 30px; height: 30px;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    transition: all var(--transition);
}
.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-light);
}

/* ── Main Layout ───────────────────────────────── */
.main-container {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* ── Editor Panel (Left) ───────────────────────── */
.editor-panel {
    width: 44%;
    min-width: 380px;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
}
.panel-header h2 {
    font-size: .88rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -.2px;
}
.badge {
    font-size: .72rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-glow);
    color: var(--accent-light);
    border: 1px solid rgba(108, 92, 231, .3);
}

/* ── Form Styles ───────────────────────────────── */
.form-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 60px;
}
.form-section {
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition);
}
.form-section:hover { border-color: var(--border-default); }
.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: .78rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .6px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
}
.section-icon { font-size: .9rem; }
.form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 14px;
    border-bottom: 1px solid rgba(42, 51, 72, .4);
}
.form-row:last-child { border-bottom: none; }
.form-label {
    font-size: .74rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.field-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px; height: 20px;
    font-size: .65rem;
    font-weight: 700;
    color: var(--accent-light);
    background: var(--accent-glow);
    border-radius: 50%;
    flex-shrink: 0;
}
.form-input {
    width: 100%;
    padding: 7px 10px;
    font-family: var(--font-mono);
    font-size: .8rem;
    color: var(--text-primary);
    background: var(--bg-deep);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all var(--transition);
}
.form-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-input::placeholder { color: var(--text-muted); font-style: italic; }
.form-textarea { resize: vertical; min-height: 54px; line-height: 1.45; }

/* ── Preview Panel (Right) ─────────────────────── */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-deep);
}
.preview-controls { display: flex; align-items: center; gap: 6px; }
.zoom-label {
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
    font-family: var(--font-mono);
}
.preview-scroll {
    flex: 1;
    overflow: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
.preview-canvas-wrap {
    display: flex;
    flex-direction: column;
    gap: 20px;
    transform-origin: top center;
}

/* ── PDF Page (Preview) ────────────────────────── */
.pdf-page {
    width: 595px; /* A4 at 72dpi */
    min-height: 842px;
    background: #FFFFFF;
    color: #000;
    box-shadow: var(--shadow-lg), 0 0 40px rgba(0,0,0,.3);
    border-radius: 2px;
    padding: 50px 42px 50px 54px;
    font-family: 'Times New Roman', 'Georgia', serif;
    font-size: 10px;
    line-height: 1.35;
    position: relative;
    overflow: hidden;
}

/* ── PDF Content Styles ────────────────────────── */
.pdf-header { text-align: center; margin-bottom: 8px; }
.pdf-header .title-main { font-size: 12px; font-weight: 700; }
.pdf-header .title-sub { font-size: 10px; font-weight: 700; }
.pdf-header .title-rule { font-size: 10px; font-weight: 700; }
.pdf-header .title-cr { font-size: 10px; font-weight: 700; margin-top: 2px; }

.pdf-row {
    display: flex;
    margin-bottom: 2px;
    page-break-inside: avoid;
}
.pdf-row-num {
    width: 16px;
    flex-shrink: 0;
    font-size: 10px;
}
.pdf-row-label {
    width: 244px;
    flex-shrink: 0;
    font-size: 10px;
    line-height: 1.3;
    padding-right: 4px;
}
.pdf-row-colon {
    width: 12px;
    flex-shrink: 0;
    font-weight: 700;
    text-align: center;
}
.pdf-row-value {
    flex: 1;
    font-size: 9.5px;
    line-height: 1.3;
    padding-left: 4px;
}
.pdf-row-value.bold { font-weight: 700; }
.pdf-row-indent { padding-left: 20px; }
.pdf-row-deep-indent { padding-left: 90px; }
.pdf-sub-row { display: flex; margin-bottom: 1px; }
.pdf-sub-label { padding-left: 20px; font-size: 10px; }
.pdf-multiline { white-space: pre-line; }

.pdf-footer {
    margin-top: 18px;
    font-size: 10px;
}
.pdf-footer-row {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
}
.pdf-footer-right { text-align: right; }
.pdf-spacer { height: 8px; }
.pdf-spacer-lg { height: 16px; }

/* ── Inline Editable Cells (Preview) ───────────── */
.pdf-editable {
    cursor: text;
    border-radius: 2px;
    outline: none;
    transition: background .18s ease, box-shadow .18s ease;
    min-height: 12px;
    position: relative;
}
.pdf-editable:hover {
    background: rgba(108, 92, 231, .07);
    box-shadow: inset 0 0 0 1px rgba(108, 92, 231, .25);
}
.pdf-editable:focus,
.pdf-editable.pdf-editing {
    background: rgba(108, 92, 231, .10);
    box-shadow: inset 0 0 0 1.5px rgba(108, 92, 231, .5);
}
.pdf-editable:empty::before {
    content: 'Click to edit...';
    color: #bbb;
    font-style: italic;
    pointer-events: none;
}
/* Modal pages also editable */
.modal-page .pdf-editable:hover {
    background: rgba(108, 92, 231, .07);
    box-shadow: inset 0 0 0 1px rgba(108, 92, 231, .25);
}
.modal-page .pdf-editable:focus,
.modal-page .pdf-editable.pdf-editing {
    background: rgba(108, 92, 231, .10);
    box-shadow: inset 0 0 0 1.5px rgba(108, 92, 231, .5);
}

/* ── Modal Overlay ─────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, .8);
    backdrop-filter: blur(8px);
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: opacity .3s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }
.modal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 10px;
}
.modal-header h2 {
    font-size: .95rem;
    font-weight: 700;
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.modal-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.margin-control {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .72rem;
    color: var(--text-secondary);
}
.margin-control span { font-weight: 600; }
.margin-control input {
    width: 52px;
    padding: 4px 6px;
    font-family: var(--font-mono);
    font-size: .75rem;
    background: var(--bg-deep);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    outline: none;
    text-align: center;
}
.margin-control input:focus { border-color: var(--accent-primary); }
.modal-body {
    flex: 1;
    overflow: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    background: #1a1a2e;
}
.modal-page {
    width: 595px;
    min-height: 842px;
    background: #fff;
    color: #000;
    box-shadow: 0 4px 40px rgba(0,0,0,.5);
    font-family: 'Times New Roman', 'Georgia', serif;
    font-size: 10px;
    line-height: 1.35;
    padding: 50px 42px 50px 54px;
}

/* ── Animations ────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.form-section { animation: fadeIn .35s ease both; }
.form-section:nth-child(2) { animation-delay: .05s; }
.form-section:nth-child(3) { animation-delay: .10s; }
.form-section:nth-child(4) { animation-delay: .15s; }
.form-section:nth-child(5) { animation-delay: .20s; }
.form-section:nth-child(6) { animation-delay: .25s; }
.form-section:nth-child(7) { animation-delay: .30s; }
.form-section:nth-child(8) { animation-delay: .35s; }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 960px) {
    .main-container { flex-direction: column; }
    .editor-panel { width: 100%; max-width: 100%; min-width: unset; height: 50vh; border-right: none; border-bottom: 1px solid var(--border-subtle); }
    .preview-panel { height: 50vh; }
    .topbar-actions { gap: 4px; }
    .btn span { display: none; }
}
