:root {
  --bg: #eef1f5;
  --bg2: #e3e8ef;
  --card: #ffffff;
  --ink: #0d2230;
  --muted: #5b7181;
  --line: #d8e0e8;
  --navy: #0b2b3c;
  --navy2: #103d52;
  --blue: #0b6cb4;
  --blue-soft: #e7f1fa;
  --gold: #f2b705;
  --green: #0f8a5f;
  --red: #b3402f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(13, 34, 48, .06), 0 8px 24px -12px rgba(13, 34, 48, .18);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 84px;
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--blue); }
button, input, select { font: inherit; color: inherit; }

/* header */
.top {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 70%, #17506a 100%);
  color: #fff;
  padding: 18px 20px 16px;
  box-shadow: var(--shadow);
}
.top-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.mark {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
  background: var(--gold); color: #16232c; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: -.04em;
}
.brand h1 { font-size: 17px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: #b9cdd9; }
.badges { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
  color: #dfeaf1; white-space: nowrap;
}
.badge b { color: #fff; font-weight: 600; }
.badge.on { background: rgba(15, 138, 95, .22); border-color: rgba(15, 138, 95, .5); color: #b8f0d8; }

main { max-width: 1180px; margin: 18px auto 0; padding: 0 16px; display: grid; grid-template-columns: 392px minmax(0, 1fr); gap: 16px; align-items: start; }
main > section { min-width: 0; }
@media (max-width: 960px) { main { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 14px 16px; margin-bottom: 14px;
}
.card > header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card > header h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.card > header .hint { margin-left: auto; font-size: 11px; color: var(--muted); }

.field { margin-bottom: 11px; }
.field:last-child { margin-bottom: 0; }
label.lbl { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.help { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.35; }

input[type=number], input[type=text], input[type=month], select {
  width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; font-variant-numeric: tabular-nums; appearance: none;
}
input[type=number]:focus, input[type=text]:focus, input[type=month]:focus, select:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(11, 108, 180, .14);
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.money { position: relative; }
.money input { padding-left: 26px; }
.money::before { content: "₱"; position: absolute; left: 10px; top: 8px; color: var(--muted); font-size: 13px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

.seg { display: flex; gap: 4px; background: #eef2f6; padding: 3px; border-radius: 10px; min-width: 0; }
.seg button {
  flex: 1 1 0; min-width: 0; border: 0; background: transparent; padding: 7px 2px; border-radius: 8px;
  font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 420px) { .seg button { font-size: 11px; letter-spacing: -.02em; } }
.seg button[aria-pressed=true] { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(13, 34, 48, .14); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip {
  border: 1px dashed var(--line); background: #fbfcfd; color: var(--muted); border-radius: 999px;
  padding: 3px 9px; font-size: 11.5px; cursor: pointer;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: #cfd8e0; position: relative; transition: background .15s; flex: 0 0 auto; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch span.t { font-size: 12.5px; font-weight: 600; }

/* event rows */
.events { display: flex; flex-direction: column; gap: 8px; }
.event {
  border: 1px solid var(--line); border-radius: 11px; padding: 9px 9px 8px; background: #fbfcfd;
  position: relative;
}
.event.paused { opacity: .55; }
.event-head { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.event-head .idx { font-size: 10.5px; font-weight: 700; color: #fff; background: var(--navy2); border-radius: 6px; padding: 2px 6px; }
.event-head .save { font-size: 11px; color: var(--green); font-weight: 600; margin-left: auto; }
.event-head button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 2px; line-height: 1; }
.event-head button:hover { color: var(--red); }
.event .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.event .grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
.event label { font-size: 10.5px; color: var(--muted); display: block; margin-bottom: 2px; }
.event input, .event select { padding: 6px 8px; border-radius: 7px; font-size: 12.5px; }
.empty { font-size: 12px; color: var(--muted); text-align: center; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 12px;
  font-size: 12.5px; font-weight: 650; cursor: pointer; color: var(--navy);
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }

/* results */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; box-shadow: var(--shadow); }
.kpi .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.kpi.dark { background: linear-gradient(150deg, var(--navy), var(--navy2)); border-color: var(--navy); color: #fff; }
.kpi.dark .k, .kpi.dark .s { color: #a9c1cf; }
.kpi.good .v { color: var(--green); }
.kpi.bad .v { color: var(--red); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12.5px; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid #c3cfd9; }
tbody tr:hover { background: #f7fafc; }
tbody tr.total td { font-weight: 700; border-top: 1.5px solid #b9c7d2; background: #f7fafc; }
.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap thead th { position: sticky; top: 0; background: #fff; z-index: 1; }
.ledger-wrap { max-height: 480px; }
.ledger-wrap table { font-size: 11.5px; }
.ledger-wrap th, .ledger-wrap td { padding: 5px 6px; }

.bar { height: 10px; border-radius: 999px; background: #e8edf2; display: flex; overflow: hidden; }
.bar span { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 4px; }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 9.5px; fill: var(--muted); }
.chart .grid-line { stroke: var(--line); stroke-width: .7; }

details.fold { border: 1px solid var(--line); border-radius: 10px; padding: 0; margin-top: 10px; }
details.fold > summary { cursor: pointer; padding: 9px 11px; font-size: 12.5px; font-weight: 650; color: var(--navy); list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "▾"; float: right; color: var(--muted); }
details.fold[open] > summary { border-bottom: 1px solid var(--line); }
details.fold > div { padding: 10px 11px; }

.note { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.note b { color: var(--ink); }
.warn { background: #fff7e3; border: 1px solid #f0d79a; color: #6b4b00; border-radius: 10px; padding: 9px 11px; font-size: 12px; }
.danger { background: #fdeeeb; border: 1px solid #f2c2b9; color: #7d2a1c; border-radius: 10px; padding: 9px 11px; font-size: 12px; }

/* sticky summary */
.sticky {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(11, 43, 60, .97); backdrop-filter: blur(8px); color: #fff;
  border-top: 1px solid rgba(255,255,255,.12);
  padding: 8px 14px; display: none;
}
@media (max-width: 960px) { .sticky { display: block; } }
.sticky-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.sticky .item .k { font-size: 10px; color: #a9c1cf; text-transform: uppercase; letter-spacing: .06em; }
.sticky .item .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sticky .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }

footer { max-width: 1180px; margin: 6px auto 26px; padding: 0 16px; font-size: 11px; color: var(--muted); }
footer a { color: var(--muted); }

@media print {
  body { background: #fff; padding: 0; }
  .top, .inputs, .sticky, .no-print, .btn { display: none !important; }
  main { display: block; max-width: none; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; border-color: #bbb; }
  .table-wrap { max-height: none; overflow: visible; }
}
