/* ═══════════════════════════════════════════════════════════
   PDF Editor — Erodea  ·  Design System
   ═══════════════════════════════════════════════════════════ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-bg: rgba(99,102,241,.06);
    --accent: #06b6d4;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f1f5f9;
    --bg-white: #ffffff;
    --bg-dark: #0f172a;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.08);
    --shadow-xl: 0 20px 50px rgba(0,0,0,.12);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: .2s ease;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: var(--font); }

/* ── NAVBAR ───────────────────────────────────────────────── */
.navbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; height: 56px;
    background: var(--bg-white); border-bottom: 1px solid var(--border);
    position: relative; z-index: 100;
}
.navbar-brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 1.05rem; color: var(--text);
}
.navbar-brand .logo-icon {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: .85rem;
}
.navbar-actions { display: flex; align-items: center; gap: 8px; }
.navbar-filename {
    font-size: .85rem; color: var(--text-secondary); font-weight: 500;
    max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 18px; border-radius: var(--radius-sm); font-size: .85rem;
    font-weight: 500; transition: all var(--transition); white-space: nowrap;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff; box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,.4); }
.btn-ghost {
    background: transparent; color: var(--text-secondary); border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: var(--radius-xs); }
.btn-icon-only {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); font-size: .9rem; transition: all var(--transition);
}
.btn-icon-only:hover { background: var(--bg); color: var(--text); }
.btn-icon-only.active { background: var(--primary-bg); color: var(--primary); }

/* ── LANG TOGGLE ──────────────────────────────────────────── */
.lang-toggle {
    display: inline-flex; border-radius: var(--radius-xs); overflow: hidden;
    border: 1px solid var(--border); font-size: .78rem;
}
.lang-toggle button {
    padding: 4px 10px; font-weight: 600; color: var(--text-muted);
    transition: all var(--transition); font-size: .78rem;
}
.lang-toggle button.active { background: var(--primary); color: #fff; }

/* ── LANDING PAGE ─────────────────────────────────────────── */
.landing {
    display: flex; flex-direction: column; min-height: 100vh; overflow: auto;
}
.landing body, .landing { overflow: auto; }
.landing-hero {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 40px 20px; position: relative;
}
.landing-hero::before {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 0%, rgba(99,102,241,.08) 0%, transparent 70%);
    pointer-events: none;
}
.landing-content { text-align: center; position: relative; z-index: 1; max-width: 560px; width: 100%; }
.landing-title {
    font-size: 2.8rem; font-weight: 800; letter-spacing: -.03em;
    background: linear-gradient(135deg, var(--text) 0%, var(--primary) 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 8px;
}
.landing-subtitle { font-size: 1.05rem; color: var(--text-secondary); margin-bottom: 36px; font-weight: 400; }

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border); border-radius: 16px;
    padding: 48px 32px; cursor: pointer; transition: all .3s ease;
    background: var(--bg-white); position: relative;
}
.dropzone:hover, .dropzone.drag-over {
    border-color: var(--primary); background: var(--primary-bg);
    transform: translateY(-2px); box-shadow: var(--shadow-lg);
}
.dropzone-icon {
    width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.5rem; box-shadow: 0 4px 15px rgba(99,102,241,.25);
}
.dropzone-text { font-size: .95rem; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.dropzone-hint { font-size: .8rem; color: var(--text-muted); }
.dropzone input[type="file"] { display: none; }

/* Feature Cards */
.features-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
    margin-top: 36px; text-align: left;
}
.feature-card {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; border-radius: var(--radius-sm);
    background: var(--bg-white); border: 1px solid var(--border-light);
    transition: all var(--transition);
}
.feature-card:hover { border-color: var(--border); box-shadow: var(--shadow-sm); }
.feature-icon {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: .75rem;
}
.feature-label { font-size: .8rem; font-weight: 500; color: var(--text-secondary); }

/* Footer */
.landing-footer {
    padding: 20px 24px; text-align: center;
    border-top: 1px solid var(--border); background: var(--bg-white);
}
.landing-footer a { color: var(--text-muted); font-size: .8rem; margin: 0 10px; }
.landing-footer a:hover { color: var(--primary); }
.landing-footer .copyright { font-size: .75rem; color: var(--text-muted); margin-top: 6px; }

