@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@200;300;400;500;700;800;900&family=Cairo:wght@200..1000&family=IBM+Plex+Sans+Arabic:wght@100;200;300;400;500;600;700&display=swap');

:root {
    /* Premium Color Palette */
    --primary-color: #0b4619;
    /* Deep Forest Green */
    --primary-light: #18632d;
    --accent-color: #d4af37;
    /* Metallic Gold */
    --accent-hover: #bfa035;
    --text-dark: #1a1a1a;
    --text-light: #666;
    --bg-main: #f4f7f6;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;

    /* Shadows & Effects */
    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: 1px solid rgba(255, 255, 255, 0.5);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Dimensions */
    --sidebar-width: 400px;
}

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

body {
    font-family: 'IBM Plex Sans Arabic', 'Cairo', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    display: flex;
    direction: rtl;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* =========================================
   Layout Structure
   ========================================= */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, #063110 100%);
    color: white;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgdmlld0JveD0iMCAwIDQwIDQwIj48ZyBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0wIDQwaDQwVjBIOFYwaDMydjQwSDBWMHoiIGZpbGw9IiNmZmZmZmYiIGZpbGwtb3BhY2l0eT0iMC4wNSIvPjwvZz48L3N2Zz4=');
    opacity: 0.1;
}

.sidebar-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: #fff;
}

.sidebar-header p {
    font-size: 0.85rem;
    opacity: 0.8;
}

.branding-icon {
    margin-bottom: 8px;
    color: var(--accent-color);
}

.sidebar-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: #fff;
}

/* Form Elements */
.section-title {
    font-size: 0.95rem;
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
}

.input-group {
    margin-bottom: 1.25rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s;
    background-color: #fafafa;
}

.form-control:focus {
    border-color: var(--primary-color);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(11, 70, 25, 0.1);
}

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

/* Compact Items List for Sidebar */
.items-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    /* Remove gap for table-like look */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.item-row.compact {
    padding: 8px;
    border: none;
    /* Reset standard border */
    border-bottom: 1px solid #f0f0f0;
    margin: 0;
    border-radius: 0;
    transition: background 0.1s;
    display: grid;
    grid-template-columns: 25px 1fr;
    gap: 8px;
    align-items: center;
}

.item-row.compact:last-child {
    border-bottom: none;
}

.item-row.compact:hover {
    background: #f8fafc;
    box-shadow: none;
}

