:root {
  color-scheme: light;
  --navy: #12344a;
  --navy-deep: #0b2638;
  --blue: #226a94;
  --sky: #dbeef7;
  --lime: #c8ef72;
  --coral: #ff724d;
  --paper: #ffffff;
  --canvas: #eef3f5;
  --ink: #14252f;
  --muted: #63747d;
  --line: #d4dfe3;
  --soft: #f6f9fa;
  --danger: #b42335;
  --shadow: 0 18px 50px rgba(12, 46, 65, .11);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--canvas); }
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.noise { position: fixed; inset: 0; pointer-events: none; opacity: .19; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E"); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0 0 7px; color: var(--blue); font-size: .75rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 18% 12%, rgba(200,239,114,.3), transparent 30%), linear-gradient(145deg, #edf4f6, #dbe7eb); }
.login-card { width: min(430px, 100%); padding: 42px; border: 1px solid rgba(18,52,74,.16); border-radius: 22px; background: rgba(255,255,255,.94); box-shadow: 0 28px 80px rgba(8,40,58,.17); }
.login-modal { width: min(460px, calc(100% - 28px)); }
.login-modal .login-card { width: 100%; padding: 34px; border: 0; border-radius: 17px; box-shadow: none; }
.login-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.login-head .brand-mark { margin-bottom: 24px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 28px; border-radius: 16px; color: var(--lime); background: var(--navy); box-shadow: 0 10px 26px rgba(18,52,74,.2); }
.brand-mark svg { width: 30px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.brand-mark circle { fill: var(--coral); stroke: white; }
.login-card h1 { margin: 0; color: var(--navy-deep); font-size: clamp(2.3rem, 9vw, 3.4rem); line-height: 1; letter-spacing: -.055em; }
.login-copy { margin: 16px 0 28px; color: var(--muted); font-size: 1rem; line-height: 1.55; }
.stack-form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #40545f; font-size: .84rem; font-weight: 750; }
input { width: 100%; min-height: 47px; padding: 10px 12px; color: var(--ink); background: white; border: 1px solid #bdccd2; border-radius: 9px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(34,106,148,.13); }
.form-message { min-height: 20px; margin: 0; font-size: .82rem; font-weight: 700; }
.error { color: var(--danger); }

.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 9px; font-weight: 800; transition: transform .15s, box-shadow .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .65; transform: none; }
.button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.button-wide { width: 100%; min-height: 48px; }
.button-primary { color: white; background: var(--navy); box-shadow: 0 8px 20px rgba(18,52,74,.16); }
.button-primary:hover { background: var(--navy-deep); }
.button-accent { color: var(--navy-deep); background: var(--lime); border-color: rgba(18,52,74,.12); box-shadow: 0 8px 20px rgba(93,131,31,.14); }
.button-secondary { color: var(--navy); background: white; border-color: var(--line); }
.button-quiet { min-height: 38px; color: rgba(255,255,255,.8); background: transparent; border-color: rgba(255,255,255,.18); font-size: .83rem; }
.button-quiet:hover { color: white; background: rgba(255,255,255,.08); }

.topbar { position: sticky; top: 0; z-index: 10; color: white; background: var(--navy-deep); box-shadow: 0 1px 0 rgba(255,255,255,.08); }
.topbar-inner { width: min(1180px, calc(100% - 40px)); min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: auto; }
.identity { display: flex; align-items: center; gap: 11px; }
.identity-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: var(--navy-deep); background: var(--lime); font-weight: 950; }
.identity strong { display: block; font-size: .94rem; letter-spacing: .025em; }
.identity span { display: block; margin-top: 2px; color: rgba(255,255,255,.58); font-size: .73rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.mode-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; color: rgba(255,255,255,.68); background: rgba(255,255,255,.06); font-size: .7rem; font-weight: 800; }
.mode-pill.editing { color: var(--lime); border-color: rgba(200,239,114,.28); background: rgba(200,239,114,.09); }
.workspace { position: relative; width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 44px 0 70px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 27px; }
.page-heading h1 { margin: 0; color: var(--navy-deep); font-size: clamp(1.9rem, 4vw, 2.9rem); line-height: 1.03; letter-spacing: -.045em; }

.summary-layout { display: grid; grid-template-columns: 1.12fr 1fr; gap: 18px; margin-bottom: 22px; }
.balance-card, .metric-card, .ledger-card { border: 1px solid var(--line); background: var(--paper); box-shadow: 0 8px 26px rgba(12,46,65,.055); }
.balance-card { min-height: 262px; display: flex; flex-direction: column; justify-content: space-between; padding: 26px; border-radius: 16px; color: white; background: linear-gradient(135deg, var(--navy-deep), var(--navy) 62%, #19506d); overflow: hidden; position: relative; }
.balance-card::after { content: ""; position: absolute; width: 210px; height: 210px; right: -78px; bottom: -100px; border: 34px solid rgba(200,239,114,.13); border-radius: 50%; }
.balance-top, .balance-foot { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: rgba(255,255,255,.7); font-size: .82rem; }
.balance-top span:last-child { padding: 6px 9px; border-radius: 999px; color: var(--lime); background: rgba(200,239,114,.1); font-weight: 800; }
.balance-card > strong { position: relative; z-index: 1; margin: 22px 0 24px; font-size: clamp(2.9rem, 6vw, 4.5rem); line-height: .95; letter-spacing: -.06em; }
.progress-track { position: relative; z-index: 1; height: 9px; margin-bottom: 16px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.13); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--lime), #e5ffad); transition: width .5s ease; }
.balance-foot b { margin-left: 5px; color: white; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.metric-card { min-width: 0; padding: 20px; border-radius: 13px; }
.metric-card span { display: block; color: var(--muted); font-size: .78rem; font-weight: 800; }
.metric-card strong { display: block; margin-top: 10px; color: var(--navy-deep); font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.04em; }
.metric-card small { display: block; margin-top: 6px; color: #819097; font-size: .7rem; line-height: 1.4; }

.ledger-card { border-radius: 16px; overflow: hidden; }
.section-head { min-height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 19px 23px; border-bottom: 1px solid var(--line); }
.section-head h2 { margin: 0; color: var(--navy-deep); font-size: 1.1rem; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: .78rem; }
.count-pill { padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--soft); font-size: .72rem; font-weight: 800; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th { padding: 12px 16px; color: #6e7f87; background: var(--soft); border-bottom: 1px solid var(--line); font-size: .7rem; font-weight: 850; letter-spacing: .045em; text-align: left; text-transform: uppercase; }
td { padding: 15px 16px; border-bottom: 1px solid #e7edef; color: #344b57; font-size: .84rem; vertical-align: middle; }
tbody tr:nth-child(even) { background: #f9fbfb; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f0f7f9; }
tfoot th, tfoot td { padding: 15px 16px; color: var(--navy-deep); background: #edf4f6; border-top: 2px solid #bfd0d7; font-size: .82rem; font-weight: 900; }
tfoot th { text-align: left; text-transform: none; letter-spacing: 0; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.entry-title { display: block; color: var(--navy-deep); font-weight: 800; }
.entry-meta { display: block; margin-top: 4px; color: #839198; font-size: .7rem; }
.detail-main { display: block; color: #405763; font-weight: 750; }
.line-kind { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 999px; font-size: .68rem; font-weight: 850; }
.line-kind.charge { color: #824215; background: #fff0d8; }
.line-kind.adjustment { color: #425862; background: #eaf0f2; }
.amount-positive { color: #167049; font-weight: 850; }
.amount-negative { color: var(--danger); font-weight: 850; }
.amount-owed { color: #8a4a1e; font-weight: 850; }
.amount-paid { color: #167049; font-weight: 850; }
.balance-number { color: var(--navy-deep); font-weight: 850; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.mini-button { min-width: 34px; min-height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; color: #50636d; background: white; font-size: .72rem; font-weight: 800; }
.mini-button:hover { border-color: #9fb3bd; color: var(--navy); }
.mini-button.danger:hover { color: var(--danger); border-color: #e7a9b0; }
.empty-state { min-height: 220px; display: grid; place-content: center; gap: 7px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--navy); font-size: 1rem; }
.inline-error { margin: 16px 22px 0; padding: 11px 13px; color: var(--danger); background: #fff0f1; border: 1px solid #f0c6ca; border-radius: 8px; font-size: .8rem; font-weight: 700; }

.modal { width: min(590px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 17px; color: var(--ink); background: white; box-shadow: 0 28px 90px rgba(7,35,52,.28); }
.modal::backdrop { background: rgba(7,28,41,.58); backdrop-filter: blur(4px); }
.modal form { padding: 26px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 23px; }
.modal-head h2 { margin: 0; color: var(--navy-deep); font-size: 1.55rem; letter-spacing: -.035em; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: white; font-size: 1.5rem; line-height: 1; }
.segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 21px; padding: 4px; border-radius: 10px; background: #eaf0f2; }
.segment-button { min-height: 39px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-weight: 800; }
.segment-button.active { color: white; background: var(--navy); box-shadow: 0 4px 12px rgba(18,52,74,.15); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.span-2 { grid-column: span 2; }
.optional { color: #8c9aa0; font-weight: 500; }
label small { color: var(--muted); font-size: .7rem; font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; padding-top: 19px; border-top: 1px solid var(--line); }
.toast { position: fixed; z-index: 40; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 11px 15px; border-radius: 9px; color: white; background: var(--navy-deep); box-shadow: var(--shadow); font-size: .82rem; font-weight: 800; }

@media (max-width: 800px) {
  .summary-layout { grid-template-columns: 1fr; }
  .balance-card { min-height: 245px; }
}
@media (max-width: 600px) {
  .topbar-inner, .workspace { width: min(100% - 24px, 1180px); }
  .topbar-inner { min-height: 62px; }
  .button-quiet span { display: none; }
  .mode-pill { display: none; }
  .workspace { padding-top: 29px; }
  .page-heading { align-items: flex-start; }
  .page-heading .button { padding: 0 12px; }
  .metric-card { padding: 16px; }
  .balance-card { padding: 21px; }
  .login-card { padding: 30px 24px; }
  .form-grid { grid-template-columns: 1fr; gap: 13px; }
  .span-2 { grid-column: span 1; }
  .modal form { padding: 21px; }
  .modal-actions .button { flex: 1; }
}