/* ── EDITOR LAYOUT ────────────────────────────────────────── */
.editor { display: flex; flex-direction: column; height: 100vh; }

/* Editor Toolbar */
.editor-toolbar {
    display: flex; align-items: center; gap: 6px;
    padding: 0 16px; height: 52px; background: var(--bg-white);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.toolbar-divider { width: 1px; height: 28px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.toolbar-group { display: flex; gap: 2px; align-items: center; }
.toolbar-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-right: 4px; }

/* Tool Button */
.tool-btn {
    width: 38px; height: 38px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); font-size: .88rem; transition: all var(--transition);
    position: relative;
}
.tool-btn:hover { background: var(--bg); color: var(--text); }
.tool-btn.active {
    background: var(--primary-bg); color: var(--primary);
    box-shadow: inset 0 0 0 1.5px rgba(99,102,241,.2);
}
.tool-btn .tip {
    display: none; position: absolute; bottom: -28px; left: 50%; transform: translateX(-50%);
    background: var(--bg-dark); color: #fff; font-size: .68rem;
    padding: 3px 8px; border-radius: 4px; white-space: nowrap; z-index: 200;
}
.tool-btn:hover .tip { display: block; }

/* Color/Size inputs in toolbar */
.toolbar-color {
    width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--border);
    cursor: pointer; padding: 0; overflow: hidden;
}
.toolbar-color::-webkit-color-swatch-wrapper { padding: 0; }
.toolbar-color::-webkit-color-swatch { border: none; border-radius: 6px; }
.toolbar-range {
    width: 60px; height: 4px; -webkit-appearance: none; appearance: none;
    background: var(--border); border-radius: 2px; outline: none;
}
.toolbar-range::-webkit-slider-thumb {
    -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
    background: var(--primary); cursor: pointer;
}
.toolbar-select {
    padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-xs);
    font-size: .8rem; color: var(--text-secondary); background: var(--bg-white);
}

/* Editor Body */
.editor-body { display: flex; flex: 1; overflow: hidden; }

/* Page Sidebar */
.page-sidebar {
    width: 140px; flex-shrink: 0; background: var(--bg-white);
    border-right: 1px solid var(--border); overflow-y: auto;
    padding: 12px 8px; display: flex; flex-direction: column; gap: 8px;
}
.page-thumb {
    position: relative; cursor: pointer; border-radius: var(--radius-sm);
    border: 2px solid transparent; overflow: hidden; transition: all var(--transition);
    background: #fff;
}
.page-thumb:hover { border-color: var(--border); }
.page-thumb.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99,102,241,.15); }
.page-thumb.deleted { opacity: .3; pointer-events: none; }
.page-thumb img { width: 100%; display: block; border-radius: var(--radius-xs); }
.page-thumb .page-num {
    position: absolute; bottom: 4px; right: 4px;
    background: rgba(0,0,0,.6); color: #fff; font-size: .65rem;
    padding: 1px 6px; border-radius: 4px; font-weight: 600;
}
.page-thumb .page-badge {
    position: absolute; top: 4px; right: 4px;
    background: var(--primary); color: #fff; font-size: .55rem;
    padding: 1px 4px; border-radius: 3px;
}
.page-actions {
    display: flex; gap: 2px; justify-content: center; margin-top: 4px;
}
.page-action-btn {
    width: 26px; height: 26px; border-radius: 6px; font-size: .65rem;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); transition: all var(--transition);
}
.page-action-btn:hover { background: var(--bg); color: var(--text); }
.page-action-btn.danger:hover { background: rgba(239,68,68,.1); color: var(--danger); }

.sidebar-add-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px; border-radius: var(--radius-sm); border: 1px dashed var(--border);
    color: var(--text-muted); font-size: .75rem; font-weight: 500;
    transition: all var(--transition); margin-top: 4px;
}
.sidebar-add-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

/* Canvas Area */
.canvas-area {
    flex: 1; display: flex; align-items: center; justify-content: center;
    background: var(--bg); overflow: hidden; position: relative;
}
.canvas-wrapper {
    position: relative; box-shadow: var(--shadow-xl);
    border-radius: 4px; overflow: hidden;
}
.canvas-wrapper canvas { display: block; }

