:root {
    --obsidian: #1C1C1E;
    --lilac: #C8B6E2;
    --lilac-soft: #EFE8F7;
    --green: #8FB996;
    --green-soft: #E9F3EA;
    --red: #C97C7C;
    --red-soft: #FBEEEE;
    --bg: #FAFAF8;
    --surface: #FFFFFF;
    --border: #E7E5E4;
    --muted: #8A8A8E;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--obsidian);
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
}

/* ---------- Top bar / tabs ---------- */
.topbar {
    display: flex;
    align-items: baseline;
    gap: 32px;
    padding: 20px 28px 0 28px;
    background: var(--bg);
}

.brand {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--obsidian);
    margin: 0 0 14px 0;
}

.tabs {
    display: flex;
    gap: 24px;
}

.tab {
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
    padding: 0 2px 12px 2px;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: var(--obsidian);
    border-bottom-color: var(--lilac);
    font-weight: 600;
}

.tab:hover { color: var(--obsidian); }

hr.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0;
}

/* ---------- Page content ---------- */
main {
    padding: 20px 28px 60px 28px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.toolbar label {
    font-size: 12px;
    color: var(--muted);
    margin-right: 6px;
}

.toolbar .group {
    display: flex;
    align-items: center;
}

.quickadd-hint {
    font-size: 12px;
    color: var(--muted);
    margin: 0 0 6px 0;
}

.quickadd-example {
    font-family: monospace;
    background: var(--lilac-soft);
    padding: 4px 6px;
    border-radius: 4px;
    display: block;
}

#quickAddModalText {
    width: 100%;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    margin: 10px 0 4px 0;
}

.spacer { flex: 1; }

input, select, textarea {
    font-family: inherit;
    font-size: 14px;
    color: var(--obsidian);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 8px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--lilac);
    box-shadow: 0 0 0 2px var(--lilac-soft);
}

button {
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--obsidian);
    padding: 7px 14px;
}

button:hover { border-color: var(--lilac); }

button.primary {
    background: var(--lilac);
    border-color: var(--lilac);
    color: var(--obsidian);
    font-weight: 600;
}

button.primary:hover { background: #bda3d9; }

button.primary.posted {
    background: var(--green);
    border-color: var(--green);
}

button.danger {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
    font-weight: 600;
}

button.danger:hover { background: #b86b6b; border-color: #b86b6b; }

button.danger-outline {
    color: var(--red);
    border-color: var(--red);
}

button.danger-outline:hover { background: var(--red-soft); border-color: var(--red); }

button.danger:disabled,
button.danger:disabled:hover {
    background: var(--surface);
    border-color: var(--border);
    color: var(--muted);
    cursor: default;
}

button.icon {
    border: none;
    background: none;
    padding: 2px 4px;
    color: var(--muted);
}

button.icon:hover { color: var(--obsidian); }

.status-text {
    font-size: 12px;
    color: var(--muted);
}

/* ---------- Grid ---------- */
.grid-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}

table.grid {
    border-collapse: collapse;
    width: 100%;
    min-width: 2200px;
}

table.grid thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    z-index: 1;
}

table.grid td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}

