/* ==========================================================================
   SRPV LOGISTICS - BILLING SYSTEM STYLES
   Full Support for Courier Docket Tax Invoice, Transport Bill & Credit Note
   Strict 20-Row Pagination, Hostinger Dashboard, and High-Resolution PDF
   ========================================================================== */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #f1f5f9;
    color: #0f172a;
    font-size: 13px;
    height: 100vh;
    overflow: hidden;
}

/* App Header & Navigation */
.app-header {
    background: #1e3a8a;
    color: white;
    padding: 8px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #172554;
    height: 52px;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-section h1 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand-section .badge {
    background: #3b82f6;
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.tab-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12.5px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

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

.tab-btn.active {
    background: white;
    color: #1e3a8a;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

.db-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.15);
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
}

.status-dot.offline {
    background: #f59e0b;
}

.status-dot.error {
    background: #ef4444;
}

/* App Main Body */
.app-container {
    display: flex;
    height: calc(100vh - 52px);
    overflow: hidden;
}

.tab-view {
    display: none;
    width: 100%;
    height: 100%;
}

.tab-view.active {
    display: flex;
}

/* ==========================================================================
   TAB 1: BILL GENERATOR & PREVIEW
   ========================================================================== */
.sidebar {
    width: 420px;
    min-width: 400px;
    background: white;
    padding: 18px;
    overflow-y: auto;
    border-right: 1px solid #cbd5e1;
    box-shadow: 2px 0 6px rgba(0,0,0,0.04);
    z-index: 5;
}

.sidebar h2 {
    font-size: 14px;
    margin-top: 16px;
    margin-bottom: 8px;
    color: #1e293b;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar h2:first-of-type {
    margin-top: 0;
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 3px;
}

.form-group input, 
.form-group select, 
.form-group textarea {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 12.5px;
    font-family: inherit;
    background: #ffffff;
    color: #0f172a;
    transition: border 0.15s;
}

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

.form-group textarea {
    resize: vertical;
    min-height: 48px;
}

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

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

/* Date Range Filter Box */
.filter-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 14px;
}

.filter-box-title {
    font-weight: 700;
    font-size: 12px;
    color: #166534;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.filter-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

/* Item Entry Form in Sidebar */
.item-row {
    background: #f8fafc;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 8px;
    position: relative;
}

.item-row .remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fca5a5;
    border-radius: 4px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
}

.item-row .remove-btn:hover {
    background: #dc2626;
    color: white;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 13px;
}

.btn.primary {
    background: #2563eb;
    color: white;
}

.btn.primary:hover {
    background: #1d4ed8;
}

.btn.success {
    background: #16a34a;
    color: white;
}

.btn.success:hover {
    background: #15803d;
}

.btn.outline {
    background: transparent;
    border: 1px solid #2563eb;
    color: #2563eb;
}

.btn.outline:hover {
    background: #eff6ff;
}

.btn.outline-secondary {
    background: white;
    border: 1px solid #cbd5e1;
    color: #334155;
}

.btn.outline-secondary:hover {
    background: #f1f5f9;
}

.btn.sm {
    padding: 5px 8px;
    font-size: 11.5px;
}

.btn-group {
    display: flex;
    gap: 8px;
}

.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }

/* Main Preview Area */
.main-preview {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #cbd5e1;
}

/* ==========================================================================
   BILL LAYOUT & PAGINATION (A4 STANDARD)
   Width: 794px (~8.27 in) - Height: 1123px (~11.69 in)
   Calibrated for exact 20 rows per page
   ========================================================================== */
#bill-preview {
    width: 794px;
    margin: 0 auto;
}

.bill-page-wrapper {
    background: white;
    width: 794px;
    height: 1123px;
    padding: 24px 28px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    margin-bottom: 30px;
    box-sizing: border-box;
    page-break-inside: avoid;
    break-inside: avoid;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.rendering-pdf .bill-page-wrapper {
    margin: 0 !important;
    box-shadow: none !important;
    width: 794px !important;
    height: 1123px !important;
    page-break-after: auto !important;
    break-after: auto !important;
}

.page-break {
    page-break-after: always;
    break-after: page;
}

/* Common Table Container */
.bill-table-container {
    width: 100%;
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    border: 1.5px solid #000;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #fff;
}

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

.bill-table-container td, 
.bill-table-container th {
    border: 1px solid #000;
    padding: 2.5px 4px;
    color: #000;
}

/* Header Sections */
.top-header-td {
    padding: 5px 8px;
    border-bottom: 1.5px solid #000;
}

.top-header-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 11px;
    line-height: 1.3;
}