.item-header-compact {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.item-badge {
    font-size: 0.65rem;
    color: #94a3b8;
    background: transparent;
    padding: 0;
}

.item-inputs-compact {
    display: grid;
    grid-template-columns: 3fr 1fr 1.5fr;
    /* Desc | Qty | Price */
    gap: 5px;
}

.item-inputs-compact .form-control {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    height: 32px;
    /* Force compact height */
}

/* Specific input sizing */
.qty-input {
    text-align: center;
}

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

.btn-remove-sm {
    background: none;
    border: none;
    color: #ef4444;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 0.5;
    padding: 2px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.9rem;
    width: 100%;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px rgba(11, 70, 25, 0.2);
}

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

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

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-outline-dashed {
    background: transparent;
    border: 1px dashed var(--border-color);
    color: var(--primary-color);
}

.btn-outline-dashed:hover {
    background: #f0fdf4;
    border-color: var(--primary-color);
}

.storage-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

/* Preview Area */
.preview-area {
    flex: 1;
    background-color: #525659;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    background-image: radial-gradient(#6a6d70 1px, transparent 1px);
    background-size: 20px 20px;
}

.a4-page {
    width: 210mm;
    height: 297mm;
    background: white;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    padding: 0;
    /* Let internal containers handle padding */
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.a4-content {
    padding: 8mm 10mm;
    /* Reduced from 10mm 12mm */
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2;
    /* Ensure content takes full height but allows us to measure overflow children */
    overflow: hidden;
}

/* Helper for JS Pagination */
.page-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* We will check scrollHeight vs clientHeight here */
}

/* Paper Watermark */
.paper-watermark {
    position: absolute;
    inset: 0;
    background-image: url('1.png');
    /* Assuming 1.png is the logo/watermark */
    background-position: center;
    background-repeat: no-repeat;
    background-size: 80%;
    /* Slightly larger */
    opacity: 0.08;
    /* Increased from 0.04 for better visibility */
    z-index: 0;
    /* Ensure it is behind everything */
    pointer-events: none;
}

/* Document Design */
.doc-header {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
    text-align: center;
}

.company-logo img {
    display: none;
    /* Hide if not used, or center it if used */
}

.company-info {
    text-align: center;
    color: var(--text-dark);
    width: 100%;
}

.company-info h1 {
    font-family: 'Tajawal', sans-serif;
    font-size: 2.4rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.company-details {
    font-size: 0.95rem;
    color: #4a5568;
    line-height: 1.6;
    margin-top: 5px;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    /* Spacing between address and phone */
}

.detail-item {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.detail-item .icon {
    color: var(--primary-color);
    opacity: 0.8;
}

.doc-title {
    background: var(--primary-color);
    color: white;
    text-align: center;
    padding: 8px;
    border-radius: 20px;
    width: fit-content;
    margin: 0 auto 15px auto;
    font-weight: 700;
    padding-inline: 40px;
    font-size: 0.95rem;
    /* Slightly smaller */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.client-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 15px;
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.meta-row {
    display: flex;
    justify-content: space-between;
}

.meta-label {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 0.9rem;
}

.meta-value {
    color: #333;
    font-weight: 500;
}

/* Table Design */
.quote-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.quote-table th {
    background: var(--primary-color);
    color: white;
    padding: 6px 8px;
    /* Reduced from 10px */
    font-size: 0.8rem;
    border: 1px solid var(--primary-color);
}

.quote-table td {
    padding: 6px 8px;
    /* Reduced from 10px */
    border: 1px solid #e2e8f0;
    font-size: 0.85rem;
    /* Reduced from 0.9rem */
    vertical-align: middle;
}

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

.col-id {
    width: 5%;
    text-align: center;
}

.col-desc {
    width: 55%;
}

.col-qty {
    width: 10%;
    text-align: center;
}

.col-price {
    width: 15%;
    text-align: center;
}

.col-total {
    width: 15%;
    text-align: center;
    font-weight: 600;
}

.totals-section {
    margin-top: 10px;
    margin-bottom: 10px;
}

.total-row {
    display: flex;
    justify-content: flex-end;
    gap: 20px;
    padding: 6px 10px;
    font-size: 1rem;
    font-weight: 700;
    border-top: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.notes-terms {
    margin-top: 10px;
    font-size: 0.8rem;
    color: #444;
}

.notes-terms h4 {
    color: var(--primary-color);
    margin-bottom: 5px;
    font-size: 0.95rem;
}

.doc-footer {
    margin-top: auto;
    border-top: 1px solid #e2e8f0;
    padding-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 0.75rem;
    color: #888;
}

/* Login Overlay (Premium) */
#login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #051908 0%, #0f3d18 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.login-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 3rem;
    border-radius: 24px;
    text-align: center;
    width: 360px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
}

.login-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent-color), #fcd34d);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3e2600;
    font-size: 1.5rem;
    box-shadow: 0 10px 15px -3px rgba(212, 175, 55, 0.3);
}

.login-title {
    color: white;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.login-subtitle {
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.pin-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.5rem;
    letter-spacing: 0.5rem;
    text-align: center;
    border-radius: 12px;
    padding: 1rem;
    width: 100%;
    margin-bottom: 1.5rem;
    transition: all 0.3s;
}

.pin-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.btn-login {
    background: var(--accent-color);
    color: #3e2600;
    width: 100%;
    padding: 1rem;
    border-radius: 12px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-login:hover {
    background: #eab308;
    transform: translateY(-2px);
}

.rights-footer {
    position: absolute;
    bottom: 20px;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.8rem;
}

/* Print Styles */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    html,
    body {
        height: auto !important;
        overflow: visible !important;
        background: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .app-container {
        display: block !important;
        width: 100% !important;
        height: auto !important;
    }

    .sidebar,
    #login-overlay,
    .no-print {
        display: none !important;
    }

    .preview-area {
        padding: 0 !important;
        background: white !important;
        display: block !important;
        margin: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    .a4-page {
        margin: 0 !important;
        box-shadow: none !important;
        page-break-after: always !important;
        break-after: page !important;
        width: 210mm !important;
        height: 297mm !important;
        display: flex !important;
        position: relative !important;
    }

    .a4-page:last-of-type {
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    .paper-watermark {
        display: block !important;
        -webkit-print-color-adjust: exact !important;
    }

    /* Ensure table rows don't break mid-row */
    .quote-table tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
}