table.grid tbody tr:hover { background: #FCFBFB; }

table.grid td input,
table.grid td select {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    padding: 6px 8px;
    border-radius: 3px;
}

table.grid td input:hover,
table.grid td select:hover {
    border-color: var(--border);
}

table.grid input[type="date"] { min-width: 128px; }
table.grid input.amount, table.grid input.qty { text-align: right; }
table.grid input.narrow { width: 90px; }

table.grid .col-select { width: 32px; text-align: center; padding-left: 8px; padding-right: 4px; }
table.grid .col-select input[type="checkbox"] { width: auto; cursor: pointer; }
tr.row-selected { background: var(--red-soft); }
table.grid tbody tr.row-selected:hover { background: var(--red-soft); }

tr.row-draft { border-left: 3px solid var(--lilac); }
tr.row-draft td:first-child { padding-left: 5px; }

tr.row-posted-flash { background: var(--green-soft); transition: background 1.2s ease; }

tr.row-dirty td:first-child { box-shadow: inset 3px 0 0 var(--lilac); }

tr.row-duplicate { background: var(--red-soft); }

.cell-muted {
    color: var(--muted);
    padding: 6px 8px;
    font-size: 14px;
}

.field-invalid {
    border-color: var(--red) !important;
    background: var(--red-soft) !important;
}

.row-errors {
    font-size: 11px;
    color: var(--red);
    padding-top: 2px;
}

.dup-banner {
    font-size: 11px;
    color: var(--red);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.dup-banner button {
    padding: 2px 8px;
    font-size: 11px;
    border-color: var(--red);
}

.badge-journal {
    font-size: 10px;
    color: var(--muted);
}

.paste-summary {
    font-size: 12px;
    background: var(--lilac-soft);
    border: 1px solid var(--lilac);
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 12px;
}

.ref-cell { display: flex; align-items: center; gap: 4px; }
.ref-cell input { flex: 1; }
.ref-file-name { font-size: 10px; color: var(--muted); max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- History modal ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(28, 28, 30, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal {
    background: var(--surface);
    border-radius: 8px;
    padding: 20px 22px;
    width: 480px;
    max-width: 92vw;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: 15px;
    margin: 0 0 12px 0;
}

.modal table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.modal table th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
}

.modal table td {
    padding: 6px 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.modal .close-row {
    text-align: right;
    margin-top: 14px;
}

.placeholder-note {
    color: var(--muted);
    font-size: 13px;
    padding: 40px 0;
    text-align: center;
}

/* ---------- Journal / Khatian (read-only reports) ---------- */
.panel {
    margin-bottom: 36px;
}

.panel h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 16px 0;
}

/* Journal / Khatian tables have few columns and room to breathe — bigger
   type and taller rows than the Posting grid. table-layout: fixed plus
   the col widths below keep Date / Journal No. / Debit / Credit / Balance
   compact while Particulars (the one column with no fixed width) takes
   whatever space is left over. */
.panel .toolbar label {
    font-size: 13px;
}

.panel .status-text {
    font-size: 13px;
}

.panel .toolbar input,
.panel .toolbar select,
.panel .toolbar button {
    font-size: 15px;
    padding: 8px 10px;
}

table.plain-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 820px;
    table-layout: fixed;
}

table.plain-table col.col-date { width: 130px; }
table.plain-table col.col-jno { width: 110px; }
table.plain-table col.col-type { width: 90px; }
table.plain-table col.col-num { width: 150px; }

table.plain-table th {
    text-align: left;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.plain-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    white-space: pre;
}

table.plain-table th.num,
table.plain-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

table.plain-table tr.journal-narration td {
    color: var(--muted);
    font-style: italic;
    font-size: 13px;
    padding-top: 0;
    white-space: normal;
}

table.plain-table tr.khatian-summary td {
    font-weight: 600;
    background: var(--lilac-soft);
}

/* "All accounts" ledger: the heading above each account's block. */
table.plain-table tr.ledger-account td {
    font-weight: 700;
    font-size: 16px;
    padding-top: 26px;
    white-space: normal;
    border-bottom: 2px solid var(--border);
}

.opening-prompt {
    font-size: 14px;
    background: var(--lilac-soft);
    border: 1px solid var(--lilac);
    border-radius: 4px;
    padding: 12px 14px;
    margin-bottom: 14px;
}

.opening-prompt .row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.opening-prompt input {
    max-width: 160px;
}

/* ---------- Balance Sheet ---------- */
table.bs-table { min-width: 520px; max-width: 820px; }
table.plain-table tr.bs-heading td {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 13px;
    padding-top: 22px;
}
table.plain-table tr.bs-line td:first-child { padding-left: 32px; }
table.plain-table tr.bs-note td {
    color: var(--muted);
    font-style: italic;
    font-size: 13px;
    padding-top: 0;
    padding-left: 32px;
    white-space: normal;
}
table.plain-table tr.bs-check-ok td { background: var(--green-soft); }
table.plain-table tr.bs-check-bad td { background: var(--red-soft); color: var(--red); }
.bs-warning {
    font-size: 14px;
    background: var(--red-soft);
    border: 1px solid var(--red);
    border-radius: 4px;
    padding: 10px 14px;
    margin-bottom: 12px;
}
.bs-warning ul { margin: 8px 0 0 0; padding-left: 20px; }

/* ---------- Financial Summary (journal.php) ---------- */
.fs-section { margin-bottom: 28px; }
.fs-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 8px 0;
}
table.fs-table { min-width: 520px; max-width: 900px; }
table.fs-table td { white-space: normal; }
table.plain-table tr.fs-subtle td { color: var(--muted); font-style: italic; font-size: 13px; }

/* ---------- PDF (browser print-to-PDF) ---------- */
.panel .toolbar button.pdf-btn {
    font-size: 12px;
    padding: 4px 8px;
    color: var(--muted);
}
.panel .toolbar button.pdf-btn:hover { color: var(--obsidian); }

.print-only { display: none; }

@media print {
    @page { size: A4; margin: 12mm; }
    html, body { background: #fff; font-size: 11px; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    /* web-only elements */
    .topbar, hr.divider, .toolbar, .pdf-btn, #kOpeningPrompt { display: none !important; }
    /* PDF ↓ prints only the panel it belongs to */
    body.print-one section.panel:not(.print-target) { display: none; }

    main { padding: 0; }
    .panel { margin: 0; }
    .panel h2 { font-size: 15px; margin: 0 0 4px 0; }
    .print-only { display: block; }
    .print-caption { font-size: 11px; color: var(--muted); margin: 0 0 10px 0; }

    .grid-wrap { overflow: visible; border: none; border-radius: 0; }
    table.plain-table, table.bs-table { min-width: 0; max-width: none; }
    table.plain-table col.col-date { width: 70px; }
    table.plain-table col.col-jno { width: 60px; }
    table.plain-table col.col-type { width: 40px; }
    table.plain-table col.col-num { width: 95px; }
    table.plain-table th { font-size: 9px; padding: 5px 6px; }
    table.plain-table td { font-size: 10px; padding: 4px 6px; white-space: pre-wrap; }
    table.plain-table tr { break-inside: avoid; }
    table.plain-table tr.bs-heading td { padding-top: 12px; }
    table.plain-table tr.bs-line td:first-child,
    table.plain-table tr.bs-note td { padding-left: 18px; }
    .bs-warning { font-size: 10px; break-inside: avoid; }
    table.fs-table { min-width: 0; max-width: none; }
    .fs-section { margin-bottom: 14px; break-inside: avoid; }
    .fs-section h3 { font-size: 12px; margin: 0 0 4px 0; }
}