.top-header-title {
    font-size: 16px;
    font-weight: 800;
    text-transform: uppercase;
    text-decoration: underline;
    letter-spacing: 0.5px;
    text-align: center;
}

.company-logo-section {
    text-align: center;
    margin-top: 3px;
    margin-bottom: 2px;
}

.company-logo-img {
    height: 52px;
    width: auto;
    object-fit: contain;
    margin-bottom: 1px;
}

.company-title-text {
    font-size: 21px;
    font-weight: 900;
    letter-spacing: 2px;
    margin: 0;
    color: #1e3a8a;
}

.company-address-text {
    font-size: 10.5px;
    margin: 1px 0;
    line-height: 1.25;
}

/* Client & Invoice Meta Info */
.info-row td {
    vertical-align: top;
    padding: 5px 8px;
    border-bottom: 1.5px solid #000;
}

.client-box {
    width: 62%;
    border-right: 1.5px solid #000;
}

.invoice-box {
    width: 38%;
}

.client-name-bold {
    font-weight: 800;
    font-size: 12.5px;
    margin-bottom: 2px;
}

.client-address-text {
    font-size: 10.5px;
    white-space: pre-wrap;
    line-height: 1.25;
    margin-bottom: 4px;
}

.meta-line {
    font-size: 10.5px;
    line-height: 1.35;
}

.meta-line strong {
    font-weight: 700;
}

/* Courier & Transport Items Table */
.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th {
    background: #fdfdfd;
    font-weight: 800;
    font-size: 10.5px;
    text-align: center;
    padding: 3.5px 2px;
    border-bottom: 1.5px solid #000;
    line-height: 1.2;
}

.items-table td {
    font-size: 10.5px;
    text-align: center;
    padding: 2px 2px;
    height: 20px;
    border-bottom: 1px solid #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.items-table td.align-left {
    text-align: left;
    padding-left: 4px;
}

.items-table td.align-right {
    text-align: right;
    padding-right: 4px;
}

.items-table td.font-bold {
    font-weight: 800;
}

/* Continuation Banner for multi-page invoices */
.continuation-row td {
    text-align: right;
    font-weight: bold;
    font-size: 11px;
    padding: 7px 12px;
    background: #f8fafc;
    border-top: 1.5px solid #000;
}

/* Filler Row to ensure stable table height */
.filler-row td {
    border-bottom: none !important;
    border-top: none !important;
}

/* Bottom Financials, Bank & Signatory */
.bottom-financials-table {
    width: 100%;
    border-collapse: collapse;
}

.words-and-bank-td {
    width: 65%;
    vertical-align: top;
    padding: 4px 6px;
    border-right: 1.5px solid #000;
    font-size: 10px;
    line-height: 1.35;
}

.totals-breakdown-td {
    width: 35%;
    padding: 0;
    vertical-align: top;
}

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

.totals-inner-table td {
    padding: 3px 5px;
    font-size: 10.5px;
}

.totals-inner-table .lbl {
    font-weight: 700;
    text-align: left;
    border-right: 1px solid #000;
}

.totals-inner-table .val {
    font-weight: 700;
    text-align: right;
}

.totals-inner-table .grand-row td {
    font-size: 12px;
    font-weight: 900;
    border-top: 1.5px solid #000;
    background: #f8fafc;
}

.bank-heading {
    text-decoration: underline;
    font-weight: 800;
    font-size: 10.5px;
    margin-bottom: 2px;
    display: inline-block;
}

.remarks-container {
    padding: 4px 6px;
    border-top: 1.5px solid #000;
    border-bottom: 1.5px solid #000;
    font-size: 10.5px;
}

.terms-and-signatory {
    padding: 6px;
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    align-items: flex-end;
}

.terms-and-signatory ul {
    list-style: none;
    padding: 0;
    margin: 2px 0 0 0;
    line-height: 1.3;
}

.signatory-box {
    text-align: center;
    min-width: 160px;
}

.signatory-box .spacer {
    height: 38px;
}

/* ==========================================================================
   CREDIT NOTE TEMPLATE (Matches media_1790362393624.jpg)
   ========================================================================== */
