/**
 * Print Stylesheet for EasyRentalGuru
 * Provides professional print layouts for invoices, receipts, and reports
 */

/* ==========================================================================
   Base Print Styles
   ========================================================================== */
@media print {
    /* Hide elements that shouldn't print */
    .no-print,
    .no-print *,
    .btn,
    .btn-primary,
    .btn-secondary,
    .btn-link,
    .spinner,
    .loading-state,
    .invoice-header,
    nav,
    header,
    footer,
    .sidebar,
    .mobile-nav,
    .toast-container,
    .modal-backdrop,
    .modal,
    .dropdown-menu,
    .tooltip,
    .popover {
        display: none !important;
    }

    /* Ensure proper page sizing */
    @page {
        size: A4;
        margin: 15mm;
    }

    /* Reset backgrounds and colors for printing */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    body {
        background: white !important;
        color: #000 !important;
        font-size: 12pt;
        line-height: 1.4;
        margin: 0;
        padding: 0;
    }

    /* Ensure links show their URL */
    a[href]:after {
        content: "" !important;
    }

    /* Page breaks */
    .page-break {
        page-break-before: always;
    }

    .page-break-after {
        page-break-after: always;
    }

    .no-page-break {
        page-break-inside: avoid;
    }

    /* Prevent orphaned elements */
    p, li {
        orphans: 3;
        widows: 3;
    }

    h1, h2, h3, h4, h5, h6 {
        orphans: 3;
        widows: 3;
        page-break-after: avoid;
    }

    table {
        page-break-inside: avoid;
    }

    tr {
        page-break-inside: avoid;
    }
}

/* ==========================================================================
   Invoice Print Styles (Screen Preview)
   ========================================================================== */
.invoice-page {
    max-width: 210mm;
    margin: 0 auto;
    padding: 20px;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.invoice-header .btn-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #6b7280;
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s;
}

.invoice-header .btn-link:hover {
    color: #111827;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.invoice-container {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 3rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Branding Section */
.invoice-branding {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid #1976d2;
}

.invoice-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #1976d2;
    margin: 0;
    letter-spacing: -0.02em;
}

.invoice-status {
    display: inline-block;
    padding: 0.375rem 1rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.5rem;
}

.invoice-status.status-paid {
    background-color: #dcfce7;
    color: #15803d;
}

.invoice-status.status-sent {
    background-color: #dbeafe;
    color: #1d4ed8;
}

.invoice-status.status-draft {
    background-color: #f3f4f6;
    color: #4b5563;
}

.invoice-status.status-overdue {
    background-color: #fee2e2;
    color: #b91c1c;
}

.invoice-status.status-cancelled {
    background-color: #f3f4f6;
    color: #6b7280;
}

.invoice-status.status-partial {
    background-color: #fef3c7;
    color: #b45309;
}

.company-details h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.company-details p {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0.25rem 0 0 0;
}

/* Meta Section */
.invoice-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2.5rem;
}

.meta-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 1rem 0;
}

.meta-table {
    width: 100%;
    border-collapse: collapse;
}

.meta-table td {
    padding: 0.375rem 0;
    font-size: 0.875rem;
}

.meta-table td.label {
    color: #6b7280;
    width: 120px;
}

.meta-table td.value {
    color: #111827;
}

.meta-section.recipient {
    background: #f9fafb;
    padding: 1.25rem;
    border-radius: 8px;
}

.recipient-details {
    font-size: 0.875rem;
}

.recipient-name {
    font-weight: 600;
    color: #111827;
    margin: 0 0 0.25rem 0;
}

.recipient-email {
    color: #6b7280;
    margin: 0 0 0.25rem 0;
}

.recipient-address {
    color: #6b7280;
    margin: 0;
    line-height: 1.5;
}

/* Line Items Table */
.line-items-section {
    margin-bottom: 2rem;
}

.line-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.line-items-table thead {
    background: #1976d2;
}

.line-items-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: white;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.line-items-table th.description {
    width: 50%;
}

.line-items-table th.quantity,
.line-items-table th.unit-price,
.line-items-table th.amount {
    text-align: right;
    width: 16.67%;
}

