/* shadcn/ui's default "zinc" theme tokens, ported to plain CSS variables --
   same neutral palette, radius and shadow scale as shadcn's Tailwind config,
   no build step or component library required. */
:root {
    --ink: #18181b;             /* zinc-900 (foreground) */
    --muted: #71717a;           /* zinc-500 (muted-foreground) */
    --muted-bg: #f4f4f5;        /* zinc-100 (secondary/badge background) */
    --border: #e4e4e7;          /* zinc-200 (border/input) */
    --bg: #fafafa;              /* zinc-50 (app background) */
    --panel: #ffffff;           /* card background */
    --accent: #18181b;          /* zinc-900 (primary) */
    --accent-ink: #fafafa;      /* zinc-50 (primary-foreground) */
    --ring: rgba(24, 24, 27, 0.14);
    --dr: #18181b;
    --cr: #dc2626;              /* red-600 (destructive) */
    --good: #16a34a;            /* green-600 */
    --radius: 0.5rem;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.045);
    --sidebar-width: 230px;
    --sidebar-bg: #18181b;      /* zinc-900 */
    --sidebar-active-bg: #27272a; /* zinc-800 -- distinct from sidebar-bg so "active" reads clearly */
    --sidebar-ink: #d4d4d8;      /* zinc-300 */
    --sidebar-ink-muted: #71717a; /* zinc-500 */
    --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.45;
}

.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    font-weight: 700;
    color: #ffffff;
    font-size: 1rem;
    line-height: 1.3;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.75rem;
}

.sidebar-nav { flex: 1; padding: 0 0.75rem 1rem; }

.sidebar-group { margin-top: 1.25rem; }

.sidebar-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sidebar-ink-muted);
    padding: 0 0.6rem 0.4rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius);
    color: var(--sidebar-ink);
    text-decoration: none;
    font-size: 0.87rem;
    margin-bottom: 0.15rem;
}

.sidebar-link:hover { background: var(--sidebar-hover-bg); color: #ffffff; }

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: #ffffff;
    font-weight: 600;
}

.nav-icon {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius);
    color: var(--sidebar-ink);
    text-decoration: none;
    font-size: 0.85rem;
}

.sidebar-footer a:hover { background: var(--sidebar-hover-bg); color: #ffffff; }

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.app-header-title {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
}

.app-header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.app-header-nav-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.87rem;
    font-weight: 600;
}

.app-header-nav-link:hover { color: var(--ink); }

.app-header-nav-link.active { color: var(--accent); }

.quick-add {
    position: relative;
}

.quick-add-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    min-width: 240px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgb(0 0 0 / 0.1);
    padding: 0.5rem;
    z-index: 10;
}

.quick-add-menu.open { display: block; }

.quick-add-menu a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
    font-size: 0.85rem;
}

.quick-add-menu a:hover { background: var(--muted-bg); }

.quick-add-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius);
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
}

.quick-add-menu-btn:hover { background: var(--muted-bg); opacity: 1; }

.quick-add-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 0.3rem 0.6rem;
}

.quick-add-divider {
    height: 1px;
    background: var(--border);
    margin: 0.4rem 0;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    align-items: flex-start;
    justify-content: center;
    padding: 10vh 1rem 1rem;
    z-index: 50;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgb(0 0 0 / 0.2);
    width: 100%;
    max-width: 420px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.1rem 0.75rem;
    font-weight: 700;
    font-size: 0.95rem;
}

.modal-close {
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--muted);
    font-size: 1.4rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.modal-close:hover { color: var(--ink); opacity: 1; }

.modal-search {
    margin: 0 1.1rem 0.75rem;
    width: auto;
}

.modal-list {
    overflow-y: auto;
    padding: 0 0.6rem 0.6rem;
}

.modal-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.5rem;
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
    font-size: 0.88rem;
}

.modal-list-item:hover { background: var(--muted-bg); }

.modal-empty {
    padding: 1rem 0.5rem;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
}

.link-btn {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    color: #2563eb;
    text-decoration: underline;
    font-size: inherit;
    font-weight: inherit;
    cursor: pointer;
}

.link-btn:hover { opacity: 0.8; }

.statement-picker-form {
    padding: 0 1.1rem 1.1rem;
}

