/* Cleaning Fairies invoicing admin — minimal, readable. */
:root {
    --bg: #fafaf7;
    --panel: #ffffff;
    --border: #e8e5dd;
    --muted: #888;
    --text: #1f1f1f;
    --accent: #b8a080;
    --accent-dk: #8a7a5a;
    --primary: #4a6a9c;
    --success: #2f7a3d;
    --danger: #b13a3a;
    --paid: #2f7a3d;
    --sent: #4a6a9c;
    --draft: #888;
    --overdue: #b13a3a;
    --void: #555;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }

/* Top nav */
.topnav { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: white; border-bottom: 1px solid var(--border); }
.topnav .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); }
.topnav .brand img { height: 28px; }
.topnav .spacer { flex: 1; }
.topnav .who { color: var(--muted); font-size: 13px; }

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* Buttons */
.btn, .btn-primary, .btn-success, .btn-danger {
    display: inline-block; padding: 7px 14px; border-radius: 5px; border: 1px solid var(--border);
    background: white; color: var(--text); cursor: pointer; font-size: 13px; text-decoration: none;
}
.btn:hover { background: #f3f0e8; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: #3a5a8c; }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { background: #25612e; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #952f2f; }
.btn-remove { background: transparent; border: none; color: var(--danger); font-size: 18px; cursor: pointer; }
button { font-family: inherit; }

/* Login card */
.login-card { max-width: 360px; margin: 80px auto; padding: 32px; background: white; border: 1px solid var(--border); border-radius: 8px; text-align: center; }
.login-card .login-logo { max-height: 60px; margin-bottom: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; }

/* Tables */
table.data { width: 100%; border-collapse: collapse; background: white; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
table.data th { background: #f4f1e8; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.data tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data .empty { text-align: center; color: var(--muted); padding: 24px; }

/* Pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.pill-draft   { background: #eee; color: var(--draft); }
.pill-sent    { background: #e3ecf6; color: var(--sent); }
.pill-paid    { background: #e0f0e2; color: var(--paid); }
.pill-overdue { background: #f6e3e3; color: var(--overdue); }
.pill-void    { background: #ddd; color: var(--void); }

/* Summary stat row */
.summary-row { display: flex; gap: 14px; margin-bottom: 18px; }
.stat { flex: 1; background: white; border: 1px solid var(--border); padding: 14px 16px; border-radius: 6px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 5px; }
.stat-value { font-size: 22px; font-weight: 600; }

/* Filter bar */
.filter-bar { display: flex; gap: 4px; margin-bottom: 14px; }
.filter-bar a { padding: 6px 12px; border-radius: 4px; color: var(--muted); font-size: 13px; }
.filter-bar a.active { background: var(--accent); color: white; }

/* Page head */
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.page-head h1 { margin: 0; }

/* Forms */
form.stacked { display: flex; flex-direction: column; gap: 14px; background: white; padding: 22px; border: 1px solid var(--border); border-radius: 6px; }
form.stacked label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
form.stacked input, form.stacked select, form.stacked textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; font-family: inherit; background: white; }
form.stacked textarea { resize: vertical; min-height: 60px; }
form.stacked .actions { display: flex; gap: 10px; margin-top: 8px; }
form.stacked .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
form.stacked .row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* Invoice form lines */
table.lines { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.lines th, table.lines td { padding: 6px 4px; vertical-align: top; }
table.lines th { font-size: 12px; text-transform: uppercase; color: var(--muted); text-align: left; }
table.lines input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
table.lines .num-input { text-align: right; }

/* Invoice view */
.invoice-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; background: white; padding: 16px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 14px; font-size: 13px; line-height: 1.7; }
.client-meta { background: white; padding: 14px 18px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 14px; font-size: 13px; line-height: 1.7; }
.notes-box { background: #fff8e0; border-left: 3px solid var(--accent); padding: 10px 14px; margin-top: 14px; font-size: 13px; }
.total-row { font-size: 16px; padding-top: 12px; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 5px; margin-bottom: 14px; font-size: 13px; }
.flash-error { background: #f6e3e3; color: var(--danger); }
.flash-success { background: #e0f0e2; color: var(--success); }
.flash-info { background: #e3ecf6; color: var(--sent); }

/* Items + recurring extras */
.archived { opacity: 0.55; }
.checkbox { display: flex; flex-direction: row !important; align-items: center; gap: 8px; }
.checkbox input { width: auto; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }
.lines .catalog-pick { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; background: white; }

/* Overdue + dashboard tweaks */
.stat-sub { font-size: 13px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.stat-overdue .stat-value { color: var(--danger); }
.row-overdue td { background: #fdf2f2; }
.overdue-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 99px; background: var(--danger); color: white; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

/* Mark-paid inline form on invoice view */
.mark-paid-form { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; background: white; border: 1px solid var(--border); border-radius: 5px; }
.mark-paid-form label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin: 0; }
.mark-paid-form input[type="date"] { padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }

/* Inline row-action buttons on the dashboard */
.row-actions { white-space: nowrap; display: flex; gap: 6px; }
.btn-mini { padding: 4px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px; background: white; color: var(--text); cursor: pointer; }
.btn-mini.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-mini.btn-primary:hover { background: #3a5a8c; }
.btn-mini.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-mini.btn-success:hover { background: #266433; }

/* Send-invoice preview modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 20, 0.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: white; border: 1px solid var(--border); border-radius: 6px; max-width: 640px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 22px 26px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal form.stacked { padding: 0; border: 0; background: transparent; }
.modal-row { font-size: 14px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal .hint { font-size: 12px; color: var(--muted); margin: 0; }

/* ── Multi-company picker (top bar) ─────────────────────────────── */
.company-picker { display: inline-flex; align-items: center; margin: 0 8px 0 4px; }
.company-picker select {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px;
    background: white; font-size: 13px; font-weight: 600; color: var(--text);
    cursor: pointer; max-width: 220px;
}
.company-picker select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* Inline helper text used on forms ("This invoice will bill under …") */
p.muted { font-size: 12px; color: var(--muted); margin: -4px 0 8px; }

/* ── Reports (P&L, Balance Sheet) ─────────────────────────────── */
.report-table th.num,
.report-table td.num { text-align: right; font-variant-numeric: tabular-nums; min-width: 7em; }
.report-table tr.section th {
    background: var(--bg); padding-top: 16px; padding-bottom: 4px;
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
    border-bottom: 1px solid var(--border);
}
.report-table tr.subtotal th { border-top: 1px solid var(--border); padding-top: 10px; }
.report-table tr.total th {
    border-top: 2px solid var(--text); border-bottom: 2px solid var(--text);
    padding-top: 12px; padding-bottom: 12px; font-size: 14px;
}
.report-table tr.total th.num { font-weight: 700; }
.report-table code { font-size: 12px; color: var(--muted); margin-right: 6px; }
.report-list { list-style: none; padding: 0; }
.report-list li { padding: 12px 16px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 10px; }
.report-list li a { text-decoration: none; }
.flash-warning { background: #fff3cd; border: 1px solid #ffe69c; color: #664d03; padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; }

/* ── Bank-connect institution grid ─────────────────────────────── */
.bank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.bank-tile {
    text-align: left; padding: 10px 12px; background: white; border: 1px solid var(--border);
    border-radius: 4px; cursor: pointer; font-size: 13px;
}
.bank-tile:hover { border-color: var(--primary); background: var(--bg); }

/* ── Reconciliation queue ─────────────────────────────────────── */
.recon-card { border: 1px solid var(--border); border-radius: 6px; padding: 14px 18px; margin-bottom: 10px; background: white; }
.recon-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.recon-date { font-weight: 600; font-size: 14px; }
.recon-account { font-size: 12px; }
.recon-amount { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 18px; }
.recon-amount.pos { color: #1c7a37; }
.recon-amount.neg { color: #a02828; }
.recon-desc { font-size: 13px; margin: 6px 0; }
.recon-actions { margin-top: 8px; }
.recon-actions summary { cursor: pointer; font-size: 13px; color: var(--primary); }
.recon-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.recon-form label { display: flex; flex-direction: column; font-size: 12px; flex: 1; min-width: 200px; }
.recon-form select, .recon-form input[type=text] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; }
.recon-form.recon-ignore { justify-content: flex-end; border-top: 0; }
.flash-info { background: #d1e9ff; border: 1px solid #9ec5fe; color: #084298; padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; }

/* ── Mobile / small-screen fixes ──────────────────────────────────
   No media queries existed before — the layout assumed desktop.
   These rules keep desktop as-is and only kick in below 768px / 480px. */
@media (max-width: 768px) {
    .container { padding: 12px; max-width: 100%; }

    /* Top nav: wrap, smaller links, hide non-essentials */
    .topnav { flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
    .topnav .brand { width: 100%; margin-bottom: 4px; }
    .topnav .brand img { height: 22px; }
    .topnav .spacer { display: none; }
    .topnav .who { display: none; font-size: 11px; }
    .topnav a { padding: 4px 6px; font-size: 12px; }
    .topnav .btn-primary { padding: 6px 10px; font-size: 12px; }

    /* Company picker: full width below the brand */
    .company-picker { width: 100%; margin: 4px 0; order: 99; }
    .company-picker select { width: 100%; max-width: 100%; font-size: 12px; }

    /* Stats: 2-up grid */
    .summary-row { flex-wrap: wrap; gap: 8px; }
    .summary-row .stat { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 8px 10px; }
    .stat-value { font-size: 16px; }
    .stat-sub { font-size: 11px; }

    /* Tables overflow horizontally instead of breaking layout */
    table.data, table.report-table {
        display: block; overflow-x: auto; max-width: 100%;
        font-size: 12px; -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    table.data td, table.data th,
    table.report-table td, table.report-table th { white-space: nowrap; }

    /* Forms / form-rows stack vertically */
    .form-row { flex-direction: column; gap: 8px; }
    .form-row label { width: 100%; min-width: 0; }

    /* Reconciliation cards: vertical stack inside .recon-form */
    .recon-form { flex-direction: column; align-items: stretch; }
    .recon-form label { min-width: 0; }

    .bank-grid { grid-template-columns: 1fr 1fr; }

    .filter-bar { flex-wrap: wrap; gap: 6px; }
    .filter-bar a { padding: 6px 10px; font-size: 12px; }

    h1 { font-size: 22px; line-height: 1.2; }
    h2 { font-size: 18px; }
    .page-head { margin-bottom: 12px; }

    .flash { font-size: 13px; padding: 8px 12px; }
}

@media (max-width: 480px) {
    .summary-row .stat { flex: 1 1 100%; }
    .bank-grid { grid-template-columns: 1fr; }
    .topnav a { padding: 3px 5px; }
}
