:root {
  --navy: #1f2a44;
  --navy2: #2d3b5e;
  --bg: #f2f4f8;
  --card: #fff;
  --line: #d5dae3;
  --text: #1c2230;
  --muted: #6b7486;
  --yellow: #fff6b0;
  --gray: #c9c9c9;
  --bal: #e4e4e4;
  --red: #c62828;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--red); min-height: 1.2em; }

/* Login */
#loginView { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--card); padding: 28px 22px; border-radius: 14px; width: 100%; max-width: 360px;
  box-shadow: 0 6px 24px rgba(0,0,0,.08); text-align: center; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-logo { width: 56px; height: 56px; }
.login-card form { text-align: left; margin-top: 18px; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top)); }
.topbar .title { font-weight: bold; font-size: 17px; letter-spacing: .3px; }
.icon-btn { background: transparent; border: 0; color: #fff; font-size: 20px; padding: 4px 8px; }

/* Form */
.panel { background: var(--card); margin: 10px; padding: 12px; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
input, select { display: block; width: 100%; margin-top: 4px; font-size: 16px; padding: 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus { outline: 2px solid #7f9cf5; border-color: transparent; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.row2 > * { min-width: 0; }
input[type="date"] { min-width: 0; -webkit-appearance: none; appearance: none; min-height: 44px; }
.chk { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 6px 0; }
.chk input { width: 20px; height: 20px; margin: 0; flex: none; }
.chk.small { font-size: 13px; color: var(--muted); margin: 6px 4px; }
.chk-col { padding-top: 14px; }
.chk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin: 8px 0; }
.print-opts { margin: 12px 0 4px; border-top: 1px solid var(--line); padding-top: 8px; }
.print-opts summary { font-size: 14px; color: var(--navy2); font-weight: bold; padding: 6px 0; }
.actions { margin-top: 10px; }

.btn { font-size: 16px; padding: 11px 14px; border-radius: 8px; border: 1px solid var(--navy2);
  background: #fff; color: var(--navy2); font-weight: bold; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.block { width: 100%; margin-top: 4px; }
.btn:disabled { opacity: .45; }
.link { background: none; border: 0; color: var(--muted); margin-top: 10px; font-size: 14px; }

/* Party search */
.party-wrap { position: relative; margin-bottom: 8px; }
.party-wrap input { margin-top: 0; font-weight: bold; }
.party-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 10; max-height: 50vh; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.party-list div { padding: 11px 12px; border-bottom: 1px solid #eef0f4; }
.party-list div:active, .party-list div.sel { background: #e8eefc; }

.msg { margin: 10px; padding: 10px 12px; border-radius: 8px; background: #fdecea; color: var(--red); }

/* Result */
.result-head { display: flex; justify-content: space-between; align-items: flex-end; margin: 4px 12px 8px; }
.closing { text-align: right; }
.closing b { font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 10px 8px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 4px 10px; font-size: 13px; }
.chip b { margin-left: 4px; }

.tabs { display: flex; margin: 0 10px; border-bottom: 2px solid var(--line); }
.tab { flex: 1; background: none; border: 0; padding: 10px 4px; font-size: 14px; color: var(--muted); font-weight: bold;
  border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); }
.tabpane { padding-bottom: 30px; }
.tabpane h3 { margin: 14px 12px 6px; font-size: 15px; }

/* Grid (ledger table) */
.table-wrap { overflow: auto; margin: 6px 10px; background: #fff; border: 1px solid #888; max-height: 70vh; }
table.grid { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.grid th, .grid td { border: 1px solid #999; padding: 4px 5px; white-space: nowrap; }
.grid th { position: sticky; top: 0; background: #cfcfcf; z-index: 1; font-weight: bold; }
.grid td.n { text-align: right; }
.grid td.c { text-align: center; }
.grid td.p { font-weight: bold; white-space: pre-wrap; min-width: 150px; max-width: 260px; }
.grid tr.yellow td { background: var(--yellow); }
.grid tr.gray td { background: var(--gray); }
.grid tr.open td { font-weight: bold; font-size: 14px; }
.grid tr.total td { font-weight: bold; }
.grid tr.bal td { background: var(--bal); font-weight: bold; font-size: 14px; }
.grid tr.bold td { font-weight: bold; }
.grid .x { display: none; }
.grid.extra .x { display: table-cell; }

/* Modal + busy */
.modal, .busy { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 340px; text-align: center; }
.modal-card h3 { margin-top: 0; }
.busy { background: rgba(255,255,255,.55); }
.spinner { width: 42px; height: 42px; border: 4px solid #c8d0e0; border-top-color: var(--navy); border-radius: 50%;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
