/* Hariyali Industries - Delivery Challan Generator
   Corporate Theme: Navy Blue + Corporate Blue + Slate Grey
   Primary Header/Sidebar: #0F172A
   Action Button: #2563EB
   Secondary/Neutral: #64748B
   Background: #F8FAFC
   Success: #10B981
*/

:root {
    --primary: #4169E1;
    --action: #2563EB;
    --secondary: #64748B;
    --bg: #F8FAFC;
    --success: #10B981;
    --white: #FFFFFF;
    --border: #E2E8F0;
    --text: #1E293B;
    --light-text: #94A3B8;
    --danger: #EF4444;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

#app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--primary);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.logo-img {
    width: 100px;
    height: auto;
    margin-bottom: 12px;
    border-radius: 8px;
}

.logo-text {
    font-size: 16px;
    font-weight: 600;
    opacity: 0.9;
}

.nav-menu {
    list-style: none;
    padding: 16px 0;
}

.nav-menu li {
    padding: 4px 16px;
}

.nav-btn {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}

.nav-btn.active {
    background: var(--action);
    color: var(--white);
    font-weight: 500;
}

/* Main Content */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 32px;
    max-width: calc(100% - 260px);
}

.section {
    display: none;
}

.section.active {
    display: block;
}

h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--primary);
}

h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--primary);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--white);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    text-align: center;
}

.stat-number {
    font-size: 36px;
    font-weight: 700;
    color: var(--action);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--secondary);
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

/* Buttons */
.btn-primary {
    padding: 12px 24px;
    background: var(--action);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #1D4ED8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.btn-secondary {
    padding: 12px 24px;
    background: var(--white);
    color: var(--secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-small {
    padding: 6px 16px;
    background: var(--action);
    color: var(--white);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.btn-icon {
    width: 36px;
    height: 36px;
    background: var(--action);
    color: var(--white);
    border: none;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-danger {
    padding: 6px 12px;
    background: var(--danger);
    color: var(--white);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
    position: relative;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    background: var(--white);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--action);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.field-hint {
    display: block;
    font-size: 12px;
    color: var(--action);
    margin-top: 4px;
    font-weight: 500;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 32px 0 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* Party Section */
.party-section {
    background: var(--white);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 24px;
}

.party-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
}

.party-input-group input {
    flex: 1;
}

.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.dropdown-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.dropdown-item:hover,
.dropdown-item.dropdown-active {
    background: var(--bg);
}

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

.party-details {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
}

.party-details.hidden {
    display: none;
}

/* PO List */
.po-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.po-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 16px;
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Items List */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.item-row {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

.item-row-header {
    display: grid;
    grid-template-columns: 1fr 120px 120px 120px 40px;
    gap: 12px;
    align-items: end;
}

.item-row-header .form-group {
    margin-bottom: 0;
}

.item-row-header input[readonly] {
    background: var(--bg);
    color: var(--secondary);
}

.item-plate-option {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.item-plate-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--action);
}

.plate-row {
    margin-top: 12px;
    padding: 16px;
    background: #F1F5F9;
    border-radius: 8px;
}

.plate-row .form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.plate-row .form-group {
    margin-bottom: 0;
}

.plate-row input[readonly] {
    background: var(--bg);
    color: var(--secondary);
}

/* Data Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--primary);
    color: var(--white);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tr:hover {
    background: var(--bg);
}

.data-table td:last-child {
    display: flex;
    gap: 8px;
}

/* Search Bar */
.search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.search-bar input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}

/* Form Card */
.form-card {
    background: var(--white);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 24px;
    max-width: 600px;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
    position: relative;
}

.close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 28px;
    cursor: pointer;
    color: var(--secondary);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}

/* ============================================ */
/* PRINT CHALLAN STYLES - Screen Preview        */
/* ============================================ */
.print-challan {
    max-width: 210mm;
    margin: 0 auto;
    background: var(--white);
    position: relative;
    font-family: 'Times New Roman', Times, serif;
}

.print-page {
    position: relative;
    padding: 15mm;
    box-sizing: border-box;
    min-height: 277mm;
    page-break-after: always;
    break-after: page;
}

.print-header {
    text-align: center;
    margin-bottom: 16px;
    border-bottom: 2px solid #000;
    padding-bottom: 12px;
}

.print-header h2 {
    font-size: 22pt;
    font-weight: bold;
    margin-bottom: 4px;
    color: #000;
}

.print-header .company-info {
    font-size: 10pt;
    color: #333;
    line-height: 1.5;
}

.print-header h3 {
    font-size: 14pt;
    font-weight: bold;
    margin-top: 8px;
    color: #000;
}

.print-meta {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
    padding: 10px;
    background: #f5f5f5;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 10pt;
}

.print-party {
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 11pt;
}

.print-party h4 {
    font-size: 11pt;
    color: #333;
    margin-bottom: 6px;
    text-transform: uppercase;
    font-weight: bold;
}

.print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 11pt;
}

.print-table th,
.print-table td {
    border: 1px solid #000;
    padding: 8px 10px;
    font-size: 11pt;
    vertical-align: middle;
}

.print-table th {
    background: #e0e0e0;
    font-weight: bold;
    text-align: center;
}

.print-table td {
    text-align: left;
}

.print-table td:nth-child(1),
.print-table td:nth-child(3),
.print-table td:nth-child(4),
.print-table td:nth-child(5) {
    text-align: center;
}

/* Print footer - fixed at bottom of page */
.print-footer {
    margin-top: auto;
    padding-top: 20px;
}

.vehicle-info {
    font-size: 11pt;
    margin-bottom: 12px;
    font-weight: bold;
}

.terms {
    font-size: 9pt;
    color: #333;
    margin-bottom: 30px;
    line-height: 1.6;
    border: 1px solid #ccc;
    padding: 10px;
    background: #fafafa;
}

.signatures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 60px;
    margin-top: 40px;
}

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

