/* Invoices module — page-specific styles. */
/* Generic primitives (.btn, .form-input, .modal, etc.) come from styles.css. */

/* styles.css has .btn-primary/.btn-ghost/.btn-danger but no base .btn-secondary. */
.btn-secondary {
    background: #f3f4f6;
    color: #1a1a2e;
    border: 1px solid #e5e7eb;
}
.btn-secondary:hover { background: #e5e7eb; }
.btn-secondary:disabled { background: #f3f4f6; color: #9ca3af; cursor: not-allowed; }

.header-right { display: flex; gap: 8px; align-items: center; }

.muted { color: #6b7280; font-size: 12px; }

/* ── Filter bar ────────────────────────────────────────────────────────────── */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
    gap: 16px;
    align-items: end;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-summary {
    color: #6b7280;
    font-size: 13px;
    align-self: end;
    padding-bottom: 10px;
}

/* ── Invoices / clients table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.invoices-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.invoices-table thead th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    background: #fafbfc;
    white-space: nowrap;
}
.invoices-table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.invoices-table tbody tr:hover { background: #fafbfc; }
.invoices-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.invoices-table .empty-state { text-align: center; color: #9ca3af; padding: 40px 16px; }
.invoices-table .invoice-number { font-weight: 600; color: #1a1a2e; }
.invoices-table .row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.invoices-table .row-actions .btn-icon { width: 28px; height: 28px; }
.invoices-table .row-actions .btn-icon svg { width: 14px; height: 14px; }

/* Status pill */
.status-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.status-pill.draft { background: #f3f4f6; color: #4b5563; }
.status-pill.sent  { background: #dbeafe; color: #1e40af; }
.status-pill.paid  { background: #d1fae5; color: #065f46; }
.status-pill.void  { background: #fef2f2; color: #991b1b; }

/* ── Modals ────────────────────────────────────────────────────────────────── */
/* invoices.html uses inline style="display:none" + JS toggling classList.active */
.modal-overlay { /* override styles.css: support both .active and inline display flex */ }

/* clientModal is always opened nested inside another modal (Manage Clients
   list, or "+ New Client" from the New Invoice modal). It needs to stack
   above whichever modal opened it, regardless of DOM order. */
#clientModal { z-index: 1010; }

.modal-large { width: 920px; max-width: 95%; }

.form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}
.form-row .form-group { margin-bottom: 0; }
.form-row .form-group-grow { grid-column: span 2; }
.form-row > .btn-inline { align-self: end; height: 40px; }

@media (max-width: 720px) {
    .form-row { grid-template-columns: 1fr; }
    .form-row .form-group-grow { grid-column: span 1; }
}

/* ── Line items repeater ──────────────────────────────────────────────────── */
.line-items {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 16px;
    background: #fafbfc;
}
.line-items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.line-items-header h3 {
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}
.line-item-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 90px 110px 110px 32px;
    gap: 8px;
    align-items: start;
    margin-bottom: 8px;
}
.line-item-row textarea,
.line-item-row input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
}
.line-item-row textarea { resize: vertical; min-height: 36px; }
.line-item-row .li-line-total {
    text-align: right;
    font-variant-numeric: tabular-nums;
    padding-top: 8px;
    color: #4b5563;
    font-size: 13px;
}
.line-item-row .btn-remove {
    width: 32px; height: 36px;
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    color: #9ca3af;
}
.line-item-row .btn-remove:hover { color: #e74c3c; border-color: #fca5a5; }

@media (max-width: 720px) {
    .line-item-row { grid-template-columns: 1fr 1fr; gap: 6px; }
}

/* ── Totals preview ───────────────────────────────────────────────────────── */
.totals-preview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 16px 0;
}
.totals-preview > div {
    background: #f8fafc;
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.totals-preview > div span { color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.totals-preview > div strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.totals-preview .grand { background: #1a1a2e; color: white; }
.totals-preview .grand span { color: rgba(255,255,255,0.7); }
.totals-preview .grand strong { color: white; font-size: 18px; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 12px;
}
.alert-warning {
    background: #fef3c7;
    border: 1px solid #fde68a;
    color: #92400e;
}
.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}
.toast {
    padding: 12px 18px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    background: #1a1a2e;
    color: white;
    font-size: 14px;
    max-width: 360px;
}
.toast-success { background: #10b981; }
.toast-error { background: #ef4444; }
.toast-info { background: #3b82f6; }
.toast-warning { background: #f59e0b; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}
.btn-inline { white-space: nowrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ── Owed to us ───────────────────────────────────────────────────────────── */
.owed-totals { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.owed-currency {
    display: grid;
    grid-template-columns: 56px repeat(5, minmax(120px, 1fr));
    gap: 16px;
    align-items: center;
    padding: 12px 16px;
    background: #fafbfc;
    border: 1px solid #f0f0f0;
    border-radius: 10px;
}
.owed-currency-code { font-weight: 700; color: #1a1a2e; font-size: 14px; }
.owed-currency .stat-value { font-size: 17px; font-variant-numeric: tabular-nums; }
.owed-overdue { color: #b91c1c !important; }
.owed-late { color: #b91c1c; font-size: 12px; margin-left: 6px; white-space: nowrap; }
.owed-clients tbody td { padding: 10px 16px; }

@media (max-width: 900px) {
    .owed-currency { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .owed-currency-code { grid-column: 1 / -1; }
}

/* Status cell: paid date or days overdue under the pill */
.status-note { font-size: 11px; color: #6b7280; margin-top: 4px; white-space: nowrap; }

/* Keep Actions in view when the table scrolls sideways, as on payslips */
.invoices-table th:last-child,
.invoices-table td.actions-col {
    position: sticky;
    right: 0;
    background: #fff;
    box-shadow: -6px 0 8px -6px rgba(0, 0, 0, 0.08);
}
.invoices-table thead th:last-child { background: #fafbfc; }
.invoices-table tbody tr:hover td.actions-col { background: #fafbfc; }
.invoices-table .row-actions { flex-wrap: nowrap; align-items: center; }
.invoices-table .row-actions .btn-sm svg { width: 14px; height: 14px; }
.owed-clients th:last-child { position: static; box-shadow: none; }

/* Short values stay on one line; the table scrolls sideways instead of
   squeezing them, with Actions pinned on the right. */
.invoices-table .invoice-number,
.invoices-table .nowrap { white-space: nowrap; }
@media (max-width: 1440px) {
    .invoices-table .col-consultant { display: none; }
}

/* Tighter cells on the main list so every column fits at laptop widths. */
#invoicesTbody td, .invoices-table:not(.owed-clients) thead th { padding-left: 10px; padding-right: 10px; }
#invoicesTbody .row-actions { gap: 2px; }
#invoicesTbody .row-actions .btn-icon { width: 26px; height: 26px; }
#invoicesTbody .row-actions .btn-sm { padding: 5px 9px; }
