/* ═══════════════════════════════════════════════════════════════
   UNIFIED RESPONSIVE UI - SOP GENERATOR
   Mobile-First CSS Architecture
   ═══════════════════════════════════════════════════════════ */

/* ============ RESET & BASE ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Outfit', sans-serif;
    --primary-gradient: radial-gradient(circle at 10% 20%, #10b981 0%, #047857 100%);
    --accent-gradient: radial-gradient(circle at 10% 20%, #0ea5e9 0%, #0284c7 100%);
    --primary-color: #10b981;
    --primary-dark: #059669;
    --accent-color: #0284c7;
    --bg-light: #f3f8f5;
    --bg-white: #ffffff;
    --text-dark: #0f2e1e;
    --text-medium: #1c3f2d;
    --text-light: #476657;
    --border-color: rgba(16, 185, 129, 0.08);
    --shadow-sm: 0 1px 2px rgba(15, 46, 30, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 46, 30, 0.06);
    --shadow-lg: 0 12px 24px rgba(15, 46, 30, 0.08);
    --shadow-hover: 0 16px 28px rgba(16, 185, 129, 0.08), 0 4px 12px rgba(15, 46, 30, 0.03);
    --ring: rgba(16, 185, 129, 0.35);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.15s ease, border-color 0.15s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        --font-display: 'Outfit', sans-serif;
        --primary-gradient: radial-gradient(circle at 10% 20%, #10b981 0%, #047857 100%);
        --accent-gradient: radial-gradient(circle at 10% 20%, #38bdf8 0%, #0284c7 100%);
        --primary-color: #10b981;
        --primary-dark: #047857;
        --accent-color: #38bdf8;
        --bg-light: #0b0f17;
        --bg-white: #111622;
        --text-dark: #f1f5f9;
        --text-medium: #cbd5e1;
        --text-light: #94a3b8;
        --border-color: rgba(52, 211, 153, 0.10);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.4);
        --shadow-hover: 0 16px 28px rgba(52, 211, 153, 0.15), 0 4px 12px rgba(0, 0, 0, 0.25);
        --ring: rgba(52, 211, 153, 0.45);
    }
}

body {
    font-family: var(--font-sans);
    background: var(--bg-light);
    min-height: 100vh;
    line-height: 1.6;
    letter-spacing: -0.011em;
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
}

/* ============ MOBILE-FIRST LAYOUT (TABS VIEW) ============ */

/* Header */
.app-header {
    background: var(--primary-gradient);
    color: white;
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.header-content h1 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.03em;
    text-wrap: balance;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.header-content p {
    font-size: 13px;
    opacity: 0.95;
    margin-top: 4px;
    letter-spacing: -0.01em;
}

.version-badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    margin-top: 6px;
}

.credit-link {
    display: none; /* Hide on mobile to save space */
}

/* Tab Navigation (Mobile Bottom Bar) */
.tab-navigation {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    display: flex;
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.tab-btn {
    flex: 1;
    border: none;
    background: none;
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    color: var(--primary-color);
}

.tab-btn::before {
    font-size: 18px;
}

/* Main Layout Area */
.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 60px; /* Leave space for mobile bottom tab bar */
}

.main-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Tab Panels Visibility */
.tab-panel {
    display: none;
    flex-direction: column;
    padding: 16px;
    width: 100%;
}

.tab-panel.active {
    display: flex;
}

/* Controls Panel (Form Side) */
.controls-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Card Styling */
.control-section {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.control-section::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top, rgba(16, 185, 129, 0.04), transparent 70%);
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
}

.control-section:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-color);
}

.control-section:hover::before {
    opacity: 1;
}

.control-section:active {
    transform: translateY(0) scale(0.985);
}

.section-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-dark);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.section-icon {
    font-size: 18px;
}

/* Form Styling */
.form-group {
    margin-bottom: 12px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-medium);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-dark);
    background-color: var(--bg-white);
    transition: var(--transition);
}

.form-group input:focus-visible,
.form-group select:focus-visible,
.form-group textarea:focus-visible {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--ring);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* Toggle Switches */
.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-light);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-item label {
    font-size: 13px;
    color: var(--text-medium);
    font-weight: 500;
    margin-bottom: 0;
    text-transform: none;
}

/* Switch UI */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e0;
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .slider {
    background-color: var(--primary-color);
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(20px);
}

/* Preview Wrapper (Mobile Zoom Handling) */
.preview-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #e2e8f0;
    padding: 12px 6px;
    overflow-x: auto;
}

#preview-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    overflow-x: auto;
}

#preview {
    width: 210mm !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    height: auto !important;
    padding: 20mm !important;
    background: white !important;
    box-shadow: var(--shadow-md);
    transform: scale(0.42);
    transform-origin: top center;
    margin-bottom: -600px; /* Offset the scale shrink space */
}

