/* ==========================================================================
   AgriDoc AI — Scientific Agriculture Manual & PDF Creator
   Styles matching the Reference PDF exactly + Modern Interactive Web Studio
   ========================================================================== */

:root {
    --primary-color: #0E5C4E;        /* Forest Teal */
    --primary-dark: #083E34;
    --primary-light: #E8F3F1;
    --accent-orange: #D35400;
    --accent-gold: #F39C12;
    --bg-app: #0F172A;
    --bg-panel: #1E293B;
    --bg-surface: #334155;
    --text-light: #F8FAFC;
    --text-muted: #94A3B8;
    --border-color: #475569;
    
    /* PDF Document Theme Variables */
    --doc-primary: #0E5C4E;
    --doc-text: #1E293B;
    --doc-heading: #0F3D3E;
    
    /* Callout Colors */
    --callout-purple-bg: #F0EBFC;
    --callout-purple-border: #7E57C2;
    --callout-purple-text: #4527A0;

    --callout-green-bg: #E2F4EA;
    --callout-green-border: #27AE60;
    --callout-green-text: #196F3D;

    --callout-blue-bg: #E1F5FE;
    --callout-blue-border: #0288D1;
    --callout-blue-text: #01579B;

    --callout-yellow-bg: #FEF9E7;
    --callout-yellow-border: #F39C12;
    --callout-yellow-text: #9A7D0A;

    --callout-red-bg: #FDEDEC;
    --callout-red-border: #E74C3C;
    --callout-red-text: #922B21;

    --callout-dark-bg: #0E5C4E;
    --callout-dark-text: #FFFFFF;
}

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

body {
    font-family: 'Inter', 'Noto Sans Devanagari', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-light);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================================
   Header Bar
   ========================================================================== */
.app-header {
    height: 60px;
    background: #111827;
    border-bottom: 1px solid #1F2937;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text h1 {
    font-size: 19px;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    color: #FFFFFF;
    letter-spacing: -0.5px;
}

.logo-text h1 span {
    color: #10B981;
}

.logo-text p {
    font-size: 11px;
    color: #9CA3AF;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.template-selector {
    position: relative;
    display: flex;
    align-items: center;
    background: #1F2937;
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 0 10px;
}

.template-selector i {
    color: #10B981;
    margin-right: 8px;
}

.template-selector select {
    background: transparent;
    border: none;
    color: #F3F4F6;
    padding: 8px 4px;
    font-size: 13px;
    font-weight: 500;
    outline: none;
    cursor: pointer;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #10B981;
    color: #FFFFFF;
}

.btn-primary:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #374151;
    color: #E5E7EB;
}

.btn-secondary:hover {
    background: #4B5563;
}

