/* ============================================
   GeethaWaterSupply Billing — Mobile-First CSS
   ============================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
    --primary: #0e7490;
    --primary-dark: #0a5e73;
    --primary-light: #e0f7fa;
    --primary-gradient: linear-gradient(135deg, #0e7490 0%, #155e75 50%, #1e3a5f 100%);

    --bg: #f0f4f8;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --success: #10b981;
    --whatsapp: #25d366;
    --danger: #ef4444;
    --warning: #f59e0b;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

input, button, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

.hidden {
    display: none !important;
}

/* ---------- App Header ---------- */
.app-header {
    background: var(--primary-gradient);
    color: white;
    padding: 20px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(14, 116, 144, 0.3);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.header-icon {
    font-size: 2rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.header-sub {
    font-size: 0.8rem;
    opacity: 0.8;
    font-weight: 400;
}

/* ---------- Container ---------- */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 100px;
}

/* ---------- Invoice Badge ---------- */
.invoice-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 16px;
    border-radius: 999px;
    margin-bottom: 16px;
    border: 1.5px solid rgba(14, 116, 144, 0.2);
}

/* ---------- Cards ---------- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px solid var(--border-light);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-icon {
    font-size: 1.1rem;
}

.chevron {
    font-size: 0.9rem;
    color: var(--text-light);
    transition: transform 0.3s ease;
}

.chevron.rotated {
    transform: rotate(180deg);
}

.card-body {
    padding: 0 18px 18px;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}

.card-body.collapsed {
    max-height: 0 !important;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    opacity: 0;
}

/* ---------- Form Elements ---------- */
.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.required {
    color: var(--danger);
}

.form-group input[type="text"],
.form-group input[type="tel"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="month"] {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.15);
    background: white;
}

.form-group input::placeholder {
    color: var(--text-light);
}

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

/* ---------- Products ---------- */
.product-card {
    background: var(--bg);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 14px;
    border: 1.5px solid var(--border);
    position: relative;
    transition: border-color 0.2s ease;
}

.product-card:focus-within {
    border-color: var(--primary);
}

.product-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.product-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-remove {
    width: 30px;
    height: 30px;
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-radius: 50%;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.btn-remove:active {
    background: rgba(239, 68, 68, 0.25);
}

.product-card .form-group input {
    background: white;
}

.flex-2 { flex: 2; }
.flex-1 { flex: 1; }

.product-card .form-row {
    display: flex;
    gap: 10px;
}

/* ---------- Delivery Grid ---------- */
.delivery-section {
    margin-top: 12px;
}

.delivery-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.delivery-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.day-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.day-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-light);
}

.day-input {
    width: 100%;
    max-width: 42px;
    height: 34px;
    text-align: center;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    background: white;
    padding: 0;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    transition: border-color 0.2s ease;
}

.day-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(14, 116, 144, 0.15);
}

.day-input::-webkit-inner-spin-button,
.day-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.delivery-total {
    margin-top: 10px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-light);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.total-qty {
    font-size: 1.1rem;
}

