/* Google Fonts - Inter & Outfit */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

:root {
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --border-color: #cbd5e1;
    --primary-color: #009fe3;
    --primary-hover: #0087c1;
    --secondary-bg: #f8fafc;
    --table-header-bg: #e2e8f0;
    --table-section-bg: #d1d5db;
    --shadow-color: rgba(15, 23, 42, 0.06);
    
    /* Document Colors (fixed for print output look) */
    --doc-bg: #ffffff;
    --doc-text: #000000;
    --doc-border: #000000;
    --doc-section-bg: #d3d3d3; /* Dark gray in original image */
    --doc-row-gray: #f2f2f2;
}

/* Dark Mode Variables for the Screen UI */
body.dark-mode {
    --bg-color: #0b0f19;
    --card-bg: #151f32;
    --text-color: #f1f5f9;
    --border-color: #24354f;
    --secondary-bg: #0b0f19;
    --shadow-color: rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Page Layout Wrapper */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Left Sidebar Styles */
.sidebar {
    width: 260px;
    background-color: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: 2px 0 8px var(--shadow-color);
    z-index: 90;
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.sidebar-logo {
    max-height: 55px;
    display: block;
    object-fit: contain;
}

.sidebar-menu {
    flex: 1;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-item {
    width: 100%;
    background: none;
    border: none;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.9rem;
    text-align: left;
    border-left: 4px solid transparent;
    transition: all 0.2s ease;
    outline: none;
}

.menu-item:hover {
    background-color: var(--secondary-bg);
}

.menu-item.active {
    background-color: #eff6ff;
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

body.dark-mode .menu-item.active {
    background-color: #1e293b;
    color: #38bdf8;
    border-left-color: #38bdf8;
}

.menu-icon {
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    text-align: center;
    color: #64748b;
}

/* Right Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevents flex-children overflowing */
}

/* Header Toolbar Styles */
header.toolbar {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 6px -1px var(--shadow-color);
    transition: background-color 0.3s, border-color 0.3s;
}

.brand-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

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

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

.btn-secondary {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background-color: var(--secondary-bg);
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* Theme Toggle Switch */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
    margin-left: 5px;
}

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

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

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

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

input:checked + .slider:before {
    transform: translateX(22px);
}

/* Page Container (A4 desk view on Screen) */
.document-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 30px;
    overflow: auto;
}

/* Base A4 Layout styles */
.a4-page {
    background-color: var(--doc-bg);
    color: var(--doc-text);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1), 0 5px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid #cbd5e1;
    position: relative;
    font-size: 8.5pt;
    line-height: 1.2;
    display: none; /* Hidden by default */
}

.a4-page.active {
    display: block; /* Shown only when active */
}

/* Portrait vs Landscape settings */
.a4-page[data-orientation="portrait"] {
    width: 210mm;
    min-height: 297mm;
    padding: 12mm;
}

.a4-page[data-orientation="landscape"] {
    width: 297mm;
    min-height: 210mm;
    padding: 10mm;
}

/* Form / Table Structure */
.form-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    margin-bottom: 8px;
}

.form-table td, .form-table th {
    border: 1px solid var(--doc-border);
    padding: 4px 6px;
    vertical-align: middle;
    position: relative;
}

.form-table th {
    background-color: #f1f5f9;
    font-weight: 700;
}

/* Colors for specific cells */
.bg-gray-section {
    background-color: var(--doc-section-bg) !important;
    font-weight: 700;
    text-transform: uppercase;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    font-size: 9pt;
    letter-spacing: 0.5px;
    padding: 5px 0 !important;
}

.bold-label {
    font-weight: 700;
}

.center-text {
    text-align: center;
}

.right-text {
    text-align: right;
}

/* Editable Inputs inside Document cells */
.cell-input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-family: 'Inter', sans-serif;
    font-size: 8.5pt;
    color: #1d4ed8; /* Premium blue color on screen for typed values */
    font-weight: 500;
    resize: none;
}

/* Highlight editable inputs on hover/focus */
.a4-page td:hover .cell-input {
    background-color: #f8fafc;
}

.cell-input:focus {
    background-color: #eff6ff;
}

textarea.cell-input {
    min-height: 38px;
    display: block;
    padding: 2px 0;
}

/* Checkbox Styling */
.checkbox-container {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 8pt;
    user-select: none;
}