.signature-line {
    border-top: 1px solid #000;
    padding-top: 8px;
    font-size: 11pt;
    font-weight: bold;
    margin-top: 50px;
}

/* ============================================ */
/* UNIVERSAL PRINT STYLES - Fallback            */
/* ============================================ */
@media print {
    @page {
        size: A4 portrait;
        margin: 10mm;
    }

    * {
        animation: none !important;
        transition: none !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* Hide everything except modal */
    body > *:not(.modal) {
        display: none !important;
    }

    .modal {
        display: block !important;
        position: static !important;
        background: white !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    .modal.active {
        display: block !important;
    }

    .modal-content {
        position: static !important;
        width: 210mm !important;
        max-width: 210mm !important;
        min-height: 297mm !important;
        max-height: none !important;
        margin: 0 auto !important;
        padding: 10mm !important;
        background: white !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        overflow: visible !important;
    }

    /* Hide UI elements */
    .close,
    .modal-actions,
    .no-print {
        display: none !important;
    }

    /* Print challan container */
    .print-challan {
        max-width: 100% !important;
        width: 100% !important;
    }

    .print-page {
        width: 190mm !important;
        min-height: 277mm !important;
        padding: 0 !important;
        page-break-after: always !important;
        break-after: page !important;
        position: relative !important;
    }

    .print-page:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
    }

    /* Table styles for print */
    .print-table {
        width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: auto !important;
    }

    .print-table thead {
        display: table-header-group !important;
    }

    .print-table tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .print-table th,
    .print-table td {
        border: 1px solid #000 !important;
        padding: 6px 8px !important;
        font-size: 10pt !important;
    }

    /* Footer stays together */
    .print-footer {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .terms {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .signatures {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Force colors */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color: #000 !important;
    }

    body {
        font-family: 'Times New Roman', Times, serif !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
        background: white !important;
    }

    /* Page break helpers */
    .page-break-after {
        page-break-after: always !important;
        break-after: page !important;
    }
}

/* Page break helper classes */
.page-break-after {
    page-break-after: always;
    break-after: page;
}

/* Utility */
.mt-4 {
    margin-top: 24px;
}

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

.hidden {
    display: none !important;
}

/* Login Screen */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--primary);
    padding: 20px;
}

.login-card {
    background: var(--white);
    padding: 40px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .logo-img {
    width: 80px;
    height: auto;
    border-radius: 8px;
    margin-bottom: 16px;
}

.login-logo h2 {
    font-size: 22px;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-logo p {
    color: var(--secondary);
    font-size: 14px;
}

.login-btn {
    width: 100%;
    margin-top: 8px;
}

.login-links {
    text-align: center;
    margin-top: 16px;
}

.login-links a {
    color: var(--action);
    font-size: 13px;
    text-decoration: none;
}

.login-links a:hover {
    text-decoration: underline;
}

.form-hint {
    font-size: 13px;
    color: var(--secondary);
    margin-bottom: 12px;
}

.token-box {
    background: #F1F5F9;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    margin-bottom: 20px;
}

.token-box code {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--action);
    background: var(--white);
    padding: 8px 16px;
    border-radius: 6px;
    margin: 8px 0;
    word-break: break-all;
}

/* Sidebar Footer / User Info */
.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info {
    margin-bottom: 12px;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--white);
}

.user-role {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
}

.logout-btn {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--white);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Role Badges */
.role-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.role-badge.admin {
    background: #DBEAFE;
    color: #1D4ED8;
}

.role-badge.operator {
    background: #D1FAE5;
    color: #047857;
}

.light-text {
    color: var(--light-text);
    font-size: 13px;
}

/* Tab Bar */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: -2px;
}

.tab-btn:hover {
    color: var(--action);
}

.tab-btn.active {
    color: var(--action);
    border-bottom-color: var(--action);
}

/* Toast / Alert */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 24px;
    background: var(--success);
    color: var(--white);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: relative;
        height: auto;
    }

    .main-content {
        margin-left: 0;
        max-width: 100%;
    }

    #app {
        flex-direction: column;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .item-row-header {
        grid-template-columns: 1fr;
    }

    .print-meta {
        grid-template-columns: 1fr;
    }

    .signatures {
        grid-template-columns: 1fr;
    }
}