/* Vanigam Web — compact, keyboard-first, desktop-application look. Blue theme. */
:root {
    --accent: #0f3d91;
    --accent-dark: #0a2d6e;
    --blue: #1e63e9;
    --blue-dark: #174fc0;
    --blue-soft: #e8f0fe;
    --blue-tint: #f3f7ff;
    --navy: #0f2f6b;
    --ink: #1b2433;
    --muted: #64708a;
    --line: #d5deec;
    --line-soft: #e8eef7;
    --panel: #ffffff;
    --app: #eef3fa;
    --title: #0f2f6b;
    --head: #eaf1fd;
    --success: #1faa59;
    --warning: #e8890c;
    --danger: #d32f2f;
    --row-alt: #f7faff;
    --focus: #dbe8ff;
    --radius: 4px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--ink); background: var(--app); overflow: hidden; user-select: none; }
input, select, textarea, button { font: inherit; color: inherit; }
input, textarea, .selectable { user-select: text; }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.danger { color: var(--danger); }
.success { color: var(--success); }
.bold { font-weight: 600; }
kbd { font: 11px Consolas, monospace; padding: 0 4px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; background: #fff; color: var(--muted); }

/* ── Window frame ─────────────────────────────────────────── */
#app { display: grid; grid-template-rows: 46px 36px 1fr 28px; grid-template-columns: 210px 1fr; height: 100vh; }
#titlebar { grid-column: 1 / 3; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: linear-gradient(90deg, #0f2f6b, #1748a8); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.15); }
#titlebar .logo { width: 30px; height: 30px; border-radius: 7px; background: #fff; color: var(--blue); display: grid; place-items: center; font-weight: 800; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
#titlebar .app-name { font-weight: 600; letter-spacing: .3px; }
#titlebar select { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius); height: 30px; padding: 0 10px; max-width: 240px; }
#titlebar .spacer { flex: 1; }
#titlebar select option { color: var(--ink); }
#titlebar .chip { padding: 4px 10px; border-radius: 10px; font-size: 12px; background: rgba(255,255,255,.14); }
#titlebar .chip.online { background: #17804a; }
#titlebar .chip.offline { background: #a23535; }
#titlebar .chip.pending { background: #b07610; }
#titlebar button { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: var(--radius); height: 30px; padding: 0 14px; cursor: pointer; }
#titlebar button:hover { background: rgba(255,255,255,.2); }

#sidebar { grid-row: 2 / 4; background: linear-gradient(180deg, #f7faff, #edf3fd); border-right: 1px solid var(--line); padding: 10px 0; overflow: auto; }
#sidebar .nav-group { padding: 14px 18px 6px; font-size: 11px; font-weight: 700; color: var(--blue-dark); text-transform: uppercase; letter-spacing: .6px; }
#sidebar button { display: flex; width: 100%; align-items: center; justify-content: space-between; border: 0; background: none; padding: 10px 18px; cursor: pointer; text-align: left; }
#sidebar button:hover { background: #dfe9fc; }
#sidebar button.active { background: #d6e4fd; color: var(--blue-dark); font-weight: 600; box-shadow: inset 4px 0 var(--blue); }

#tabs { display: flex; align-items: flex-end; gap: 3px; padding: 0 10px; background: #dce6f6; border-bottom: 1px solid var(--line); overflow-x: auto; }
#tabs .tab { display: flex; align-items: center; gap: 10px; padding: 7px 14px; background: #cddbf3; border: 1px solid #bccde9; border-bottom: 0; border-radius: 6px 6px 0 0; cursor: pointer; white-space: nowrap; max-width: 220px; color: #2a3a57; }
#tabs .tab:hover { background: #dbe6f8; }
#tabs .tab.active { background: var(--panel); font-weight: 600; color: var(--blue-dark); box-shadow: inset 0 3px var(--blue); }
#tabs .tab .close { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; font-size: 14px; line-height: 1; }
#tabs .tab .close:hover { color: var(--danger); }

#workspace { position: relative; overflow: hidden; background: var(--panel); }
.view { position: absolute; inset: 0; overflow: auto; padding: 18px 20px; }

#statusbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 18px; padding: 0 16px; background: #dce6f6; border-top: 1px solid #c6d5ee; font-size: 12px; color: #3d4d6a; }
#statusbar .spacer { flex: 1; }

/* ── Controls ─────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input { height: 38px; padding: 7px 12px; border: 1px solid #cfd5dd; border-radius: var(--radius); background: #fff; outline: none; min-width: 0; transition: border-color .12s, box-shadow .12s; }
.input:hover { border-color: #b7bfca; }
textarea.input { height: auto; min-height: 76px; resize: vertical; }
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30, 99, 233, .16); }
.input[readonly] { background: #f6f7f9; }
.btn { height: 38px; padding: 0 18px; font-weight: 500; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f5f8; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented button { border: 0; background: #fff; height: 36px; padding: 0 18px; cursor: pointer; }
.segmented button.on { background: var(--blue); color: #fff; }

/* ── Grids ────────────────────────────────────────────────── */
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
table.grid th { position: sticky; top: 0; z-index: 1; background: var(--head); color: #1d3a75; border: 1px solid var(--line); padding: 10px 12px; font-weight: 600; text-align: left; font-size: 12px; white-space: nowrap; }
table.grid td { border: 1px solid var(--line-soft); padding: 9px 12px; vertical-align: middle; }
table.grid tbody tr:nth-child(even) td { background: var(--row-alt); }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.clickable:hover td { background: var(--blue-soft); }
table.grid tbody tr.selected td { background: #dbe7fd !important; }
table.grid tbody tr.cancelled td { color: var(--muted); text-decoration: line-through; }
table.grid tfoot td { background: var(--head); color: #1d3a75; font-weight: 600; border: 1px solid var(--line); padding: 10px 12px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 9px; font-size: 11px; font-weight: 600; }
.badge.paid { background: #e3f6ea; color: #1b7f45; }
.badge.partial { background: #fff1d6; color: #9a5b00; }
.badge.unpaid { background: #fde4e4; color: #b42318; }
.badge.cancelled { background: #eceff3; color: var(--muted); }
.badge.confirmed { background: var(--blue-soft); color: var(--blue-dark); }
.badge.sync { background: #fff1d6; color: #9a5b00; }

/* ── Bill editor ──────────────────────────────────────────── */
.bill { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; height: 100%; min-height: 0; }
.bill-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: 14px; }
.bill-head { display: grid; grid-template-columns: 130px 148px minmax(150px, 1fr) 140px auto; gap: 12px; align-items: end; }
.bill-head .segmented button { padding: 0 14px; }
.bill-lines { flex: 1; min-height: 160px; overflow: auto; border: 1px solid var(--line); }
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { position: sticky; top: 0; z-index: 1; background: var(--head); color: #1d3a75; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line-soft); padding: 10px 10px; font-size: 12px; text-align: left; }
table.lines td { border-bottom: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); padding: 0; height: 40px; }
table.lines td.idx { width: 42px; text-align: center; color: var(--muted); }
table.lines td.amount { padding: 0 12px; text-align: right; font-weight: 600; width: 110px; font-variant-numeric: tabular-nums; }
table.lines td.del { width: 38px; text-align: center; }
table.lines input { width: 100%; height: 39px; border: 0; padding: 0 10px; background: transparent; outline: none; }
table.lines input.num { text-align: right; }
table.lines input:focus { background: var(--focus); box-shadow: inset 0 0 0 2px var(--blue); }
table.lines tr.active-row td { background: #fbfcff; }
table.lines .del button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 8px; }
table.lines .del button:hover { color: var(--danger); }
.line-hint { font-size: 11.5px; color: var(--success); padding: 0 10px 5px; }
.bill-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; padding-right: 2px; }
.bill-footer { position: sticky; bottom: 0; margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 10px; background: var(--panel); box-shadow: 0 -8px 12px -10px rgba(16, 24, 40, .25); }
.panel .body.compact { gap: 6px; padding: 10px 14px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.panel h4 { margin: 0; padding: 11px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--blue-dark); border-bottom: 1px solid var(--line-soft); background: var(--blue-tint); }
.panel .body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.sum-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sum-row input { width: 110px; text-align: right; }
.grand { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px; background: linear-gradient(90deg, #e8f0fe, #f3f7ff); border-top: 1px solid #c9d9f6; }
.grand .value { font-size: 26px; font-weight: 700; color: var(--accent-dark); font-variant-numeric: tabular-nums; }
.split-row { display: grid; grid-template-columns: 1fr 110px 38px; gap: 8px; }
.bill-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bill-actions .btn { height: 44px; font-size: 14.5px; }

/* ── Search popup (items / parties) ───────────────────────── */
.popup { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 28px rgba(0,0,0,.16); max-height: 320px; overflow: auto; min-width: 360px; }
.popup .opt { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; padding: 9px 14px; cursor: pointer; border-bottom: 1px solid var(--line-soft); }
.popup .opt:last-child { border-bottom: 0; }
.popup .opt.on, .popup .opt:hover { background: var(--blue-soft); }
.popup .opt .sub { color: var(--muted); font-size: 12px; }
.popup .empty { padding: 14px; color: var(--muted); }

/* ── Cards / dashboard ────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { border: 1px solid var(--line); border-top: 3px solid var(--blue); border-radius: 6px; padding: 14px 18px 16px; background: #fff; box-shadow: 0 1px 3px rgba(15, 47, 107, .06); }
.card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 600; letter-spacing: .4px; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card .note { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 10px 0 12px; }

/* ── Dialogs / toasts / screens ───────────────────────────── */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(15, 20, 30, .38); display: grid; place-items: center; }
.dialog { background: #fff; border-radius: 6px; width: min(560px, 94vw); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(0,0,0,.3); }
.dialog.wide { width: min(860px, 96vw); }
.dialog header { padding: 14px 20px; font-weight: 600; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; }
.dialog .content { padding: 18px 20px; overflow: auto; }
.dialog footer { padding: 14px 20px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 10px; }
#toasts { position: fixed; right: 14px; bottom: 34px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy); color: #fff; padding: 12px 18px; border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0,0,0,.25); max-width: 420px; }
.toast.error { background: #8e1f1f; }
.toast.ok { background: #1f5f3a; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, #0f2f6b, #1e63e9); }
.screen .box { width: min(440px, 92vw); background: #fff; border-radius: 6px; padding: 34px 32px; box-shadow: 0 18px 50px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 16px; }
.screen h1 { margin: 0; font-size: 20px; }
.screen .brand { display: flex; align-items: center; gap: 10px; }
.screen .brand .logo { width: 38px; height: 38px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.screen .list button { display: flex; justify-content: space-between; width: 100%; padding: 14px 16px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer; text-align: left; }
.screen .list button:hover { background: var(--blue-soft); border-color: var(--blue); }
.screen .error { color: var(--danger); min-height: 18px; font-size: 12px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

#print-frame { position: fixed; width: 0; height: 0; border: 0; visibility: hidden; }

/* ── Reports ──────────────────────────────────────────────── */
.view.view-flush { padding: 0; overflow: hidden; }
.reports { display: grid; grid-template-columns: 230px minmax(0, 1fr); height: 100%; }
.report-list { border-right: 1px solid var(--line); background: var(--blue-tint); overflow: auto; padding: 6px 0 14px; }
.report-list .nav-group { padding: 14px 16px 6px; font-size: 11px; font-weight: 700; color: var(--blue-dark); text-transform: uppercase; letter-spacing: .6px; }
.report-list button { display: block; width: 100%; border: 0; background: none; padding: 9px 16px; text-align: left; cursor: pointer; color: var(--ink); }
.report-list button:hover { background: #e2ebfc; }
.report-list button.active { background: #d6e4fd; color: var(--blue-dark); font-weight: 600; box-shadow: inset 4px 0 var(--blue); }
.report-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 16px 20px; gap: 12px; overflow: hidden; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.report-head h2 { margin: 0 0 3px; font-size: 19px; color: var(--navy); }
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.report-params { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 12px 14px; background: var(--blue-tint); border: 1px solid var(--line); border-radius: 6px; }
.report-params:empty { display: none; }
.param-group { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 4px; }
.report-output { flex: 1; min-height: 0; overflow: auto; }
.report-subtitle { color: var(--muted); margin-bottom: 10px; font-size: 12.5px; }
.report-cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-bottom: 14px; }
.report-cards .value { font-size: 19px; color: var(--navy); }
.report-table table.grid tbody tr.row-bold td, .report-table table.grid tbody tr.row-group td { font-weight: 600; background: var(--blue-soft); }
.report-table table.grid tbody tr.row-muted td { color: var(--muted); }
.report-table table.grid tbody tr.row-danger td { color: var(--danger); }
.report-table table.grid td { white-space: nowrap; }
.user-id { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.user-id code { user-select: all; background: var(--blue-soft); padding: 3px 7px; border-radius: 4px; font-size: 12.5px; color: var(--navy); }
.screen .box.wide { width: min(620px, 94vw); max-height: 92vh; overflow: auto; }
.import-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.import-log { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.import-log .ok { color: #17804a; }