.statement-picker-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 40vh;
    overflow-y: auto;
    margin-bottom: 0.9rem;
}

.statement-picker-option {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.88rem;
    cursor: pointer;
}

.statement-picker-option input[type="checkbox"] {
    width: auto;
}

.statement-picker-dates {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.statement-picker-dates label {
    flex: 1;
    font-size: 0.78rem;
    color: var(--muted);
}

.statement-picker-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
}

.container {
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.75rem; }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: 0.92rem; }

.account-contact-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem 1.25rem;
    color: var(--ink);
    font-size: 0.95rem;
    margin: 0 0 0.75rem;
}

.account-contact-line .muted { color: var(--muted); }

.statement-letterhead {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    margin-bottom: 0.15rem;
}

.statement-billto {
    display: inline-block;
    min-width: 280px;
    margin-bottom: 1.5rem;
}

.statement-billto-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.3rem;
}

.statement-billto-name {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
}

.statement-billto-line {
    font-size: 0.88rem;
    color: var(--ink);
}

.entry-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}

.toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.toolbar-filters {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.toolbar-filters input { width: 240px; }
.toolbar-filters select { width: auto; min-width: 160px; }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.panel > *:first-child { margin-top: 0; }

.panel-scroll { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

th, td {
    text-align: left;
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

td.particulars, th.particulars { white-space: normal; min-width: 220px; }

.dr { color: var(--dr); }
.cr { color: var(--cr); font-weight: 600; }

.stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 640px) { .stat-row { grid-template-columns: 1fr; } }

.stat-tile {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 0.9rem 1.1rem;
}

.stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 0.3rem;
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.cat-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
}

.cat-tab {
    background: var(--panel);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.cat-tab:hover { color: var(--ink); border-color: var(--accent); }

.cat-tab.active {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}

.cat-tab-count {
    font-size: 0.75rem;
    opacity: 0.75;
}

.balance-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}
@media (max-width: 1200px) { .balance-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 620px) { .balance-grid { grid-template-columns: 1fr; } }

.totals-row td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: none; }

.mismatch-warning {
    background: #fff4e5;
    border: 1px solid #f0c36d;
    border-radius: var(--radius);
    color: #7a4b00;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

form.inline-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    align-items: end;
}

form.inline-form label {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

/* Vertical stack of related fields inside one table cell or form slot (e.g. an
   Account select with a Flock picker underneath it) -- flex-column so they
   never sit side by side or overflow into a neighbouring cell. */
.field-stack {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    white-space: normal;
}
.field-stack > select,
.field-stack > input,
.field-stack > .flock-radio-group {
    width: 100%;
}

/* Radio/checkbox inputs opt out of the block-level input/select sizing rules
   below (full-width, 2.4rem tall) -- they stay their natural small size
   wherever they're used, in this app or any future one. */
input[type="radio"],
input[type="checkbox"] {
    width: auto;
    min-height: 0;
    padding: 0;
}

.voucher-table {
    table-layout: fixed;
    width: 100%;
    min-width: 1100px;
}

/* Flock picker: a small caption plus a row of pill toggles (radios under the
   hood) that sit right under the Account select they belong to -- reads as
   part of that field instead of a separate boxed panel. */
.flock-radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px dashed var(--border);
}

.flock-picker-label {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 700;
}

.flock-pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.flock-radio-option {
    display: inline-flex;
    position: relative;
    cursor: pointer;
}

.flock-radio-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    pointer-events: none;
}