.checkbox-container input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border: 1px solid var(--doc-border);
    border-radius: 1px;
    outline: none;
    background-color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.checkbox-container input[type="checkbox"]:checked::after {
    content: "X";
    font-size: 9px;
    font-weight: 700;
    color: black;
    position: absolute;
}

/* Header Cells styling */
.row-header {
    height: 60px;
}

.logo-cell {
    text-align: center;
}

.title-cell {
    font-size: 11.5pt;
    font-weight: 800;
    text-align: center;
    line-height: 1.3;
}

.code-cell {
    font-size: 11pt;
    font-weight: 700;
    text-align: center;
}

/* Document Footer Section */
.footer-container {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
    border-top: 2px solid var(--doc-border);
    padding-top: 8px;
    font-size: 8pt;
    font-weight: 700;
}

.footer-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.footer-input {
    border: none;
    border-bottom: 1px dashed #64748b;
    outline: none;
    font-family: 'Inter', sans-serif;
    font-size: 8.5pt;
    color: #1d4ed8;
    font-weight: 600;
    padding: 0 4px;
    width: 150px;
    background: transparent;
}

.footer-input:focus {
    border-bottom-color: var(--primary-color);
    background-color: #eff6ff;
}

/* KT-1 (Test Matrisi) specific styles */
.matrix-table {
    font-size: 8.5pt !important;
}

.matrix-table th, .matrix-table td {
    padding: 6px 4px !important;
    text-align: center;
}

.matrix-table th {
    font-size: 8.5pt;
    background-color: #e2e8f0;
}

.matrix-table .cell-input {
    font-size: 8.5pt;
    text-align: center;
}

.matrix-table select.cell-input {
    text-align-last: center;
    cursor: pointer;
}

.btn-delete-row {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.btn-delete-row:hover {
    color: #dc2626;
    transform: scale(1.1);
}

/* KT-3 specific styles */
#form-kt-3 textarea.cell-input {
    min-height: 28px;
}

/* Auto-save notification toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #0f172a;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* Print CSS Configurations */
@page portrait-page {
    size: A4 portrait;
    margin: 8mm;
}

@page landscape-page {
    size: A4 landscape;
    margin: 5mm;
}

@media print {
    /* Set page layouts according to orientation attribute */
    #form-kt-1 {
        page: landscape-page;
    }
    
    #form-kt-2, #form-kt-3, #form-kt-4 {
        page: portrait-page;
    }

    body {
        background-color: white !important;
        color: black !important;
        min-height: auto;
    }
    
    .no-print {
        display: none !important;
    }
    
    .app-layout {
        display: block !important;
    }
    
    .main-content {
        display: block !important;
    }

    .document-container {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        display: block !important;
    }
    
    .a4-page {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        min-height: auto !important;
    }
    
    .a4-page.active {
        display: block !important;
    }
    
    /* Make other forms stay hidden during print */
    .a4-page:not(.active) {
        display: none !important;
    }
    
    .cell-input {
        color: black !important;
        background: transparent !important;
    }

    .footer-input {
        color: black !important;
        border-bottom: none !important;
    }

    /* Make KT-1 smaller inside print mode so it fits A4 perfectly */
    .matrix-table {
        font-size: 6.8pt !important;
    }
    .matrix-table th, .matrix-table td {
        padding: 2px 1px !important;
    }
    .matrix-table th {
        font-size: 6.8pt;
    }
    .matrix-table .cell-input {
        font-size: 6.8pt !important;
    }

    /* Print backgrounds */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Saved Forms Sidebar section */
.sidebar-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    padding: 16px 20px 8px 20px;
    border-top: 1px solid var(--border-color);
}

.saved-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 250px;
}

/* Custom scrollbar for saved list */
.saved-list-container::-webkit-scrollbar {
    width: 4px;
}

.saved-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.saved-list-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

body.dark-mode .saved-list-container::-webkit-scrollbar-thumb {
    background: #475569;
}

.saved-item {
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: left;
    transition: all 0.2s ease;
    color: var(--text-color);
    outline: none;
}

.saved-item:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
    transform: translateX(2px);
}

body.dark-mode .saved-item:hover {
    background-color: #1e293b;
    border-color: #475569;
}

.saved-item-title {
    font-weight: 600;
    font-size: 0.8rem;
}

.saved-item-meta {
    font-size: 0.7rem;
    color: #64748b;
    display: flex;
    justify-content: space-between;
}

.saved-item-loading {
    padding: 16px;
    font-size: 0.8rem;
    color: #64748b;
    text-align: center;
    font-style: italic;
}