.credit-note-container {
    width: 100%;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    border: 1.5px solid #000;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.cn-header-title {
    text-align: center;
    font-size: 18px;
    font-weight: 800;
    padding: 6px;
    border-bottom: 1.5px solid #000;
    text-transform: capitalize;
}

.cn-meta-grid {
    display: flex;
    border-bottom: 1.5px solid #000;
}

.cn-company-client-col {
    width: 50%;
    border-right: 1.5px solid #000;
    display: flex;
    flex-direction: column;
}

.cn-company-box {
    padding: 6px 8px;
    border-bottom: 1px solid #000;
    font-size: 10.5px;
    line-height: 1.35;
}

.cn-client-box {
    padding: 6px 8px;
    font-size: 10.5px;
    line-height: 1.35;
    flex: 1;
}

.cn-details-col {
    width: 50%;
    display: flex;
    flex-direction: column;
}

.cn-detail-row {
    display: flex;
    border-bottom: 1px solid #000;
    font-size: 10.5px;
    min-height: 28px;
}

.cn-detail-row:last-child {
    border-bottom: none;
    flex: 1;
}

.cn-detail-cell {
    flex: 1;
    padding: 4px 6px;
    border-right: 1px solid #000;
    line-height: 1.3;
}

.cn-detail-cell:last-child {
    border-right: none;
}

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

.cn-table th {
    border: 1px solid #000;
    font-size: 10.5px;
    font-weight: 800;
    padding: 4px;
    text-align: center;
    background: #fff;
    border-top: none;
}

.cn-table td {
    border-right: 1px solid #000;
    border-left: 1px solid #000;
    border-top: none;
    border-bottom: none;
    padding: 4px;
    font-size: 11px;
    vertical-align: top;
}

.cn-table tr.total-row td {
    border-top: 1.5px solid #000;
    border-bottom: 1.5px solid #000;
    font-weight: 800;
    font-size: 11.5px;
    padding: 4px 6px;
}

.cn-bottom-section {
    border-top: 1.5px solid #000;
    padding: 8px 10px;
    margin-top: auto;
    font-size: 11px;
    line-height: 1.4;
}

.cn-words-line {
    margin-bottom: 25px;
}

.cn-sign-right {
    text-align: right;
    padding-right: 20px;
}

.cn-sign-right .sign-spacer {
    height: 45px;
}

/* ==========================================================================
   TAB 2: DAILY DATA ENTRY MODULE
   ========================================================================== */
.daily-entry-view {
    flex: 1;
    padding: 20px 28px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.card {
    background: white;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    padding: 18px 22px;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    margin-top: 0;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.daily-entry-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.daily-table-container {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th {
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid #cbd5e1;
    white-space: nowrap;
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
    white-space: nowrap;
}

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

.pill {
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 10.5px;
    font-weight: 600;
}

.pill.courier { background: #dbeafe; color: #1e40af; }
.pill.transport { background: #fef3c7; color: #92400e; }
.pill.credit_note { background: #fce7f3; color: #9d174d; }

.action-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.action-icon-btn.edit:hover { background: #dbeafe; color: #1d4ed8; }
.action-icon-btn.delete:hover { background: #fee2e2; color: #dc2626; }

/* ==========================================================================
   TAB 3: SAVED INVOICES
   ========================================================================== */
.history-view {
    flex: 1;
    padding: 20px 28px;
    overflow-y: auto;
}

/* ==========================================================================
   TAB 4: HOSTINGER SETTINGS
   ========================================================================== */
.settings-view {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
    max-width: 800px;
    margin: 0 auto;
}

.instruction-box {
    background: #eff6ff;
    border-left: 4px solid #3b82f6;
    padding: 12px 16px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 16px;
    font-size: 12.5px;
    line-height: 1.45;
}

.instruction-box ol {
    margin: 6px 0 0 0;
    padding-left: 18px;
}

/* Toast Notifications */
#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1e293b;
    color: white;
    padding: 10px 18px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    display: none;
    align-items: center;
    gap: 8px;
}

#toast.success { background: #16a34a; }
#toast.error { background: #dc2626; }

/* Print & PDF Overrides */
@media print {
    body { background: white; }
    .no-print, .app-header, .sidebar { display: none !important; }
    .main-preview { padding: 0 !important; background: white !important; display: block !important; }
    .bill-page-wrapper { margin: 0 !important; box-shadow: none !important; width: 100% !important; height: auto !important; }
}
