/* InIT.Accounts.UI - styles for the accounting screens. Self-contained (every class starts with "ac-"); the host can re-colour
   everything by setting --ac-accent and friends on :root. Phone layouts kick in under 720px. */

.ac {
    --ac-accent: var(--red, #b51f2e);
    --ac-accent-dark: #8f1824;
    --ac-blue: var(--blue, #1a73e8);
    --ac-good: #1e7b43;
    --ac-bad: #b3261e;
    --ac-ink: var(--ink, #222);
    --ac-muted: var(--gray500, #6b7280);
    --ac-line: var(--gray200, #e5e7eb);
    --ac-soft: #f6f7f9;
    --ac-paper: #fff;
    box-sizing: border-box;
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 12px 40px;
    color: var(--ac-ink);
    font-size: 14px;
    line-height: 1.4;
}
.ac *, .ac *::before, .ac *::after { box-sizing: inherit; }
.ac a { color: var(--ac-blue); text-decoration: none; }
.ac a:hover { text-decoration: underline; }
.ac h1 { font-size: 18px; margin: 0; flex: 1; }
.ac h2 { font-size: 16px; margin: 0 0 6px; }
.ac h3 { font-size: 13px; margin: 14px 0 4px; color: var(--ac-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---- title bar ---- */
.ac-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--ac-accent); color: #fff; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.ac-top a, .ac-top a:hover { color: #fff; }
.ac-back { font-size: 13px; opacity: .9; white-space: nowrap; }
.ac-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ac-actions .ac-btn { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.4); }
.ac-actions .ac-btn:hover { background: rgba(255,255,255,.28); text-decoration: none; }

/* ---- messages ---- */
.ac-busy { color: var(--ac-muted); padding: 4px 2px; font-size: 13px; }
.ac-error, .ac-banner { background: #fdecea; color: var(--ac-bad); border: 1px solid #f5c2bd; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.ac-notice, .ac-note { background: #eaf6ee; color: var(--ac-good); border: 1px solid #bfe2cb; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.ac-note.ac-good { background: #eaf6ee; }
.ac-banner { background: #fff4e5; color: #8a5300; border-color: #f2d19b; }
.ac-empty { text-align: center; color: var(--ac-muted); padding: 30px 10px; }
.ac-hint { color: var(--ac-muted); font-size: 12px; margin: 2px 0 8px; }
.ac-good { color: var(--ac-good); }
.ac-bad { color: var(--ac-bad); }

/* ---- buttons and links ---- */
.ac-btn { display: inline-block; font: inherit; font-size: 13px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--ac-line); background: #fff; color: var(--ac-ink); cursor: pointer; }
.ac-btn:hover { background: var(--ac-soft); text-decoration: none; }
.ac-btn:disabled { opacity: .5; cursor: default; }
.ac-primary, .ac .ac-primary { background: var(--ac-accent); border-color: var(--ac-accent); color: #fff; font-weight: 600; }
.ac-primary:hover { background: var(--ac-accent-dark); }
.ac-danger { color: var(--ac-bad); border-color: #f0b4ae; }
.ac-link { font: inherit; background: none; border: 0; color: var(--ac-blue); cursor: pointer; padding: 4px 6px; }
.ac-danger-text { color: var(--ac-bad); }
.ac-x { font-size: 20px; line-height: 1; width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--ac-soft); color: var(--ac-bad); cursor: pointer; }
.ac-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.ac-badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #e8f0fe; color: #1a56c4; margin-left: 4px; }
.ac-badge.ac-bad { background: #fdecea; color: var(--ac-bad); }
.ac-badge.ac-soft { background: var(--ac-soft); color: var(--ac-muted); }

/* ---- forms ---- */
.ac input:not([type=checkbox]), .ac select, .ac textarea { font: inherit; font-size: 14px; width: 100%; padding: 7px 9px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; color: var(--ac-ink); }
.ac input:disabled, .ac select:disabled, .ac textarea:disabled { background: var(--ac-soft); color: var(--ac-muted); }
.ac input:focus, .ac select:focus, .ac textarea:focus { outline: 2px solid color-mix(in srgb, var(--ac-blue) 40%, transparent); border-color: var(--ac-blue); }
.ac label > span:first-child, .ac label > em { display: block; font-size: 12px; color: var(--ac-muted); font-style: normal; margin-bottom: 2px; }
.ac-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; margin: 8px 0 12px; }
.ac-form-row { grid-template-columns: 150px 120px 1fr; align-items: end; }
.ac-block { display: block; margin: 10px 0; }
.ac-grow { flex: 1; min-width: 200px; }
.ac-check { display: flex; align-items: center; gap: 8px; }
.ac-check input { width: auto; }
.ac-check span { margin: 0 !important; font-size: 13px !important; color: var(--ac-ink) !important; }
.ac-filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin: 8px 0; }
.ac-filters label { min-width: 130px; }
.ac-picker { display: block; }
.ac-picker.ac-invalid input { border-color: var(--ac-bad); background: #fff7f6; }

/* ---- book bar ---- */
.ac-bar { display: flex; gap: 10px 14px; flex-wrap: wrap; align-items: end; background: var(--ac-soft); border: 1px solid var(--ac-line); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.ac-bar label { min-width: 120px; flex: 1 1 140px; max-width: 260px; }
.ac-presets { display: flex; gap: 2px; flex-wrap: wrap; }

/* ---- cards, tiles ---- */
.ac-card { background: var(--ac-paper); border: 1px solid var(--ac-line); border-radius: 12px; padding: 12px 14px; margin: 10px 0; }
.ac-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ac-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; margin-top: 8px; }
.ac-tiles h2 { grid-column: 1 / -1; margin: 10px 0 0; color: var(--ac-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.ac-tile { display: block; background: var(--ac-paper); border: 1px solid var(--ac-line); border-left: 4px solid var(--ac-accent); border-radius: 10px; padding: 10px 12px; color: var(--ac-ink) !important; }
.ac-tile:hover { background: var(--ac-soft); text-decoration: none !important; }
.ac-tile b { display: block; font-size: 15px; }
.ac-tile span { color: var(--ac-muted); font-size: 12px; }
.ac-glance { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.ac-tile-sm { display: flex; flex-direction: column; min-width: 150px; background: var(--ac-paper); border: 1px solid var(--ac-line); border-radius: 10px; padding: 6px 12px; color: var(--ac-ink) !important; }
.ac-tile-sm span { font-size: 12px; color: var(--ac-muted); }
.ac-tile-sm b { font-size: 16px; }

/* ---- tabs and chips ---- */
.ac-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--ac-line); margin-bottom: 8px; }
.ac-tab { font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--ac-muted); margin-bottom: -2px; }
.ac-tab.ac-on { color: var(--ac-accent); border-bottom-color: var(--ac-accent); font-weight: 600; }
.ac-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 8px; }
.ac-chip { font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 14px; border: 1px solid var(--ac-line); background: #fff; cursor: pointer; }
.ac-chip.ac-on { background: var(--ac-accent); border-color: var(--ac-accent); color: #fff; }

/* ---- tables ---- */
.ac-table { width: 100%; border-collapse: collapse; background: var(--ac-paper); border: 1px solid var(--ac-line); border-radius: 10px; overflow: hidden; }
.ac-table th, .ac-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--ac-line); vertical-align: top; }
.ac-table thead th { background: var(--ac-soft); font-size: 12px; color: var(--ac-muted); text-transform: uppercase; letter-spacing: .03em; }
.ac-table tfoot th { background: var(--ac-soft); border-top: 2px solid var(--ac-line); }
.ac-table .ac-group th { background: #f1f3f6; color: var(--ac-ink); font-size: 13px; text-transform: none; letter-spacing: 0; }
.ac-num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ac-dr { color: var(--ac-ink); }
.ac-cr { color: #8a4b00; }
.ac-click { cursor: pointer; }
.ac-click:hover { background: var(--ac-soft); }
.ac-cancelled td { color: var(--ac-muted); text-decoration: line-through; }
.ac-cancelled td:first-child, .ac-cancelled a { text-decoration: none; }
.ac-off td { color: var(--ac-muted); }
.ac-open td { font-style: italic; background: #fafafa; }
.ac-table input { padding: 4px 6px; }
.ac-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; color: var(--ac-muted); }
.ac-summary { display: flex; gap: 8px 22px; flex-wrap: wrap; background: var(--ac-soft); border: 1px solid var(--ac-line); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.ac-summary b { font-size: 15px; margin-left: 4px; }

/* ---- income & expenditure / balance sheet ---- */
.ac-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 8px; }
.ac-sides section { background: var(--ac-paper); border: 1px solid var(--ac-line); border-radius: 10px; padding: 10px 12px; }
.ac-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.ac-row-group { font-weight: 600; background: var(--ac-soft); margin: 6px -6px 0; padding: 4px 6px; border-radius: 6px; }
.ac-row-line { padding-left: 12px; }
.ac-row-total { border-top: 1px dashed var(--ac-line); margin-top: 8px; font-weight: 600; }
.ac-row-grand { border-top: 2px solid var(--ac-ink); margin-top: 10px; font-weight: 700; font-size: 15px; }

/* ---- voucher entry ---- */
.ac-voucher .ac-form-row { grid-template-columns: 150px 110px 1fr; }
.ac-lines { margin: 6px 0; }
.ac-line { display: grid; gap: 8px; align-items: end; padding: 4px 0; }
.ac-lines-1 .ac-line { grid-template-columns: minmax(180px, 2fr) 130px minmax(120px, 1.5fr) 36px; }
.ac-lines-2 .ac-line { grid-template-columns: minmax(150px, 2fr) minmax(150px, 2fr) 130px minmax(110px, 1.5fr) 36px; }
.ac-line-head { color: var(--ac-muted); font-size: 12px; border-bottom: 1px solid var(--ac-line); padding-bottom: 2px; }
.ac-line label > em { display: none; }
.ac-line input { text-align: left; }
.ac-line .ac-num input { text-align: right; }
.ac-total { display: flex; justify-content: flex-end; gap: 14px; align-items: baseline; font-size: 16px; padding: 8px 0; }
.ac-total.ac-good, .ac-total.ac-bad { justify-content: flex-start; font-size: 14px; font-weight: 600; }

/* ---- pop-up ---- */
.ac-dim { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 12px 12px; z-index: 1000; overflow: auto; }
.ac-modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.ac-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; }
.ac-modal-head h2 { margin: 0; }
.ac-modal-body { padding: 4px 16px 8px; }
.ac-modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 8px 16px 14px; border-top: 1px solid var(--ac-line); }

/* ---- data check ---- */
.ac-issue { border-left: 4px solid var(--ac-muted); background: var(--ac-soft); border-radius: 6px; padding: 6px 10px; margin: 6px 0; }
.ac-issue.ac-error { border-left-color: var(--ac-bad); }
.ac-issue.ac-warning { border-left-color: #d98b00; }
.ac-issue.ac-info { border-left-color: var(--ac-blue); }

.ac-print-title { display: none; }

/* phone-only / desktop-only bits (the rules that switch them are in the phone block below) */
.ac-phone-only { display: none; }

/* ledger picker: the phone list (a full-screen sheet) */
.ac-pick-btn { display: none; }
.ac-sheet { position: fixed; inset: 0; z-index: 200; background: #fff; display: flex; flex-direction: column; }
.ac-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--red, #b51f2e); color: #fff; }
.ac-sheet-head .ac-x { background: rgba(255,255,255,.2); color: #fff; width: 40px; height: 40px; }
.ac .ac-sheet-search { margin: 10px 12px 6px; width: calc(100% - 24px); font-size: 16px; min-height: 46px; padding: 8px 12px; border: 1px solid var(--gray200, #e5e7eb); border-radius: 10px; }
.ac-sheet-body { flex: 1; overflow: auto; padding: 0 12px 16px; }
.ac-sheet-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; font: inherit; font-size: 16px; padding: 12px 10px; margin: 0; border: 0; border-bottom: 1px solid var(--gray200, #e5e7eb); background: none; color: inherit; cursor: pointer; }
.ac-sheet-item small { color: var(--gray500, #6b7280); font-size: 12px; }
.ac-sheet-item.ac-sel { background: #eef4ff; font-weight: 700; }
.ac-sheet-none { color: var(--ac-bad, #b3261e); flex-direction: row; }

/* ============================ phone ============================ */
@media (max-width: 720px) {
    .ac-phone-only { display: inline-flex; }
    .ac-desk-only { display: none; }

    /* title bar that stays put (voucher entry): back link, title, total and Save on one row */
    .ac-top.ac-top-sticky { position: sticky; top: 0; z-index: 60; flex-wrap: nowrap; gap: 8px; padding: 6px 8px; margin-left: -8px; margin-right: -8px; border-radius: 0 0 10px 10px; }
    .ac-top.ac-top-sticky h1 { flex: 1; flex-basis: auto; order: 0; min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ac-top.ac-top-sticky .ac-actions { order: 0; flex-basis: auto; flex-wrap: nowrap; align-items: center; }
    .ac-top-total { font-weight: 700; font-size: 15px; white-space: nowrap; align-items: center; }
    .ac-actions .ac-btn.ac-save-top { background: #2e9b57; border-color: #2e9b57; color: #fff; font-size: 16px; font-weight: 700; min-height: 40px; padding: 6px 16px; }

    /* ledger pickers become a tap-to-open button */
    .ac-picker .ac-pick-input { display: none; }
    .ac-pick-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 46px; padding: 8px 12px; font: inherit; font-size: 16px; text-align: left; border: 1px solid var(--ac-line); border-radius: 10px; background: #fff; color: var(--ac-ink); cursor: pointer; }
    .ac-pick-btn .ac-ph { color: var(--ac-muted); }
    .ac-pick-btn i { font-style: normal; color: var(--ac-muted); }
    .ac-picker.ac-invalid .ac-pick-btn { border-color: var(--ac-bad); }

    /* voucher form: big enough to tap, 16px so the browser doesn't zoom in on focus */
    .ac .ac-voucher input:not([type=checkbox]), .ac .ac-voucher select, .ac .ac-voucher textarea { font-size: 16px; min-height: 46px; padding: 8px 10px; }
    .ac .ac-voucher textarea { min-height: 70px; }
    .ac-voucher .ac-form-row { grid-template-columns: 1fr 1fr; }
    .ac-line .ac-x { width: 44px; height: 44px; font-size: 24px; align-self: end; }
    .ac-voucher .ac-link { display: block; width: 100%; padding: 12px; margin: 4px 0; font-size: 16px; border: 1px dashed var(--ac-accent); border-radius: 10px; text-align: center; }
    .ac-buttons .ac-btn { flex: 1; min-height: 46px; font-size: 16px; }

    .ac { padding: 8px 8px 60px; }
    .ac-form-row, .ac-voucher .ac-form-row { grid-template-columns: 1fr 1fr; }
    .ac-form-row .ac-grow { grid-column: 1 / -1; }
    .ac-sides { grid-template-columns: 1fr; }
    .ac-bar label { max-width: none; }

    /* tables become one card per row, with each cell labelled */
    .ac-stack, .ac-stack tbody, .ac-stack tr, .ac-stack td, .ac-stack tfoot, .ac-stack th { display: block; width: 100%; }
    .ac-stack thead { display: none; }
    .ac-stack { border: 0; background: transparent; }
    .ac-stack tr { background: #fff; border: 1px solid var(--ac-line); border-radius: 10px; margin-bottom: 8px; padding: 4px 10px; }
    .ac-stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
    .ac-stack td::before { content: attr(data-label); flex: none; color: var(--ac-muted); font-size: 12px; text-align: left; }
    .ac-stack td:empty { display: none; }
    .ac-stack tr.ac-group { background: #eef0f4; padding: 2px 10px; }
    .ac-stack tr.ac-group th { display: flex; justify-content: space-between; background: transparent; }
    .ac-stack tfoot tr { background: var(--ac-soft); display: flex; flex-wrap: wrap; justify-content: space-between; }
    .ac-stack tfoot th { width: auto; border: 0; background: transparent; }
    .ac-stack input { text-align: right; max-width: 150px; }

    /* voucher lines: each line is a small card */
    .ac-line, .ac-lines-1 .ac-line, .ac-lines-2 .ac-line { grid-template-columns: 1fr 1fr; border: 1px solid var(--ac-line); border-radius: 10px; padding: 8px; margin-bottom: 8px; background: #fff; }
    .ac-line-head { display: none; }
    .ac-line label > em { display: block; font-size: 12px; color: var(--ac-muted); font-style: normal; margin-bottom: 2px; }
    .ac-line > label:first-child, .ac-lines-2 .ac-line > label:nth-child(2) { grid-column: 1 / -1; }
    .ac-line > .ac-x { grid-column: 2; justify-self: end; }
    .ac-total { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--ac-line); }
    .ac-top h1 { flex-basis: 100%; order: 2; }
    .ac-actions { order: 3; flex-basis: 100%; }
}

/* ============================ print ============================ */
@media print {
    .ac-top, .ac-bar, .ac-filters, .ac-chips, .ac-buttons, .ac-tabs, .ac-actions, .ac-busy, .ac-notice, .ac-link { display: none !important; }
    .ac { max-width: none; padding: 0; font-size: 12px; }
    .ac-print-title { display: block; text-align: center; margin-bottom: 8px; font-size: 14px; }
    .ac-table, .ac-sides section, .ac-card { border-color: #999; }
    .ac a { color: inherit; }
}