#preview.fluid-preview {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 24px 16px !important;
    box-shadow: none !important;
    transform: none !important;
    margin-bottom: 0 !important;
}

/* ═══════════════════════════════════════════════════════════
   DOCUMENT PREVIEW TYPOGRAPHY & LAYOUT (Times New Roman)
   ═══════════════════════════════════════════════════════════ */
#preview, 
#preview * {
    font-family: "Times New Roman", Times, Georgia, serif !important;
}

#preview h1 {
    font-size: 18pt !important;
    font-weight: bold !important;
    color: #0f172a !important;
    text-align: center !important;
    margin-top: 0 !important;
    margin-bottom: 18px !important;
    line-height: 1.2 !important;
}

#preview h2 {
    font-size: 12pt !important;
    font-weight: bold !important;
    text-transform: uppercase !important;
    color: #1e293b !important;
    border-left: 4px solid #475569 !important;
    padding-left: 8px !important;
    margin-top: 20px !important;
    margin-bottom: 10px !important;
    line-height: 1.3 !important;
}

#preview h3 {
    font-size: 11pt !important;
    font-weight: bold !important;
    color: #334155 !important;
    margin-top: 14px !important;
    margin-bottom: 6px !important;
    line-height: 1.3 !important;
}

#preview p,
#preview li {
    font-size: 11pt !important;
    line-height: 1.45 !important;
    color: #1a202c !important;
    text-align: justify !important;
}

#preview p {
    margin-bottom: 8px !important;
}

#preview ul,
#preview ol {
    margin-bottom: 10px !important;
    padding-left: 20px !important;
}

#preview li {
    margin-bottom: 5px !important;
}

/* Premium Academic Table Styling */
#preview table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 14px 0 !important;
    border: none !important;
}

#preview th,
#preview td {
    padding: 6px 8px !important;
    text-align: left !important;
    vertical-align: top !important;
    border: none !important;
}

#preview th {
    background-color: #1e293b !important;
    color: #ffffff !important;
    font-weight: bold !important;
    font-size: 10.5pt !important;
    border-bottom: 2px solid #0f172a !important;
}

#preview td {
    font-size: 10pt !important;
    border-bottom: 1px solid #cbd5e0 !important;
    color: #2d3748 !important;
}

#preview tbody tr:nth-child(even) td {
    background-color: #f8fafc !important;
}

#preview tbody tr:hover td {
    background-color: #f1f5f9 !important;
}

#preview hr {
    border: none !important;
    border-top: 1px solid #cbd5e0 !important;
    margin: 16px 0 !important;
    height: 0 !important;
}

/* Action Bar / Bottom Buttons */
.bottom-action-bar {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-bottom: 12px;
}

.action-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-primary:active,
.btn-secondary:active,
.action-btn:active {
    transform: translateY(0) scale(0.97);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background: var(--bg-white);
    color: var(--text-dark);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* Status Bar */
.status-bar {
    display: none; /* Hide on mobile */
}


/* ═══════════════════════════════════════════════════════════════
   DESKTOP RESPONSIVE LAYOUT (UNLOCKED SPLIT VIEW)
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
    body {
        padding: 24px;
        background: var(--primary-gradient);
        height: 100vh;
        overflow: hidden;
    }

    /* Outer Wrapper Card */
    .app-container {
        width: 100%;
        max-width: 1680px;
        margin: 0 auto;
        background: var(--bg-white);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-xl);
        overflow: hidden;
        margin-bottom: 0;
        height: 100%;
    }

    /* Unhide Top Header Elements & Style Desktop */
    .app-header {
        padding: 24px 32px;
        text-align: left;
    }

    .header-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .header-content h1 {
        font-size: 24px;
        justify-content: flex-start;
    }

    .header-content p {
        font-size: 14px;
    }

    .credit-link {
        display: block;
        font-size: 13px;
        color: rgba(255, 255, 255, 0.85);
        text-decoration: none;
        transition: var(--transition);
        margin-top: 6px;
    }

    .credit-link:hover {
        color: white;
        text-decoration: underline;
    }

    /* Hide Mobile Navigation elements */
    .tab-navigation {
        display: none;
    }

    /* Side-by-Side Dual Pane Layout */
    .main-layout {
        display: grid;
        grid-template-columns: 420px 1fr;
        grid-template-rows: 1fr;
        height: calc(100% - 140px); /* Subtract header and footer height */
        overflow: hidden;
    }

    /* Force both panels to display side-by-side */
    .tab-panel {
        display: flex !important;
        width: auto !important;   /* Override mobile width:100% so grid controls sizing */
        min-width: 0;             /* Prevent grid blowout */
        padding: 0;
        height: 100%;
        overflow: hidden;
    }

    /* Ensure preview tab is always visible on desktop, not tab-toggled */
    #tab-preview {
        display: flex !important;
    }

    /* Left Edit Sidebar Styling */
    .controls-panel {
        background: var(--bg-light);
        border-right: 1px solid var(--border-color);
        overflow-y: auto;
        padding: 24px;
        height: 100%;
    }

    .control-section {
        border-radius: var(--radius-sm);
        flex-shrink: 0;
    }

    /* Right Preview Sidebar Styling */
    .preview-panel {
        background: #525659;
        overflow-y: auto;
        padding: 24px;
        height: 100%;
        position: relative;
    }

    #preview-wrapper {
        height: 100%;
        overflow-y: auto;
        display: block;
    }

    #preview {
        transform: none; /* No scale shrink needed on desktop */
        margin: 0 auto 30px auto;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    }

    /* Move Export Buttons into Toolbar */
    .bottom-action-bar {
        position: absolute;
        top: 24px;
        right: 24px;
        z-index: 10;
        width: auto;
        margin-bottom: 0;
        gap: 8px;
    }

    .action-btn {
        width: 140px;
        padding: 10px 16px;
        font-size: 13px;
        border-radius: var(--radius-sm);
    }

    /* Status Bar Footer */
    .status-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--bg-light);
        border-top: 1px solid var(--border-color);
        padding: 10px 24px;
        font-size: 12px;
        color: var(--text-light);
    }

    .status-indicator {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .status-dot {
        width: 8px;
        height: 8px;
        background-color: #48bb78;
        border-radius: 50%;
        animation: pulse 2s infinite;
    }
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(72, 187, 120, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(72, 187, 120, 0); }
}