.flock-radio-option span {
    padding: 0.28rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.2;
    white-space: nowrap;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.flock-radio-option:hover span {
    border-color: var(--accent);
    color: var(--accent);
}

.flock-radio-option input:checked + span {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

.flock-radio-option input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Zoho Books / QuickBooks-style line-item grid: fields read as plain text
   until the row is touched, so the grid reads as a sheet of data rather than
   a wall of boxes; the outline only appears on hover/focus, and the delete
   icon only appears once there's a row to delete it from. */
.voucher-table th {
    background: var(--bg);
}

.voucher-table td {
    padding: 0.3rem 0.5rem;
    vertical-align: middle;
}

.voucher-table tbody tr.voucher-row {
    transition: background-color 0.1s ease;
}

.voucher-table tbody tr.voucher-row:hover {
    background: var(--bg);
}

.voucher-table input,
.voucher-table select {
    background: transparent;
    border-color: var(--border);
    min-height: 2.15rem;
    padding: 0.4rem 0.5rem;
}

.voucher-table td.num input {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.voucher-table tbody tr.voucher-row:hover input,
.voucher-table tbody tr.voucher-row:hover select,
.voucher-table input:focus,
.voucher-table select:focus {
    background: var(--panel);
}

.voucher-table input:focus,
.voucher-table select:focus {
    border-color: var(--accent);
}

.voucher-table input[readonly] {
    background: transparent;
    color: var(--ink);
    font-weight: 600;
    cursor: default;
}

.voucher-table tbody tr.voucher-row:hover input[readonly] {
    background: transparent;
}

.stock-hint {
    font-size: 0.7rem;
    color: var(--muted);
    white-space: normal;
    padding: 0.15rem 0.1rem 0;
    line-height: 1.3;
}

.stock-hint.warn {
    color: #b45309;
    font-weight: 600;
}

.voucher-row-actions {
    text-align: center;
}

.remove-row-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.15rem;
    line-height: 1;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.1s ease, color 0.1s ease;
}

.voucher-table tbody tr.voucher-row:hover .remove-row-btn {
    opacity: 1;
}

.remove-row-btn:hover {
    color: var(--cr);
}

.voucher-actions-row {
    margin-top: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.voucher-add-row-btn {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--accent);
    font-weight: 600;
}

.voucher-add-row-btn:hover {
    background: var(--bg);
    border-color: var(--accent);
}

input, select {
    width: 100%;
    min-height: 2.4rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    font-size: 0.92rem;
    line-height: 1.35;
    font-family: inherit;
    background: var(--panel);
    color: var(--ink);
    box-sizing: border-box;
}

select {
    /* Extra right padding so long option text never runs under the
       browser's native dropdown arrow. */
    padding-right: 1.75rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px var(--ring);
}

input[readonly] {
    background: var(--muted-bg);
    color: var(--muted);
    cursor: not-allowed;
}

button, .btn {
    background: var(--accent);
    color: var(--accent-ink);
    border: none;
    border-radius: var(--radius);
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.12s ease, opacity 0.12s ease;
}
button:hover, .btn:hover { opacity: 0.9; }

.btn-ghost {
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg);
    opacity: 1;
}

.btn-danger { background: var(--cr); }

.btn-sm {
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
}

a.void-link { color: var(--muted); font-size: 0.8rem; }

.type-badge {
    display: inline-block;
    font-size: 0.72rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: var(--muted-bg);
    color: var(--muted);
}

.type-badge-select {
    display: inline-block;
    width: auto;
    min-height: 0;
    font-size: 0.72rem;
    padding: 0.15rem 1.4rem 0.15rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--muted-bg);
    color: var(--muted);
    cursor: pointer;
}

.account-name a { color: var(--ink); text-decoration: none; font-weight: 600; }
.account-name a:hover { color: var(--accent); }

.field-hint { display: block; margin-top: 0.25rem; }

.print-only { display: none; }

.page-label {
    color: var(--muted);
    font-size: 0.8rem;
    text-align: right;
    margin: 0 0 0.5rem;
}

.print-page-break {
    page-break-after: always;
    break-after: page;
}

.screen-hidden { display: none; }

.pagination {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.pagination .btn.active {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}

.pagination .btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

@media print {
    @page { size: A4; margin: 15mm; }
    .sidebar, .no-print { display: none !important; }
    .print-only { display: block; }
    .screen-hidden { display: block; }
    body { background: white; }
    .panel { border: none; padding: 0; }
    .print-page { margin-bottom: 0; }
    table { break-inside: auto; }
    tr { break-inside: avoid; }
    thead { display: table-header-group; }
}

@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .sidebar-brand { border-bottom: none; margin-bottom: 0; padding: 0.9rem 1rem; }
    .sidebar-nav { display: flex; flex-wrap: wrap; padding: 0.5rem 0.75rem; }
    .sidebar-group { margin-top: 0; margin-left: 0.75rem; display: flex; align-items: center; flex-wrap: wrap; }
    .sidebar-group-label { display: none; }
    .sidebar-footer { border-top: none; }
    .app-header { flex-wrap: wrap; position: static; }
}
