/* Tally Converter - styles for the tool page. No framework, no inline styles (CSP). */
:root {
  --paper: #f6f4ee;
  --card: #ffffff;
  --ink: #17212b;
  --muted: #5d6b78;
  --line: #d9d5ca;
  --accent: #0e6b5c;
  --accent-ink: #ffffff;
  --good: #1d7a46;
  --good-bg: #e6f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --bad: #a3271f;
  --bad-bg: #fde8e6;
  --radius: 8px;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  line-height: 1.45;
}
[hidden] { display: none !important; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--ink);
  color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }

main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 8px; font-size: 1.05rem; }
.hint { margin: 4px 0 10px; color: var(--muted); font-size: .93rem; }

.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 10px; }
.grow { flex: 1 1 240px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.field > span { font-size: .85rem; color: var(--muted); }
input[type="text"], input[type="number"], select, input[type="file"] {
  font: inherit;
  color: inherit;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.btn {
  display: inline-block;
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }

.pill { padding: 4px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600; }
.pill-off { background: #3a4653; color: #dfe5ea; }
.pill-on { background: var(--good-bg); color: var(--good); }
.pill-mock { background: var(--warn-bg); color: var(--warn); }

.msg { margin: 6px 0 0; font-size: .93rem; min-height: 1.3em; }
.msg:empty { min-height: 0; margin: 0; }
.msg-good { color: var(--good); }
.msg-warn { color: var(--warn); }
.msg-bad { color: var(--bad); }

/* Review grid */
.toolbar { align-items: flex-end; }
.gridwrap { max-height: 62vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 5px 8px; border-bottom: 1px solid #ece9e0; text-align: left; vertical-align: middle; }
thead th { position: sticky; top: 0; background: #efece3; z-index: 1; font-weight: 600; white-space: nowrap; }
tfoot td { position: sticky; bottom: 0; background: #efece3; font-weight: 600; border-bottom: 0; }
.c-sel { width: 30px; }
.c-num { width: 44px; color: var(--muted); }
.c-date { width: 92px; white-space: nowrap; }
.c-ref { width: 130px; word-break: break-all; }
.c-amt { width: 118px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-type { width: 126px; }
.c-led { width: 240px; }
.c-status { width: 170px; }
td.c-type select, td.c-led input { padding: 4px 6px; }
tr.row-issue td.c-status { color: var(--warn); }
tr.row-issue td.c-led input { border-color: #d9a400; background: var(--warn-bg); }
tr.row-done { background: var(--good-bg); }
tr.row-done td.c-status { color: var(--good); font-weight: 600; }
tr.row-error { background: var(--bad-bg); }
tr.row-error td.c-status { color: var(--bad); }
tr.row-break td.c-amt:nth-child(7) { color: var(--bad); font-weight: 700; }

/* App frame: top bar, entry types on the left, work area, status bar */
body.app { height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.appbar { justify-content: flex-start; flex-wrap: wrap; gap: 8px 20px; padding: 8px 16px; }
.bar-group { display: flex; align-items: center; gap: 8px; }
.bar-group.grow { flex: 1 1 340px; }
.bar-label { font-size: .85rem; color: #c9d2da; }
.appbar input[type="text"] { width: 118px; padding: 5px 8px; color: var(--ink); letter-spacing: 2px; font-weight: 600; }
.appbar input[type="text"]::placeholder { letter-spacing: 0; font-weight: 400; }
.appbar .btn:disabled { opacity: .8; }
.appbar select { flex: 1 1 200px; min-width: 180px; max-width: 560px; padding: 5px 8px; color: var(--ink); }
.appbar .btn { padding: 5px 12px; }
.appbar select:disabled { opacity: .7; }
.bar-download { margin-left: auto; }

.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 0; }
.side { background: #fff; border-right: 1px solid var(--line); padding: 14px 10px; overflow: auto; }
.side h2 { margin: 0 8px 8px; font-size: .76rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.nav-item {
  display: block; width: 100%; text-align: left; font: inherit; color: var(--ink);
  padding: 8px 10px; margin-bottom: 2px; border: 0; border-radius: 6px; background: none; cursor: pointer;
}
.nav-item:hover { background: #f0eee7; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
body.app main { max-width: none; margin: 0; padding: 16px 20px 24px; overflow: auto; min-width: 0; }
.mod-title { margin: 0 0 12px; font-size: 1.25rem; }

.statusbar { display: flex; align-items: stretch; background: var(--ink); color: #dfe5ea; font-size: .82rem; padding: 0 12px; min-height: 28px; }
.sb-msg { flex: 1 1 auto; min-width: 0; padding: 5px 12px 5px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-seg { flex: 0 0 auto; padding: 5px 12px; border-left: 1px solid #3a4653; white-space: nowrap; }
.sb-samples a { color: #9fd8ff; margin-left: 8px; }
.sb-samples a:hover { color: #fff; }
.sb-good { color: #8fe0ae; }
.sb-warn { color: #ffd166; }
.sb-bad { color: #ff9d94; font-weight: 600; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .side { display: flex; flex-wrap: wrap; gap: 4px; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .side h2 { display: none; }
  .nav-item { width: auto; margin: 0; }
  #sbRows, #sbCompany { display: none; }
}

/* Column mapping */
#mapPanel { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
#mapPanel h3 { margin: 0 0 4px; font-size: 1rem; }
.field.narrow { min-width: 0; width: 210px; }
.check { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; }
.mapwrap { max-height: 300px; }
#mapTable th, #mapTable td { white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
#mapTable thead tr:first-child th { background: #fff; position: static; padding: 6px; }
#mapTable thead tr:nth-child(2) th { position: static; }
#mapTable select { min-width: 150px; padding: 4px 6px; color: var(--muted); }
#mapTable select.mapped { color: var(--ink); border-color: var(--accent); font-weight: 600; }

/* Journal Entries: one block per voucher, its ledger lines in a small table */
input[type="date"] { font: inherit; color: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
input[type="date"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.btn-small { padding: 4px 10px; font-size: .88rem; }
#jList { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.jv { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 6px; background: #fff; }
.jv-ready { border-left-color: var(--accent); }
.jv-issue { border-left-color: #d9a400; }
.jv-done { border-left-color: var(--good); background: #f7fbf8; }
.jv-error { border-left-color: var(--bad); }
.jv-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; padding: 10px 12px; border-bottom: 1px solid #ece9e0; }
.jv-head > input[type="checkbox"] { margin-bottom: 10px; }
.jv-head .field { min-width: 0; }
.jv-head .jv-date { width: 150px; flex: 0 0 auto; }
.jv-head .jv-number { width: 140px; flex: 0 0 auto; }
.jv-head .grow { flex: 3 1 220px; }
.jv-no { font-weight: 700; color: var(--muted); padding-bottom: 8px; min-width: 32px; }
.jv-status { flex: 1 1 140px; min-width: 0; padding-bottom: 8px; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jv-ready .jv-status { color: var(--accent); font-weight: 600; }
.jv-issue .jv-status { color: var(--warn); }
.jv-done .jv-status { color: var(--good); font-weight: 600; }
.jv-error .jv-status { color: var(--bad); }
.jv-lines th { position: static; }
.jv-lines td { padding: 3px 8px; }
.jv-lines input[type="text"] { padding: 4px 6px; }
.jv-lines td.c-amt input { text-align: right; font-variant-numeric: tabular-nums; }
.jv-lines .c-side { width: 54px; color: var(--muted); font-weight: 600; }
.jv-lines .c-del { width: 44px; text-align: center; }
.jv-lines .c-amt { width: 150px; }
.jv-lines tfoot td { position: static; background: #faf9f5; }
.jv-diff { font-weight: 600; }
.jv-off { color: var(--bad); }
.jv-even { color: var(--good); }
.jv-lines tr.line-unknown input[data-f="ledger"] { border-color: #d9a400; background: var(--warn-bg); }
#jType { width: 100%; }
.jv-head > .btn-small { margin-bottom: 6px; flex: 0 0 auto; }

/* Tally release, licence and serial number badge in the top bar */
.pill-lic { white-space: nowrap; cursor: pointer; }
.pill-lic:hover, .pill-lic:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.pill-edu { background: #fde8e6; color: #b3261e; border: 1px solid #f1b5ae; }

/* Educational Mode notice under the top bar */
.edu-banner { background: #fde8e6; color: #8c1d18; border-bottom: 1px solid #f1b5ae; padding: 8px 20px; font-size: .92rem; line-height: 1.45; }
.edu-banner strong { color: #b3261e; }
.edu-banner .edu-fix { display: inline-block; margin-left: 6px; color: #6b3a36; }
/* Fixed rows so the notice (row 2) takes only its own height, and none when hidden */
body.app { grid-template-rows: auto auto minmax(0, 1fr) auto; }
body.app > header { grid-row: 1; }
body.app > .notices { grid-row: 2; }
body.app > .shell { grid-row: 3; }
body.app > footer { grid-row: 4; }

/* Create ledgers in Tally: the hint under the ledger fields, the toolbar button, the link in a row, the dialog */
.btn-warn { background: var(--warn-bg); border-color: #d9a400; color: var(--warn); font-weight: 600; }
.newled { margin: 8px 0 0; padding: 6px 10px; border: 1px solid #d9a400; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: .93rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.linkbtn { border: 0; background: none; padding: 0; font: inherit; color: var(--warn); text-decoration: underline; cursor: pointer; }
.linkbtn:hover, .linkbtn:focus-visible { color: var(--accent); }
.jv-status.jv-create { cursor: pointer; text-decoration: underline; }
.dlg { width: min(900px, 94vw); max-height: 88vh; border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; color: var(--ink); }
.dlg::backdrop { background: rgba(20, 28, 36, .45); }
.dlg h2 { margin: 0 0 4px; }
.ld-wrap { max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.ld-table { width: 100%; border-collapse: collapse; }
.ld-table th { position: sticky; top: 0; background: #f0ede4; text-align: left; padding: 6px 8px; font-size: .85rem; }
.ld-table td { padding: 4px 8px; border-top: 1px solid #ece9e0; vertical-align: middle; }
.ld-table input[type="text"], .ld-table select { width: 100%; padding: 5px 7px; }
.ld-table select:invalid, .ld-table .ld-bad { border-color: var(--bad); background: var(--bad-bg); }
.ld-table td.ld-res { width: 190px; font-size: .88rem; color: var(--muted); }
.ld-table tr.ld-done td.ld-res { color: var(--good); font-weight: 600; }
.ld-table tr.ld-fail td.ld-res { color: var(--bad); }
.ld-actions { margin-top: 10px; align-items: center; }
.ld-actions .hint { margin: 0; }

/* Review grid: the ledger box is where the work happens, so it keeps its width when the window is narrow */
#grid td.c-narr { min-width: 170px; }
#grid .c-amt { width: 104px; }
#grid .c-type { width: 112px; }
#grid td.c-narr .ref { display: block; color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
#grid td.c-led input { width: 100%; min-width: 200px; }
#grid td.c-type select { min-width: 100px; }
#grid th.c-status, #grid td.c-status { min-width: 104px; }
#grid .linkbtn { white-space: nowrap; }

/* A Tally that is open but could not be used, and the report dialog */
.tn-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tn-line + .tn-line { margin-top: 6px; }
.tn-line .btn { flex: 0 0 auto; }
.tally-notice { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #d9a400; padding: 8px 20px; font-size: .92rem; line-height: 1.45; }
.rp-text { max-height: 56vh; overflow: auto; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: #faf9f5; font: .82rem/1.45 Consolas, "Courier New", monospace; white-space: pre; }

/* Ledger suggestions: one floating list shared by every ledger box */
.sug { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(20, 28, 36, .18); max-height: 320px; overflow: auto; font-size: .92rem; }
.sug-item { display: flex; justify-content: space-between; gap: 14px; padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.sug-item .sug-grp { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; }
.sug-item.on, .sug-item:hover { background: #e6f1ee; }
.sug-item.sug-new { color: var(--accent); font-weight: 600; border-top: 1px solid #ece9e0; }
/* The company's own bank / cash ledgers as one-click chips */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; font-size: .9rem; color: var(--muted); }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 12px; font: inherit; color: var(--ink); cursor: pointer; }
.chip:hover, .chip:focus-visible { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.chip-new { border-style: dashed; color: var(--accent); }
/* A note the user adds under a statement narration; the narration itself stays as the bank printed it */
#grid td.c-narr .note-add { display: inline-block; margin-top: 2px; font-size: .82rem; }
#grid td.c-narr input.note { display: block; width: 100%; margin-top: 3px; padding: 3px 6px; font-size: .85rem; border: 1px dashed #b9b4a6; border-radius: 4px; background: #fffdf4; }
#grid td.c-narr input.note:focus { border-style: solid; }

/* Status bar on a narrow screen: the segments shorten with "..." instead of pushing the page wider than the window */
.statusbar { overflow: hidden; }
.sb-msg { flex: 1 1000 auto; }   /* the message gives way first; the fixed segments shorten only after it */
.sb-seg { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sb-seg.sb-samples { flex: 0 0 auto; }

/* Tally details (click the licence badge): one fact per line, the technical report folded under it */
.facts { width: 100%; border-collapse: collapse; margin: 4px 0 12px; }
.facts th { width: 190px; text-align: left; font-weight: 600; color: var(--muted); padding: 6px 10px 6px 0; vertical-align: top; white-space: nowrap; }
.facts td { padding: 6px 0; border-bottom: 1px solid #ece9e0; overflow-wrap: anywhere; }
.facts th { border-bottom: 1px solid #ece9e0; }
.facts .fact-note { display: block; color: var(--muted); font-size: .85rem; }
.facts .fact-warn { color: #9a5b00; font-weight: 600; }
.facts .fact-bad { color: var(--bad); font-weight: 600; }
.rp-more > summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
.rp-more .rp-text { max-height: 38vh; }