/* ═══════════════════════════════════════════════════════════
   LIVE WYSIWYG & TOUCH ACTION BAR STYLING
   ═══════════════════════════════════════════════════════════ */
[contenteditable="true"] {
    outline: none;
    transition: all 0.2s ease;
    cursor: text;
    border-bottom: 1px dashed transparent;
}

[contenteditable="true"]:hover {
    background-color: rgba(99, 102, 241, 0.04);
    border-bottom: 1px dashed rgba(99, 102, 241, 0.3);
}

[contenteditable="true"]:focus {
    background-color: rgba(99, 102, 241, 0.08);
    border-bottom: 1px dashed var(--primary-color);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
    border-radius: 4px;
    padding: 2px 4px;
}

/* Empty placeholder styles */
[contenteditable="true"]:empty::before {
    content: attr(data-placeholder);
    color: #a0aec0;
    font-style: italic;
    pointer-events: none;
}

#preview [contenteditable="true"]:empty:not(:focus)::before {
    content: "" !important;
    display: none !important;
}

/* Inline lists support */
#preview li[contenteditable="true"] {
    padding: 4px 6px;
    border-radius: 4px;
}

#preview li[contenteditable="true"]:hover {
    background-color: rgba(99, 102, 241, 0.04);
}

/* Global WYSIWYG Actions Bar */
#wysiwyg-action-bar {
    position: absolute;
    display: none;
    z-index: 9999;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 30px;
    box-shadow: var(--shadow-lg);
    padding: 6px 10px;
    gap: 8px;
    align-items: center;
    pointer-events: auto;
    transform: translate(-50%, -100%);
    margin-top: -8px;
}

#wysiwyg-action-bar.active {
    display: flex;
}

.wysiwyg-action-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--bg-light);
    color: var(--text-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    touch-action: manipulation;
}

.wysiwyg-action-btn:hover {
    background-color: var(--border-color);
    transform: translateY(-1px);
}

.wysiwyg-action-btn:active {
    background-color: #cbd5e0;
    transform: translateY(1px);
}

.wysiwyg-action-btn.btn-delete {
    background-color: #fff5f5;
    color: #e53e3e;
}

.wysiwyg-action-btn.btn-delete:hover {
    background-color: #fed7d7;
}

/* Hide action bar during print/export */
@media print {
    #wysiwyg-action-bar {
        display: none !important;
    }
    [contenteditable="true"] {
        border-bottom: none !important;
        background-color: transparent !important;
        box-shadow: none !important;
        padding: 0 !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE-SPECIFIC CUSTOMIZATIONS (ZOOM & ACCESSIBILITY)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    /* Prevent iOS browser auto-zoom on input focus */
    .form-group input[type="text"],
    .form-group input[type="date"],
    .form-group select,
    .form-group textarea {
        font-size: 16px !important;
    }

    /* Larger Touch Targets for Inline Editing Action Bar */
    .wysiwyg-action-btn {
        width: 48px !important;
        height: 48px !important;
        font-size: 18px !important;
    }
    
    /* Disable manual resizing of textareas to avoid scroll locks */
    .form-group textarea {
        resize: none !important;
    }
}

/* Zoom Toggle Button styling & desktop hiding */
#zoom-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 768px) {
    #zoom-toggle-btn {
        display: none !important;
    }
}