/* ---------- Buttons ---------- */
.btn-add {
    width: 100%;
    padding: 14px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-add:active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.btn-add span {
    font-size: 1.3rem;
    line-height: 1;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 15px rgba(14, 116, 144, 0.3);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-large {
    width: 100%;
    padding: 18px;
    font-size: 1.1rem;
    border-radius: var(--radius-lg);
    margin-top: 8px;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-secondary:active {
    background: var(--border);
}

/* ---------- Action Bar (Preview) ---------- */
.action-bar {
    position: sticky;
    top: 0;
    z-index: 90;
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

.action-right {
    display: flex;
    gap: 8px;
}

.btn-action {
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease;
}

.btn-action:active {
    transform: scale(0.95);
}

.btn-back {
    background: var(--bg);
    color: var(--text);
}

.btn-download {
    background: var(--primary);
    color: white;
}

.btn-whatsapp {
    background: var(--whatsapp);
    color: white;
}

/* ---------- Invoice Wrapper ---------- */
.invoice-wrapper {
    padding: 12px;
    max-width: 850px;
    margin: 0 auto;
}

/* ============================================
   INVOICE PREVIEW STYLES (Print-ready)
   ============================================ */
.invoice-page {
    background: white;
    padding: 28px 22px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 11px;
    color: #1a1a2e;
    line-height: 1.4;
}

/* Invoice Header */
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.inv-business-name {
    font-size: 18px;
    font-weight: 800;
    color: #1a1a2e;
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.inv-business-addr,
.inv-business-phone {
    font-size: 9.5px;
    color: #555;
    line-height: 1.5;
}

.inv-title-block {
    text-align: right;
}

.inv-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: 0.05em;
}

.inv-number {
    font-size: 9.5px;
    color: #555;
    margin-top: 2px;
}

.inv-num-val {
    font-weight: 700;
    border-bottom: 1px solid #333;
    padding-bottom: 1px;
}

.inv-divider {
    border: none;
    border-top: 2px solid var(--primary);
    margin: 10px 0 14px;
}

/* Customer Table */
.inv-customer-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 10px;
}

.inv-customer-table td {
    padding: 6px 8px;
    border: 1px solid #d0d8e0;
    vertical-align: top;
}

.inv-label {
    background: var(--primary-light);
    font-weight: 700;
    color: #1a1a2e;
    width: 18%;
    font-size: 9.5px;
}

.inv-value {
    width: 32%;
    color: #333;
}

/* Products Table */
.inv-products-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
    font-size: 10px;
}

.inv-products-table thead th {
    background: var(--primary);
    color: white;
    padding: 8px 6px;
    text-align: center;
    font-weight: 700;
    font-size: 9.5px;
}

.inv-products-table thead th:first-child {
    text-align: left;
}

.inv-products-table tbody td {
    padding: 8px 6px;
    border: 1px solid #d0d8e0;
    text-align: center;
}

.inv-products-table tbody td:first-child {
    text-align: left;
}

/* Totals */
.inv-totals-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 18px;
    font-size: 10px;
}

.inv-totals-table td {
    padding: 6px 8px;
    border: 1px solid #d0d8e0;
}

.inv-totals-label {
    text-align: right;
    font-weight: 600;
    color: #555;
    background: #f8fafc;
}

.inv-totals-value {
    width: 80px;
    text-align: center;
    font-weight: 700;
}

.inv-total-row td {
    background: var(--primary) !important;
    color: white !important;
    font-weight: 800 !important;
    font-size: 11px;
}

/* Delivery Summary */
.inv-delivery-section {
    margin-bottom: 20px;
}

.inv-delivery-title {
    font-size: 11px;
    font-weight: 800;
    color: #1a1a2e;
    margin-bottom: 8px;
}

.inv-delivery-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8px;
    margin-bottom: 0;
}

.inv-del-header {
    background: #e2e8f0;
    font-weight: 700;
    text-align: center;
    padding: 4px 2px;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 7.5px;
}

.inv-del-product {
    background: #f8fafc;
    font-weight: 600;
    padding: 4px 3px;
    border: 1px solid #cbd5e1;
    font-size: 7.5px;
    white-space: nowrap;
}

.inv-del-cell {
    text-align: center;
    padding: 4px 2px;
    border: 1px solid #cbd5e1;
    font-weight: 600;
    color: var(--primary);
    min-width: 14px;
}

/* Invoice Footer */
.inv-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px solid #e2e8f0;
}

.inv-notes {
    flex: 1;
}

.inv-notes-title {
    font-weight: 700;
    font-size: 9.5px;
    margin-bottom: 3px;
    color: #1a1a2e;
}

.inv-notes p {
    font-size: 8.5px;
    color: #555;
    line-height: 1.5;
}

.inv-signature {
    text-align: center;
    min-width: 120px;
}

.inv-sig-line {
    width: 100px;
    border-bottom: 1px solid #333;
    margin: 0 auto 4px;
}

.inv-sig-title {
    font-size: 8.5px;
    font-weight: 600;
    color: #555;
}

.inv-sig-name {
    font-size: 10px;
    font-weight: 800;
    color: #1a1a2e;
}

.inv-sig-business {
    font-size: 8px;
    font-weight: 600;
    color: var(--primary);
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 28px 22px 34px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-content h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 18px;
}

.filename-input-wrap {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
    transition: border-color 0.2s ease;
}

.filename-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.15);
}

.filename-input-wrap input {
    flex: 1;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 12px 14px;
}

.filename-ext {
    padding: 0 14px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    background: var(--border-light);
    height: 100%;
    display: flex;
    align-items: center;
    padding-top: 12px;
    padding-bottom: 12px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    flex: 1;
}

/* ---------- Loading Overlay ---------- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 300;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    font-weight: 600;
    color: var(--text-secondary);
}

/* ============================================
   RESPONSIVE — Tablet & Desktop
   ============================================ */
@media (min-width: 768px) {
    html {
        font-size: 16px;
    }

    .app-header {
        padding: 24px 20px;
    }

    .app-header h1 {
        font-size: 1.5rem;
    }

    .container {
        padding: 24px;
    }

    .card-body {
        padding: 0 24px 24px;
    }

    .invoice-page {
        padding: 40px 36px;
        font-size: 12px;
    }

    .inv-business-name {
        font-size: 22px;
    }

    .inv-title {
        font-size: 28px;
    }

    .inv-customer-table td {
        padding: 8px 10px;
    }

    .inv-delivery-table {
        font-size: 9px;
    }

    .inv-del-header,
    .inv-del-product {
        font-size: 8.5px;
    }

    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: var(--radius-xl);
        max-width: 440px;
    }

    .day-input {
        max-width: 48px;
        height: 38px;
    }
}
