/* ============================================
   CSS VARIABLES & RESET
   ============================================ */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --border: #e2e8f0;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.5;
}

/* ============================================
   LAYOUT CONTAINERS
   ============================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

main.container {
    width: 100%;
}

/* ============================================
   NAVIGATION
   ============================================ */
nav {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    margin-bottom: 2rem;
}

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

nav ul {
    list-style: none;
    display: flex;
    gap: 2rem;
    margin: 0;
    padding: 0;
}

nav a {
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
}

nav a.active {
    color: var(--primary);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-success {
    background: #10b981;
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: #ef4444;
    color: white;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.btn-sm {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    cursor: pointer;
    background: white;
    transition: background-color 0.2s;
}

.btn-sm:hover {
    background: #f8fafc;
}

.btn-sm.btn-danger {
    color: #ef4444;
    border-color: #fecaca;
}

.btn-sm.btn-danger:hover {
    background: #fee2e2;
}

/* ============================================
   FORM STYLES
   ============================================ */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-family: inherit;
    font-size: 1rem;
}

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

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

/* ============================================
   GENERATOR PAGE LAYOUT
   ============================================ */
.generator-container {
    width: 100%;
    overflow: visible;
}

.form-section {
    width: 100%;
    max-width: 800px;
}

.form-section .form-group:not(.items-container .form-group) {
    max-width: 500px;
}


/* ============================================
   TABLES
   ============================================ */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.form-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
    background: white;
    border: none;
    table-layout: auto;
}

.form-table th {
    background: #f1f5f9;
    padding: 0.75rem 0.5rem;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #64748b;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.form-table th:nth-child(1) { width: 130px; } /* Ch. No. & Dt. */
.form-table th:nth-child(2) { width: 200px; } /* Item */
.form-table th:nth-child(3) { width: 100px; } /* HSN */
.form-table th:nth-child(4) { width: 90px; }  /* Rate */
.form-table th:nth-child(5) { width: 70px; }  /* Qty */
.form-table th:nth-child(6) { width: 70px; }  /* Unit */
.form-table th:nth-child(7) { width: 70px; }  /* GST % */
.form-table th:nth-child(8) { width: 100px; } /* Total */
.form-table th:nth-child(9) { width: 50px; }  /* Actions */

.form-table td {
    padding: 0.5rem;
    border-bottom: 1px solid #f1f5f9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-table td:nth-child(2) {
    white-space: normal;
    word-wrap: break-word;
}

.form-table tr:hover {
    background: #f8fafc;
}

.form-input-sm {
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 0.875rem;
    width: 100%;
    transition: border-color 0.2s;
}

.form-input-sm:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.item-total-cell {
    font-weight: 600;
    font-size: 0.9rem;
}

.item-selectors {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    align-items: center;
}

.item-selectors select {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
}

/* ============================================
   INVOICES PAGE
   ============================================ */
.invoices-container {
    width: 100%;
}

.invoices-container .table-responsive {
    overflow-y: visible;
    overflow-x: visible;
    overflow: visible;
}

.invoices-container .form-table {
    display: table;
    width: 100%;
    table-layout: auto;
}

.invoices-container .form-table th:nth-child(1),
.invoices-container .form-table td:nth-child(1) {
    width: 120px;
    min-width: 120px;
}

.invoices-container .form-table th:nth-child(2),
.invoices-container .form-table td:nth-child(2) {
    width: 100px;
    min-width: 100px;
    max-width: 100px;
}

.invoices-container .form-table th:nth-child(3),
.invoices-container .form-table td:nth-child(3) {
    width: auto;
    min-width: 150px;
}

.invoices-container .form-table th:nth-child(4),
.invoices-container .form-table td:nth-child(4) {
    width: 120px;
    min-width: 120px;
}

.invoices-container .form-table th:nth-child(5),
.invoices-container .form-table td:nth-child(5) {
    width: 180px;
    min-width: 180px;
}

.invoices-container tbody {
    display: table-row-group;
}

/* ============================================
   SECTION HEADERS
   ============================================ */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.5rem;
}

.section-header h1,
.section-header h3 {
    margin: 0;
}

/* ============================================
   INVOICE SUMMARY
   ============================================ */
.invoice-summary {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 1rem 0;
    border: 1px solid var(--border);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.summary-row.total {
    font-weight: 600;
    font-size: 1.1rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 2px solid var(--border);
    margin-bottom: 0;
}

.actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* ============================================
   DIRECTORY PAGE
   ============================================ */
.directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
}