/* Zoom & Page Bar */
.editor-bottombar {
    display: flex; align-items: center; justify-content: center; gap: 16px;
    padding: 0 20px; height: 40px; background: var(--bg-white);
    border-top: 1px solid var(--border); flex-shrink: 0;
}
.page-indicator { font-size: .82rem; color: var(--text-secondary); font-weight: 500; }
.zoom-controls { display: flex; align-items: center; gap: 4px; }

/* ── PROCESSING OVERLAY ───────────────────────────────────── */
.processing-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,.85);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 1000; backdrop-filter: blur(4px);
}
.processing-spinner {
    width: 48px; height: 48px; border: 3px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin .8s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-text { font-size: .95rem; font-weight: 500; color: var(--text-secondary); }

/* ── COOKIE BANNER ────────────────────────────────────────── */
.cookie-banner {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999;
    background: var(--bg-dark); color: #e2e8f0; padding: 16px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15); animation: slideUp .4s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.cookie-text { font-size: .82rem; line-height: 1.5; flex: 1; }
.cookie-text a { color: var(--primary-light); text-decoration: underline; }
.cookie-actions { display: flex; gap: 8px; flex-shrink: 0; }
.cookie-btn {
    padding: 8px 20px; border-radius: var(--radius-xs); font-size: .82rem;
    font-weight: 600; transition: all var(--transition);
}
.cookie-btn-accept { background: var(--primary); color: #fff; }
.cookie-btn-accept:hover { background: var(--primary-dark); }
.cookie-btn-reject { background: transparent; color: var(--text-muted); border: 1px solid rgba(255,255,255,.15); }
.cookie-btn-reject:hover { background: rgba(255,255,255,.05); }

/* ── UPLOAD PROGRESS ──────────────────────────────────────── */
.upload-progress {
    margin-top: 16px; width: 100%;
}
.progress-bar {
    height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.progress-fill {
    height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 2px; transition: width .3s ease; width: 0%;
}
.progress-text { font-size: .8rem; color: var(--text-muted); margin-top: 6px; }

/* ── RESPONSIVE ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .landing-title { font-size: 2rem; }
    .landing-subtitle { font-size: .9rem; }
    .features-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .feature-card { padding: 10px; }
    .feature-label { font-size: .75rem; }
    .dropzone { padding: 32px 20px; }
    .dropzone-icon { width: 48px; height: 48px; font-size: 1.2rem; }

    .page-sidebar { width: 80px; padding: 8px 4px; }
    .page-actions { display: none; }
    .page-thumb .page-num { font-size: .55rem; padding: 1px 4px; }

    .editor-toolbar { padding: 0 8px; gap: 2px; }
    .tool-btn { width: 34px; height: 34px; font-size: .82rem; }
    .toolbar-divider { margin: 0 2px; }
    .toolbar-label { display: none; }
    .navbar-filename { max-width: 120px; }

    .cookie-banner { flex-direction: column; text-align: center; padding: 14px 16px; }
    .cookie-actions { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .features-grid { grid-template-columns: 1fr 1fr; }
    .navbar { padding: 0 12px; }
    .navbar-brand span { display: none; }
    .landing-hero { padding: 24px 16px; }
    .landing-title { font-size: 1.7rem; }
    .page-sidebar { width: 60px; }
}

/* ══════════════════════════════════════════════════════════
   NEW v3 STYLES — Modal, Font Picker, Undo/Redo, Mobile
   ══════════════════════════════════════════════════════════ */

/* ── Toolbar color wrapper ── */
.toolbar-color-wrap {
    position: relative; display: flex; align-items: center;
    justify-content: center; cursor: pointer;
    width: 32px; height: 32px; border-radius: var(--radius-xs);
    transition: background var(--transition);
}
.toolbar-color-wrap:hover { background: var(--bg); }
.toolbar-color-wrap .toolbar-color {
    position: absolute; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.toolbar-color-wrap .fa-palette { font-size: .9rem; color: var(--text-secondary); }

/* ── Tool disabled ── */
.tool-btn-disabled { opacity: 0.38 !important; cursor: not-allowed !important; }
.tool-btn-disabled:hover { background: transparent !important; }

/* ── Zoom controls ── */
.zoom-controls { display: flex; align-items: center; gap: 2px; }
.zoom-label {
    font-size: .75rem; font-weight: 600; color: var(--text-secondary);
    min-width: 36px; text-align: center;
}
.zoom-btn { width: 28px !important; height: 28px !important; font-size: .75rem !important; }

/* ── Font controls (toolbar) ── */
.font-controls {
    display: flex; align-items: center; gap: 6px;
    border-left: 1px solid var(--border); padding-left: 8px;
}
.font-size-group {
    display: flex; align-items: center; gap: 2px;
    background: var(--bg); border-radius: var(--radius-xs); padding: 2px;
}
.font-size-btn {
    width: 24px; height: 24px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: .65rem; color: var(--text-secondary);
    transition: all var(--transition);
}
.font-size-btn:hover { background: var(--border); color: var(--text); }
.font-size-select {
    height: 24px; padding: 0 4px; font-size: .78rem;
    border: none; background: transparent; color: var(--text);
    cursor: pointer; width: 46px; text-align: center;
}
.font-size-select:focus { outline: none; }

/* ── Font family dropdown ── */
.font-family-wrap { position: relative; }
.toolbar-font-btn {
    height: 28px; padding: 0 10px; border-radius: var(--radius-xs);
    background: var(--bg); border: 1px solid var(--border);
    font-size: .78rem; color: var(--text);
    display: flex; align-items: center; gap: 6px;
    cursor: pointer; transition: all var(--transition); white-space: nowrap;
    max-width: 140px; overflow: hidden;
}
.toolbar-font-btn:hover { background: var(--border-light); border-color: var(--primary); }
.toolbar-font-btn .fas { font-size: .55rem; opacity: 0.6; flex-shrink: 0; }

.font-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 9999;
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
    width: 200px;
}
.font-dropdown-inner {
    max-height: 280px; overflow-y: auto;
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.font-option {
    display: block; width: 100%; text-align: left;
    padding: 8px 12px; border-radius: 6px;
    font-size: .88rem; color: var(--text);
    transition: background var(--transition); cursor: pointer;
}
.font-option:hover { background: var(--bg); }
.font-option.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }

/* ── Signature Modal ── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(15,23,42,.55); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    background: var(--bg-white); border-radius: var(--radius);
    box-shadow: var(--shadow-xl);
    width: 100%; max-width: 560px;
    animation: popIn .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn {
    from { transform: scale(.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal-close {
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: .9rem;
    transition: all var(--transition); cursor: pointer;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px; }
.modal-hint { font-size: .82rem; color: var(--text-secondary); margin-bottom: 12px; }
.modal-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; border-top: 1px solid var(--border); gap: 8px;
}

/* ── Signature canvas ── */
.sig-canvas-wrap {
    border: 2px dashed var(--border); border-radius: var(--radius-sm);
    overflow: hidden; background: #f8fafc;
    cursor: crosshair;
    touch-action: none;
    user-select: none;
}
.sig-canvas-wrap canvas {
    display: block; touch-action: none;
    width: 100% !important; max-width: 480px;
    height: auto !important;
}

/* ── btn-disabled ── */
.btn-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ── Sidebar page item ── */
.sidebar-page-item { margin-bottom: 8px; }

/* ── Tablet breakpoint ── */
@media (max-width: 1024px) {
    .page-sidebar { width: 90px; }
    .editor-toolbar { gap: 2px; padding: 0 8px; flex-wrap: nowrap; overflow-x: auto; }
    .font-controls { gap: 4px; }
    .font-dropdown { width: 180px; }
    .toolbar-font-btn { max-width: 110px; }
    .zoom-label { display: none; }
}

/* ── Mobile improvements ── */
@media (max-width: 768px) {
    .tool-btn { min-width: 40px; min-height: 40px; width: 40px; height: 40px; }
    .editor-toolbar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .font-controls { border-left: none; padding-left: 0; }
    .font-dropdown { position: fixed; left: 12px; right: 12px; width: auto; bottom: 56px; top: auto; }
    .modal-box { max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .sig-canvas-wrap canvas { height: 160px !important; }
    .zoom-controls { display: none; }
    .lang-toggle { flex-shrink: 0; }
    .btn-label { display: none; }
    .page-actions { flex-direction: column; }
    .page-action-btn { min-height: 32px; }
}

@media (max-width: 480px) {
    .editor-toolbar { height: auto; min-height: 48px; padding: 4px 6px; }
    .toolbar-divider { height: 24px; margin: 0 1px; }
    .page-sidebar { width: 58px; }
    .font-size-select { width: 36px; }
}