.line-items-table td {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    color: #374151;
}

.line-items-table td.quantity,
.line-items-table td.unit-price,
.line-items-table td.amount {
    text-align: right;
}

.line-items-table tbody tr:last-child td {
    border-bottom: 2px solid #1976d2;
}

/* Totals Section */
.totals-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 2rem;
}

.totals-table {
    width: 320px;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.totals-table td {
    padding: 0.5rem 1rem;
}

.totals-table td.label {
    color: #6b7280;
    text-align: left;
}

.totals-table td.value {
    color: #111827;
    text-align: right;
    font-weight: 500;
}

.totals-table td.value.discount {
    color: #15803d;
}

.totals-table td.paid {
    color: #15803d;
}

.totals-table tr.total-row {
    background: #eff6ff;
}

.totals-table tr.total-row td {
    padding: 1rem;
    font-size: 1rem;
    font-weight: 700;
}

.totals-table tr.balance-row {
    background: #fff7ed;
}

.totals-table tr.balance-row td {
    padding: 1rem;
    font-size: 1rem;
    font-weight: 700;
    color: #c2410c;
}

/* Payments Section */
.payments-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f0fdf4;
    border-radius: 8px;
    border: 1px solid #bbf7d0;
}

.payments-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #15803d;
    margin: 0 0 1rem 0;
}

.payments-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.payments-table th {
    padding: 0.5rem;
    text-align: left;
    font-weight: 600;
    color: #15803d;
    border-bottom: 1px solid #bbf7d0;
}

.payments-table th.amount {
    text-align: right;
}

.payments-table td {
    padding: 0.5rem;
    color: #374151;
    border-bottom: 1px solid #bbf7d0;
}

.payments-table td.amount {
    text-align: right;
    font-weight: 500;
}

/* Notes Section */
.notes-section {
    margin-bottom: 2rem;
    padding: 1.25rem;
    background: #fefce8;
    border-radius: 8px;
    border: 1px solid #fde047;
}

.notes-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #a16207;
    margin: 0 0 0.5rem 0;
}

.notes-section p {
    font-size: 0.875rem;
    color: #713f12;
    margin: 0;
    line-height: 1.5;
}

/* Terms Section */
.terms-section {
    margin-bottom: 2rem;
    padding: 1.25rem;
    background: #f9fafb;
    border-radius: 8px;
}

.terms-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    margin: 0 0 0.5rem 0;
}

.terms-section p {
    font-size: 0.75rem;
    color: #6b7280;
    margin: 0;
    line-height: 1.6;
}

/* Footer */
.invoice-footer {
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid #e5e7eb;
}

.invoice-footer p {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0 0 0.5rem 0;
}

.invoice-footer .footer-meta {
    font-size: 0.75rem;
    color: #9ca3af;
}

/* ==========================================================================
   Loading and Error States
   ========================================================================== */
.loading-state,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.loading-state p {
    margin-top: 1rem;
    color: #6b7280;
}

.error-state h3 {
    margin: 1.5rem 0 0.5rem 0;
    color: #111827;
}

.error-state p {
    color: #6b7280;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Button Styles (for screen only)
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: #1976d2;
    color: white;
    border-color: #1976d2;
}

.btn-primary:hover:not(:disabled) {
    background: #1565c0;
    border-color: #1565c0;
}

.btn-secondary {
    background: white;
    color: #374151;
    border-color: #d1d5db;
}

.btn-secondary:hover:not(:disabled) {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-link {
    background: transparent;
    color: #1976d2;
    border-color: transparent;
    padding: 0.5rem;
}

.btn-link:hover {
    color: #1565c0;
    text-decoration: underline;
}

/* Spinner */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .invoice-container {
        padding: 1.5rem;
    }

    .invoice-meta {
        grid-template-columns: 1fr;
    }

    .invoice-branding {
        flex-direction: column;
        gap: 1rem;
    }

    .line-items-table {
        font-size: 0.75rem;
    }

    .line-items-table th,
    .line-items-table td {
        padding: 0.5rem;
    }

    .totals-section {
        justify-content: stretch;
    }

    .totals-table {
        width: 100%;
    }
}