.btn-accent {
    background: linear-gradient(135deg, #0E5C4E, #10B981);
    color: #FFFFFF;
}

.btn-accent:hover {
    filter: brightness(1.1);
}

.btn-block {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 14px;
}

/* ==========================================================================
   Main Workspace Layout
   ========================================================================== */
.main-container {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

.left-panel {
    width: 440px;
    background: #1E293B;
    border-right: 1px solid #334155;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 20;
}

.left-panel.collapsed {
    width: 0;
    transform: translateX(-100%);
}

.panel-collapse-btn {
    position: absolute;
    top: 15px;
    left: 440px;
    z-index: 30;
    background: #334155;
    color: #FFFFFF;
    border: none;
    border-radius: 0 6px 6px 0;
    width: 22px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.3s ease;
}

.left-panel.collapsed + .panel-collapse-btn {
    left: 0;
}

.panel-header {
    padding: 16px 16px 0 16px;
    border-bottom: 1px solid #334155;
    background: #1E293B;
    position: sticky;
    top: 0;
    z-index: 10;
}

.panel-header h2 {
    font-size: 15px;
    font-weight: 700;
    color: #E2E8F0;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-tabs {
    display: flex;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #94A3B8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    color: #10B981;
    border-bottom-color: #10B981;
    background: rgba(16, 185, 129, 0.08);
}

.tab-content {
    display: none;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

.input-instruction {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    gap: 10px;
    font-size: 12px;
    color: #93C5FD;
    margin-bottom: 16px;
    line-height: 1.4;
}

.input-group {
    margin-bottom: 14px;
}

.input-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #CBD5E1;
    margin-bottom: 6px;
}

.input-group input[type="text"],
.input-group textarea,
.input-group select {
    width: 100%;
    background: #0F172A;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 10px 12px;
    color: #F8FAFC;
    font-size: 13px;
    outline: none;
    transition: border 0.2s;
}

.input-group input[type="text"]:focus,
.input-group textarea:focus,
.input-group select:focus {
    border-color: #10B981;
}

.input-group textarea {
    height: 180px;
    resize: vertical;
    line-height: 1.5;
}

.api-key-box {
    display: flex;
    gap: 6px;
}

.api-key-box input {
    flex: 1;
    background: #0F172A;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 8px 12px;
    color: #FFF;
    font-size: 13px;
}

.btn-sm {
    padding: 8px 12px;
    background: #334155;
    border: none;
    color: #FFF;
    border-radius: 6px;
    cursor: pointer;
}

.color-options {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.color-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
}

.color-dot.active {
    border-color: #FFFFFF;
    transform: scale(1.15);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #CBD5E1;
    margin-bottom: 8px;
    cursor: pointer;
}

/* ==========================================================================
   Right Panel: Live A4 Document Preview
   ========================================================================== */
.preview-panel {
    flex: 1;
    background: #0B1120;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.preview-toolbar {
    height: 48px;
    background: #111827;
    border-bottom: 1px solid #1F2937;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.badge-page-count {
    background: #1F2937;
    border: 1px solid #374151;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    color: #E5E7EB;
}

.badge-page-count b {
    color: #10B981;
}

.text-tip {
    font-size: 12px;
    color: #9CA3AF;
    margin-left: 14px;
}

.btn-tool {
    background: #1F2937;
    border: 1px solid #374151;
    color: #E5E7EB;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    margin-left: 6px;
}

.btn-tool:hover {
    background: #374151;
}

.document-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 30px 20px 60px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ==========================================================================
   A4 Page Styling (Matching Reference PDF Pixel-for-Pixel)
   ========================================================================== */
.a4-page-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
    align-items: center;
}

.a4-page {
    width: 210mm;
    min-height: 297mm;
    background: #FFFFFF;
    color: var(--doc-text);
    padding: 20mm 18mm 18mm 18mm;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    border-radius: 4px;
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.page-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.page-footer-area {
    margin-top: auto;
    padding-top: 15px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.page-number-tag {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
}

/* Page Break Decorator on Web */
.page-break-line {
    width: 100%;
    text-align: center;
    font-size: 11px;
    color: #6B7280;
    position: relative;
    margin: 10px 0;
}

/* ==========================================================================
   Document Content Blocks & Typography (Scientific PDF Rules)
   ========================================================================== */

/* Super Category Header */
.doc-super-header {
    text-align: center;
    color: var(--accent-orange);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 12px;
}

/* Main Manual Title */
.doc-main-title {
    color: var(--doc-heading);
    font-size: 24px;
    font-weight: 800;
    text-align: center;
    line-height: 1.3;
    margin-bottom: 6px;
}

/* Subtitle */
.doc-subtitle {
    text-align: center;
    color: var(--doc-primary);
    font-size: 15px;
    font-weight: 600;
    font-style: italic;
    margin-bottom: 14px;
}

/* Teal Accent Divider */
.doc-accent-divider {
    height: 3px;
    background: var(--doc-primary);
    width: 100%;
    margin-bottom: 22px;
    border-radius: 2px;
}

/* Numbered Section Header (e.g. 1 पहचान — पहले पक्का करें कि Thrips ही है) */
.doc-section-header {
    background: #E8F3F1;
    border-left: 4px solid var(--doc-primary);
    padding: 10px 14px;
    border-radius: 0 6px 6px 0;
    margin: 20px 0 14px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.doc-section-badge {
    background: var(--doc-primary);
    color: #FFFFFF;
    font-weight: 800;
    font-size: 14px;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.doc-section-title {
    color: var(--doc-heading);
    font-size: 17px;
    font-weight: 700;
    flex: 1;
}

/* Sub-headings */
.doc-subheading {
    font-size: 16px;
    font-weight: 700;
    color: var(--doc-heading);
    margin: 16px 0 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Standard Paragraph */
.doc-p {
    font-size: 14.5px;
    line-height: 1.65;
    color: #2D3748;
    margin-bottom: 12px;
}

/* Bullet Lists */
.doc-bullet-list {
    margin: 10px 0 16px 8px;
    list-style-type: none;
}

.doc-bullet-list li {
    font-size: 14.5px;
    line-height: 1.6;
    color: #2D3748;
    margin-bottom: 6px;
    position: relative;
    padding-left: 20px;
}

.doc-bullet-list li::before {
    content: "•";
    color: var(--doc-primary);
    font-size: 18px;
    position: absolute;
    left: 4px;
    top: -2px;
}

/* ==========================================================================
   Callout Boxes (Purple Fact, Green Test, Blue Science, Warnings, etc.)
   ========================================================================== */
.doc-callout {
    border-radius: 6px;
    padding: 14px 16px;
    margin: 16px 0;
    position: relative;
}

/* 💜 Purple: रोचक तथ्य (Fact / Note) */
.callout-purple {
    background-color: var(--callout-purple-bg);
    border-left: 4px solid var(--callout-purple-border);
}

.callout-purple .callout-title {
    color: var(--callout-purple-text);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

/* 💚 Mint Green: किसान का आसान Field Test / Kisan Rule */
.callout-green {
    background-color: var(--callout-green-bg);
    border-left: 4px solid var(--callout-green-border);
}

.callout-green .callout-title {
    color: var(--callout-green-text);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

/* 💙 Sky Blue: वैज्ञानिक कारण / Scientific Concept */
.callout-blue {
    background-color: var(--callout-blue-bg);
    border-left: 4px solid var(--callout-blue-border);
}

.callout-blue .callout-title {
    color: var(--callout-blue-text);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

/* ⚠️ Amber/Yellow: सावधानी / Warning */
.callout-yellow {
    background-color: var(--callout-yellow-bg);
    border-left: 4px solid var(--callout-yellow-border);
}

.callout-yellow .callout-title {
    color: var(--callout-yellow-text);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

/* ❌ Red/Pink: गलत सोच / गलत तरीका */
.callout-red {
    background-color: var(--callout-red-bg);
    border-left: 4px solid var(--callout-red-border);
}

.callout-red .callout-title {
    color: var(--callout-red-text);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

/* 🌲 Dark Green: अंतिम बात (Summary Takeaway Card) */
.callout-dark {
    background-color: var(--callout-dark-bg);
    color: var(--callout-dark-text);
    border-radius: 8px;
    padding: 24px 20px;
    margin: 20px 0;
    text-align: center;
}

.callout-dark .callout-title {
    color: #F1C40F;
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 12px;
}

.callout-dark p {
    color: #E2E8F0;
    font-size: 15px;
    line-height: 1.6;
}

/* ==========================================================================
   Scientific Agriculture Tables
   ========================================================================== */
.doc-table-container {
    margin: 18px 0;
    overflow-x: auto;
    width: 100%;
}

.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    border: 1px solid #CBD5E1;
}

.doc-table th {
    background: var(--doc-primary);
    color: #FFFFFF;
    padding: 10px 12px;
    font-weight: 700;
    text-align: left;
    border: 1px solid #0B4B3F;
}

.doc-table td {
    padding: 10px 12px;
    border: 1px solid #E2E8F0;
    color: #2D3748;
}

.doc-table tr:nth-child(even) {
    background-color: #F8FAFC;
}

/* Badges inside table (IRAC Group etc) */
.badge-irac {
    background: #1E293B;
    color: #FFFFFF;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    display: inline-block;
    font-size: 12px;
}

/* ==========================================================================
   Flowchart & Life Cycle Steps
   ========================================================================== */
.doc-flowchart {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: 20px 0;
}

.flow-step-node {
    background: var(--doc-primary);
    color: #FFFFFF;
    padding: 8px 24px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 14.5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.flow-arrow {
    font-size: 16px;
    color: var(--accent-orange);
    font-weight: 800;
}

/* ==========================================================================
   Text Highlights (Bold & Highlights)
   ========================================================================== */
.hl-yellow { background-color: #FFF59D; padding: 1px 4px; border-radius: 2px; }
.hl-green { background-color: #C8E6C9; padding: 1px 4px; border-radius: 2px; }
.hl-cyan { background-color: #B2EBF2; padding: 1px 4px; border-radius: 2px; }
.hl-orange { background-color: #FFE0B2; padding: 1px 4px; border-radius: 2px; }
.hl-red { background-color: #FFCDD2; padding: 1px 4px; border-radius: 2px; }

/* ==========================================================================
   Image Blocks inside Document
   ========================================================================== */
.doc-image-block {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.doc-image-block img {
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    max-width: 100%;
    object-fit: cover;
}

.doc-image-caption {
    font-size: 12px;
    color: #64748B;
    margin-top: 6px;
    font-style: italic;
    text-align: center;
}

/* ==========================================================================
   Interactive Block Controls (Hover Actions & Editing)
   ========================================================================== */
.editable-block {
    position: relative;
    border: 1px dashed transparent;
    border-radius: 4px;
    transition: all 0.2s;
}

.editable-block:hover {
    border-color: rgba(16, 185, 129, 0.4);
    background-color: rgba(16, 185, 129, 0.02);
}

.block-hover-actions {
    position: absolute;
    right: 0;
    top: -26px;
    display: none;
    background: #1E293B;
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 2px 6px;
    z-index: 50;
    gap: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.editable-block:hover .block-hover-actions {
    display: flex;
}

.action-btn-mini {
    background: transparent;
    border: none;
    color: #CBD5E1;
    font-size: 11px;
    padding: 3px 6px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.action-btn-mini:hover {
    background: #334155;
    color: #10B981;
}

.action-btn-mini.btn-danger:hover {
    color: #EF4444;
}

/* ==========================================================================
   Floating Text Formatting Toolbar
   ========================================================================== */
.floating-text-tools {
    position: absolute;
    display: none;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 6px;
    padding: 4px 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    z-index: 200;
    gap: 6px;
    align-items: center;
}

.floating-text-tools button {
    background: transparent;
    border: none;
    color: #F3F4F6;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.floating-text-tools button:hover {
    background: #374151;
}

.tool-divider {
    width: 1px;
    height: 18px;
    background: #4B5563;
    display: inline-block;
}

.btn-hl {
    font-weight: 800;
    font-size: 12px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal-backdrop.show {
    display: flex;
}

.modal-card {
    background: #1E293B;
    border: 1px solid #334155;
    border-radius: 12px;
    width: 480px;
    max-width: 90vw;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #334155;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 16px;
    color: #FFF;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: transparent;
    border: none;
    color: #94A3B8;
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.modal-or {
    text-align: center;
    margin: 12px 0;
    position: relative;
}

.modal-or span {
    background: #1E293B;
    padding: 0 10px;
    color: #94A3B8;
    font-size: 12px;
}

.modal-or::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 100%;
    height: 1px;
    background: #334155;
    z-index: -1;
}

.image-preview-box {
    margin-top: 12px;
    max-height: 160px;
    border-radius: 6px;
    overflow: hidden;
    background: #0F172A;
    display: flex;
    justify-content: center;
}

.image-preview-box img {
    max-height: 160px;
    object-fit: contain;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid #334155;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ==========================================================================
   Print & High-Fidelity PDF Export Media Query
   ========================================================================== */
@media print {
    body {
        background: #FFFFFF !important;
        color: #000000 !important;
        overflow: visible !important;
        height: auto !important;
    }

    .app-header,
    .left-panel,
    .panel-collapse-btn,
    .preview-toolbar,
    .floating-text-tools,
    .modal-backdrop,
    .block-hover-actions {
        display: none !important;
    }

    .preview-panel,
    .document-viewport {
        padding: 0 !important;
        margin: 0 !important;
        background: #FFFFFF !important;
        overflow: visible !important;
    }

    .a4-page-container {
        gap: 0 !important;
    }

    .a4-page {
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 15mm 15mm 15mm 15mm !important;
        width: 100% !important;
        height: 297mm !important;
        page-break-after: always !important;
        break-after: page !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .editable-block {
        border: none !important;
        background: none !important;
    }
}
