/* ==========================================================================
   STYLE.CSS - MODERN DESKTOP-FIRST & MOBILE-FRIENDLY UI
   ========================================================================== */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;
    --radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f1f5f9;
    color: var(--slate-800);
    line-height: 1.5;
    font-size: 14px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* =============================================================
   NAVIGATION BAR
   ============================================================= */
.navbar {
    background: #ffffff;
    border-bottom: 1px solid var(--slate-200);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: var(--slate-900);
    text-decoration: none;
}
.brand-badge {
    background: var(--primary);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 9999px;
    text-transform: uppercase;
}
.navbar-menu {
    display: flex;
    align-items: center;
    gap: 16px;
}
.nav-link {
    color: var(--slate-600);
    font-weight: 500;
    font-size: 13.5px;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: all 0.15s ease;
    text-decoration: none;
}
.nav-link:hover, .nav-link.active {
    color: var(--primary);
    background: var(--primary-light);
    text-decoration: none;
}
.user-menu-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--slate-100);
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 500;
}
.mode-guest-pill {
    background: #fef3c7;
    color: #92400e;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.mode-auth-pill {
    background: #dcfce7;
    color: #166534;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* =============================================================
   MAIN APP LAYOUT (DESKTOP-FIRST SPLIT VIEW)
   ============================================================= */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 65px);
}
.editor-sidebar {
    width: 48%;
    min-width: 460px;
    max-width: 650px;
    background: #ffffff;
    border-right: 1px solid var(--slate-200);
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.preview-column {
    flex: 1;
    background: #cbd5e1;
    overflow-y: auto;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}
.preview-toolbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}
.preview-toolbar button, .preview-toolbar select {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 4px;
}
.preview-toolbar button:hover {
    background: rgba(255, 255, 255, 0.2);
}
.preview-scale-wrapper {
    transform-origin: top center;
    transition: transform 0.2s ease;
}

/* Mobile Tabs Switcher */
.mobile-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-top: 1px solid var(--slate-200);
    z-index: 1000;
    padding: 8px;
}
.mobile-tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    font-weight: 600;
    font-size: 13px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.mobile-tab-btn.active {
    background: var(--primary);
    color: #ffffff;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
    .app-container {
        height: auto;
        flex-direction: column;
        padding-bottom: 70px;
    }
    .editor-sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        border-right: none;
    }
    .preview-column {
        width: 100%;
        padding: 16px 8px;
    }
    .sheet-a4 {
        width: 100% !important;
        min-height: auto;
        padding: 14mm 10mm;
        box-shadow: var(--shadow);
    }
    .mobile-tabs {
        display: flex;
        gap: 8px;
    }
    .editor-sidebar.mobile-hidden {
        display: none !important;
    }
    .preview-column.mobile-hidden {
        display: none !important;
    }
}

/* =============================================================
   FORM CARDS & ACCORDIONS
   ============================================================= */
.form-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}
.form-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--slate-100);
}
.form-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--slate-900);
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.form-grid-full {
    grid-column: span 2;
}
@media (max-width: 640px) {
    .form-grid, .form-grid-3 {
        grid-template-columns: 1fr;
    }
    .form-grid-full {
        grid-column: span 1;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 10px;
}
.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
}
.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--slate-300);
    border-radius: 6px;
    background: #ffffff;
    color: var(--slate-800);
    transition: all 0.15s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea.form-control {
    resize: vertical;
    min-height: 60px;
}

/* Document Type Radio Pills */
.type-selector-pills {
    display: flex;
    background: var(--slate-100);
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}
.type-pill-btn {
    flex: 1;
    text-align: center;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--slate-600);
    transition: all 0.15s ease;
}
.type-pill-btn.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Theme Thumbnails & Selector */
.theme-select-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
@media (max-width: 640px) {
    .theme-select-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
.theme-pill-option {
    border: 2px solid var(--slate-200);
    border-radius: 6px;
    padding: 8px 4px;
    text-align: center;
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 600;
    transition: all 0.15s;
    background: #ffffff;
}
.theme-pill-option:hover {
    border-color: var(--primary);
}
.theme-pill-option.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* Color Picker Row */
.brand-colors-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 9999px;
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px var(--slate-300);
    transition: transform 0.15s ease;
}
.color-swatch:hover, .color-swatch.active {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px var(--slate-800);
}
.custom-color-input {
    width: 32px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--slate-300);
    border-radius: 4px;
    cursor: pointer;
}

/* =============================================================
   DYNAMIC ITEMS TABLE IN EDITOR
   ============================================================= */
.editor-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
}
.editor-items-table th {
    background: var(--slate-100);
    padding: 8px 6px;
    font-size: 11px;
    text-align: left;
    color: var(--slate-600);
    text-transform: uppercase;
}
.editor-items-table td {
    padding: 6px 4px;
    vertical-align: middle;
}
.btn-del-item {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
}
.btn-del-item:hover {
    background: #fee2e2;
}

/* =============================================================
   BUTTONS
   ============================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}
.btn-primary {
    background: var(--primary);
    color: #ffffff;
}
.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-success {
    background: var(--success);
    color: #ffffff;
}
.btn-success:hover {
    background: #15803d;
}
.btn-outline {
    background: #ffffff;
    border-color: var(--slate-300);
    color: var(--slate-700);
}
.btn-outline:hover {
    background: var(--slate-50);
    border-color: var(--slate-400);
}
.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
}
.btn-block {
    width: 100%;
}

/* =============================================================
   NOTICES & SPAM ALERTS
   ============================================================= */
.alert-spam-box {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 4px solid #f59e0b;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 13px;
    color: #92400e;
    line-height: 1.5;
    margin-bottom: 16px;
}
.alert-spam-box strong {
    color: #78350f;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    background: #ffffff;
    border-radius: 8px;
    padding: 12px 18px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    border-left: 4px solid var(--primary);
    animation: slideUp 0.25s ease-out;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* =============================================================
   DASHBOARD & ADMIN TABLES
   ============================================================= */
.dashboard-container {
    max-width: 1200px;
    margin: 24px auto;
    padding: 0 20px;
    width: 100%;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
.stat-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card .val {
    font-size: 24px;
    font-weight: 800;
    color: var(--slate-900);
    margin-top: 4px;
}
.stat-card .lbl {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-500);
    text-transform: uppercase;
}

.table-responsive {
    overflow-x: auto;
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.data-table th {
    background: var(--slate-50);
    padding: 12px 16px;
    font-weight: 700;
    color: var(--slate-700);
    text-align: left;
    border-bottom: 1px solid var(--slate-200);
}
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--slate-100);
    vertical-align: middle;
}
.badge-status {
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
}
.badge-paid { background: #dcfce7; color: #15803d; }
.badge-unpaid { background: #fee2e2; color: #b91c1c; }
.badge-draft { background: #f1f5f9; color: #475569; }

/* Signature Pad Canvas */
.signature-canvas {
    border: 2px dashed var(--slate-300);
    border-radius: 6px;
    background: #ffffff;
    touch-action: none;
    cursor: crosshair;
}