.admin-form {
    background: #f1f5f9;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.list-item {
    background: white;
    padding: 1rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.item-info strong {
    display: block;
    font-size: 1.1rem;
}

.item-info p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    color: #64748b;
    line-height: 1.2;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
}

/* ============================================
   BILL PAPER / PREVIEW
   ============================================ */
.bill-paper {
    background: white;
    width: 210mm;
    min-height: 297mm;
    padding: 2mm;
    margin: 1rem auto;
    border: 1px solid #000;
    color: #000;
    font-family: 'Times New Roman', serif;
    font-size: 9pt;
    line-height: normal;
}

.preview-section .bill-paper {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 1.5mm;
    font-size: 8pt;
    min-height: auto;
}

.bill-top-header {
    display: flex;
    justify-content: space-between;
    font-size: 8pt;
    border-bottom: 1px solid #000;
    padding-bottom: 2px;
}

.bill-main-header {
    text-align: center;
    padding: 10px 0;
}

.bill-main-header h1 {
    font-size: 24pt;
    margin: 0;
    font-weight: bold;
    letter-spacing: 1px;
}

.bill-main-header p {
    margin: 2px 0;
}

.bill-subheader-line {
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    text-align: center;
    font-weight: bold;
    padding: 2px 0;
    text-transform: uppercase;
    margin: 5px 0;
}

.bill-middle-section {
    display: grid;
    grid-template-columns: 1fr 200px;
    border-bottom: 1px solid #000;
}

.bill-billed-to {
    border-right: 1px solid #000;
    padding: 5px;
}

.bill-invoice-info {
    padding: 5px;
}

.bill-invoice-info h2 {
    font-size: 11pt;
    text-align: center;
    border-bottom: 1px solid #000;
    margin: -5px -5px 5px -5px;
    padding: 5px 0;
}

.bill-info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.bill-table {
    width: 100%;
    border-collapse: collapse;
}

.bill-table th,
.bill-table td {
    border: 1px solid #000;
    padding: 4px;
    text-align: center;
    vertical-align: top;
}

.bill-table th {
    font-size: 9pt;
    height: 30px;
    vertical-align: middle;
}

.bill-table .desc-col {
    text-align: left;
    width: 40%;
}

.bill-table .no-col {
    width: 30px;
}

.bill-table .amount-col {
    width: 80px;
}

.bill-summary-grid {
    display: grid;
    grid-template-columns: 60% 40%;
    border-top: none;
    border-bottom: 1px solid #000;
}

.tax-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt;
}

.tax-table th,
.tax-table td {
    border: 1px solid #000;
    padding: 2px;
    text-align: center;
}

.total-amt-box {
    border-left: 1px solid #000;
    padding: 5px;
}

.amt-in-words {
    border: 1px solid #000;
    border-top: none;
    padding: 5px;
    font-weight: bold;
}

.bill-footer {
    font-size: 8pt;
    margin-top: 10px;
}

.bill-signature {
    text-align: right;
    margin-top: 30px;
}

.placeholder {
    text-align: center;
    color: #94a3b8;
    padding: 2rem;
}

/* ============================================
   MODAL
   ============================================ */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    width: 90%;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    padding-bottom: 10px;
}

.modal-footer {
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.close {
    font-size: 28px;
    cursor: pointer;
    color: #64748b;
}

.close:hover {
    color: var(--text);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1024px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    @page {
        margin: 0;
        size: A4;
    }
    
    html, body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }
    
    /* Hide everything except the preview modal parent and the modal itself when modal is open */
    body.modal-open > *:not(#preview-modal) {
        display: none !important;
        visibility: hidden !important;
    }
    
    #preview-modal {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: auto !important;
        background: white !important;
        display: block !important;
        visibility: visible !important;
        z-index: 999999 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    
    .modal-content {
        position: relative !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
        background: white !important;
    }
    
    .modal-header,
    .modal-footer,
    .close {
        display: none !important;
        visibility: hidden !important;
    }
    
    #modal-bill-preview,
    .bill-paper {
        border: none !important;
        margin: 0 auto !important;
        padding: 2mm !important;
        width: 210mm !important;
        min-height: 297mm !important;
        page-break-after: always !important;
        box-shadow: none !important;
        background: white !important;
        position: relative !important;
        display: block !important;
        visibility: visible !important;
    }
}
