:root {
  --navy: #123b64;
  --navy-2: #0b2947;
  --blue: #1d6ca1;
  --gold: #e3a72f;
  --gold-soft: #fff4d7;
  --ink: #172333;
  --muted: #617084;
  --line: #dfe6ee;
  --surface: #ffffff;
  --canvas: #f3f6f9;
  --success: #16805a;
  --danger: #bd3b46;
  --shadow: 0 10px 30px rgba(14, 45, 74, .09);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.eyebrow { margin: 0 0 .3rem; color: var(--blue); font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.2; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 1.1fr) minmax(360px, .9fr); background: #fff; }
.login-brand { position: relative; min-height: 100vh; padding: clamp(3rem, 8vw, 8rem); display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; color: #fff; background: radial-gradient(circle at 78% 15%, rgba(227,167,47,.27), transparent 30%), linear-gradient(145deg, var(--navy-2), var(--navy) 58%, #1b5d85); }
.login-brand::after { content: ""; position: absolute; right: -14vw; bottom: -18vw; width: 42vw; aspect-ratio: 1; border: 1px solid rgba(255,255,255,.18); border-radius: 50%; box-shadow: 0 0 0 5vw rgba(255,255,255,.035), 0 0 0 10vw rgba(255,255,255,.025); }
.login-brand > * { position: relative; z-index: 1; }
.brand-mark { width: 76px; height: 76px; display: grid; place-items: center; border: 2px solid rgba(255,255,255,.7); color: var(--gold); font-weight: 900; letter-spacing: .08em; }
.login-brand .eyebrow { color: #8ed2ff; }
.login-brand h1 { max-width: 680px; margin: 0 0 1.5rem; font-family: Georgia, serif; font-size: clamp(3rem, 6vw, 6rem); font-weight: 500; letter-spacing: -.04em; }
.brand-copy { max-width: 600px; color: #d7e6f3; font-size: 1.1rem; }
.brand-points { display: flex; flex-wrap: wrap; gap: .75rem; }
.brand-points span { padding: .65rem .8rem; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.07); font-size: .85rem; }
.login-panel { min-height: 100vh; padding: 2rem; display: grid; place-items: center; }
.login-card { width: min(420px, 100%); }
.login-card h2 { margin-bottom: .4rem; font-size: 2rem; }
.mobile-brand { display: none; margin-bottom: 2rem; color: var(--navy); font-weight: 800; }
label { display: grid; gap: .45rem; color: #31445a; font-size: .88rem; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 46px; padding: .7rem .8rem; color: var(--ink); background: #fff; border: 1px solid #cbd6e1; border-radius: 8px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(29,108,161,.13); }
.login-card label { margin-top: 1rem; }
.button { min-height: 42px; padding: .65rem 1rem; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 1px solid transparent; border-radius: 8px; font-weight: 800; transition: transform .15s, background .15s; }
.button:active { transform: translateY(1px); }
.button.primary { color: #fff; background: var(--navy); }
.button.primary:hover { background: var(--navy-2); }
.button.secondary { color: var(--navy); background: #fff; border-color: #c9d6e3; }
.button.secondary:hover { background: #f2f6fa; }
.button.danger { color: #fff; background: var(--danger); }
.button.wide { width: 100%; margin-top: 1.4rem; }
.button[disabled] { opacity: .55; cursor: wait; }
.form-message { min-height: 1.2rem; margin: .8rem 0 0; color: var(--danger); font-size: .88rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.2rem 1rem; display: flex; flex-direction: column; color: #eaf2f8; background: var(--navy-2); z-index: 10; }
.sidebar-brand { padding: .5rem .45rem 1.5rem; display: flex; align-items: center; gap: .8rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo { width: 44px; height: 44px; display: grid; place-items: center; color: var(--gold); border: 1px solid rgba(255,255,255,.42); font-size: .75rem; font-weight: 900; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand span { color: #91a9bc; font-size: .76rem; }
.nav-list { padding: 1.4rem 0; display: grid; gap: .35rem; }
.nav-item { width: 100%; padding: .75rem .8rem; display: flex; align-items: center; gap: .8rem; color: #b9cbda; background: transparent; border: 0; border-radius: 8px; text-align: left; font-size: .92rem; font-weight: 700; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-item.active { color: #fff; background: #1c527d; box-shadow: inset 3px 0 0 var(--gold); }
.nav-icon { width: 1.25rem; color: var(--gold); text-align: center; font-size: 1.1rem; }
.sidebar-user { margin-top: auto; padding: 1rem .4rem 0; display: grid; grid-template-columns: 36px minmax(0,1fr) 34px; align-items: center; gap: .65rem; border-top: 1px solid rgba(255,255,255,.1); }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; color: var(--navy-2); background: var(--gold); border-radius: 50%; font-weight: 900; }
.user-meta strong, .user-meta span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta strong { font-size: .82rem; }
.user-meta span { color: #91a9bc; font-size: .72rem; }
.icon-button, .menu-button, .close-button { border: 0; background: transparent; }
.icon-button { color: #d5e1ea; font-size: 1.25rem; }

.workspace { min-width: 0; }
.topbar { min-height: 92px; padding: 1.15rem clamp(1rem, 3vw, 2.2rem); display: flex; align-items: center; gap: 1rem; background: #fff; border-bottom: 1px solid var(--line); }
.role-notice { margin: 1rem clamp(1rem, 3vw, 2.2rem) 0; padding: .9rem 1rem; display: grid; gap: .2rem; color: #694b00; background: #fff7dc; border: 1px solid #edce70; border-left: 5px solid var(--gold); border-radius: 9px; }
.role-notice strong { color: #493400; }
.role-notice code { font-weight: 800; }
.context-title { min-width: 190px; margin-right: auto; }
.context-title h1 { margin: 0; font-size: 1.55rem; }
.context-controls { display: flex; gap: .8rem; }
.select-control { min-width: 180px; color: var(--muted); font-size: .72rem; }
.select-control select { min-height: 39px; padding: .42rem .65rem; color: var(--ink); font-size: .88rem; font-weight: 700; }
.menu-button { display: none; padding: .5rem; font-size: 1.25rem; }
.view { display: none; padding: clamp(1rem, 3vw, 2.2rem); }
.view.active-view { display: block; }
.view-heading { margin-bottom: 1.2rem; display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.view-heading h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(1.7rem, 3vw, 2.35rem); font-weight: 500; }
.panel { padding: 1.15rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-heading { margin-bottom: 1rem; display: flex; justify-content: space-between; gap: 1rem; }
.panel-heading h3 { margin-bottom: .2rem; font-size: 1rem; }
.panel-heading p { margin: 0; color: var(--muted); font-size: .8rem; }

.metric-grid { margin-bottom: 1rem; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .8rem; }
.metric-card { min-height: 132px; padding: 1rem; position: relative; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 5px 18px rgba(14,45,74,.055); }
.metric-card::before { content: ""; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--blue); }
.metric-card.gold::before { background: var(--gold); }
.metric-card.green::before { background: var(--success); }
.metric-card.red::before { background: var(--danger); }
.metric-card span { display: block; color: var(--muted); font-size: .76rem; font-weight: 700; }
.metric-card strong { margin-top: 1.1rem; display: block; color: var(--navy-2); font-family: Georgia, serif; font-size: clamp(1.25rem, 2vw, 1.75rem); font-weight: 600; }
.metric-card small { display: block; margin-top: .3rem; color: #8491a0; font-size: .7rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.55fr) minmax(300px,.8fr); gap: 1rem; }
.bar-chart { min-height: 290px; display: grid; grid-template-columns: repeat(12, minmax(28px,1fr)); align-items: end; gap: .55rem; border-bottom: 1px solid #ccd7e2; }
.chart-month { height: 260px; display: grid; grid-template-rows: 1fr auto; gap: .35rem; align-items: end; }
.bar-pair { height: 220px; display: flex; align-items: end; justify-content: center; gap: 3px; }
.bar { width: min(16px, 42%); min-height: 2px; border-radius: 3px 3px 0 0; background: var(--blue); }
.bar.expense { background: var(--gold); }
.chart-label { color: var(--muted); text-align: center; font-size: .66rem; }
.activity-list { display: grid; }
.activity-item { padding: .8rem 0; display: grid; grid-template-columns: 34px minmax(0,1fr) auto; gap: .7rem; align-items: center; border-bottom: 1px solid #edf1f5; }
.activity-item:last-child { border-bottom: 0; }
.activity-type { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: var(--success); background: #e6f5ef; font-weight: 900; }
.activity-type.expense { color: #a36c00; background: var(--gold-soft); }
.activity-item strong, .activity-item span { display: block; }
.activity-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
.activity-item span { color: var(--muted); font-size: .7rem; }
.activity-amount { font-size: .8rem; font-weight: 800; white-space: nowrap; }

.table-tools { margin-bottom: 1rem; display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.search-field { width: min(440px, 100%); }
.search-field input { min-height: 42px; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th { padding: .8rem .7rem; color: #506176; background: #f3f6f9; border-bottom: 1px solid var(--line); text-align: left; font-size: .72rem; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
td { padding: .85rem .7rem; border-bottom: 1px solid #edf1f5; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; white-space: nowrap; }
.row-action { color: var(--danger); background: transparent; border: 0; font-weight: 800; }
.bill-link { color: var(--blue); font-weight: 800; text-decoration: none; }
.status { display: inline-flex; padding: .28rem .55rem; color: var(--success); background: #e8f6f0; border-radius: 99px; font-size: .72rem; font-weight: 800; }
.status.inactive { color: #7a5260; background: #f5eaed; }
.empty-state { padding: 3rem 1rem; color: var(--muted); text-align: center; }
.balance-intro { margin-bottom: 1rem; display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .84rem; }
.balance-intro strong { color: var(--navy); }
.balance-table tfoot { font-weight: 900; background: #f7f9fb; }

.report-sheet { width: min(900px, 100%); min-height: 1040px; margin: 0 auto; padding: clamp(1.4rem, 4vw, 3.5rem); color: #142334; background: #fff; border: 1px solid #d6e0e9; box-shadow: var(--shadow); }
.report-header { display: flex; align-items: center; gap: 1.2rem; }
.report-emblem { width: 74px; height: 74px; display: grid; place-items: center; flex: 0 0 auto; color: var(--gold); background: var(--navy); font-weight: 900; letter-spacing: .08em; }
.report-header p { margin: 0 0 .15rem; color: var(--muted); font-size: .76rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.report-header h2 { margin: 0; font-family: Georgia, serif; font-size: 1.75rem; font-weight: 500; }
.report-header span { color: var(--muted); }
.report-rule { height: 4px; margin: 1.5rem 0 .9rem; background: linear-gradient(90deg, var(--navy) 76%, var(--gold) 76%); }
.report-basis { color: var(--muted); font-size: .82rem; }
.report-cards { margin: 1.4rem 0; display: grid; grid-template-columns: repeat(2,1fr); border: 1px solid #ced9e4; }
.report-cards > div { padding: 1rem; border-right: 1px solid #ced9e4; border-bottom: 1px solid #ced9e4; }
.report-cards > div:nth-child(2n) { border-right: 0; }
.report-cards > div:nth-last-child(-n+2) { border-bottom: 0; }
.report-cards span, .report-cards strong { display: block; }
.report-cards span { color: var(--muted); font-size: .76rem; }
.report-cards strong { margin-top: .35rem; color: var(--navy); font-size: 1.35rem; }
.report-cards .accent-card { background: var(--gold-soft); }
.report-table { margin: 1.2rem 0; }
.report-table td:first-child { font-weight: 700; }
.report-table td:last-child { text-align: right; font-weight: 800; }
.report-summary { margin-top: 1.5rem; display: grid; grid-template-columns: 1fr 1fr; background: var(--navy); color: #fff; }
.report-summary div { padding: 1.1rem; }
.report-summary div + div { border-left: 1px solid rgba(255,255,255,.25); }
.report-summary span, .report-summary strong { display: block; }
.report-summary span { color: #c9d9e6; font-size: .75rem; }
.report-summary strong { margin-top: .35rem; color: #fff; font-size: 1.3rem; }
.signature-row { margin-top: 5.5rem; display: grid; grid-template-columns: repeat(3,1fr); gap: 2rem; }
.signature-row div { padding-top: .5rem; border-top: 1px solid #526474; text-align: center; font-size: .76rem; }
.report-sheet footer { margin-top: 2.8rem; padding-top: .7rem; display: flex; justify-content: space-between; color: var(--muted); border-top: 1px solid #dce4ec; font-size: .7rem; }

.settings-grid { display: grid; grid-template-columns: minmax(320px,.85fr) minmax(320px,1.15fr); gap: 1rem; }
.form-panel { display: grid; gap: 1rem; }
.form-panel h3, .form-panel p { margin-bottom: 0; }
.info-panel dl { margin: 1rem 0 0; display: grid; }
.info-panel dl div { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.info-panel dl div:last-child { border-bottom: 0; }
.info-panel dt { color: var(--navy); font-weight: 800; }
.info-panel dd { margin: .25rem 0 0; color: var(--muted); font-size: .86rem; }

.modal, .confirm-modal { width: min(680px, calc(100% - 2rem)); padding: 0; border: 0; border-radius: 14px; box-shadow: 0 25px 70px rgba(6,27,47,.28); }
.modal::backdrop, .confirm-modal::backdrop { background: rgba(6,27,47,.64); backdrop-filter: blur(3px); }
.modal form, .confirm-modal form { padding: 1.4rem; }
.modal-heading { margin-bottom: 1.2rem; display: flex; justify-content: space-between; gap: 1rem; }
.modal-heading h2 { margin: 0; }
.close-button { align-self: start; color: var(--muted); font-size: 1.8rem; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.span-2 { grid-column: 1 / -1; }
label small { color: var(--muted); font-size: .72rem; font-weight: 500; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 4.5rem; }
.password-toggle { position: absolute; top: 50%; right: .45rem; min-width: 3.4rem; padding: .35rem .55rem; color: var(--blue); background: #eef5fb; border: 0; border-radius: 6px; transform: translateY(-50%); font-size: .75rem; font-weight: 800; }
.password-toggle:hover { background: #dfeef9; }
.file-field { padding: .8rem; background: #f5f8fb; border: 1px dashed #b9c8d7; border-radius: 8px; }
.file-field input { padding: .4rem; background: transparent; border: 0; }
.modal-actions { margin-top: 1.3rem; display: flex; justify-content: flex-end; gap: .7rem; }
.confirm-modal { width: min(430px, calc(100% - 2rem)); }
.loading-state { position: fixed; inset: 0 0 0 250px; display: flex; align-items: center; justify-content: center; gap: .7rem; color: var(--navy); background: rgba(243,246,249,.82); z-index: 20; backdrop-filter: blur(2px); font-weight: 800; }
.spinner { width: 24px; height: 24px; border: 3px solid #c6d5e2; border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast-region { position: fixed; top: 1rem; right: 1rem; width: min(380px, calc(100% - 2rem)); display: grid; gap: .6rem; z-index: 100; }
.toast { padding: .85rem 1rem; color: #fff; background: var(--navy-2); border-left: 4px solid var(--gold); border-radius: 8px; box-shadow: 0 14px 30px rgba(8,34,58,.22); font-size: .88rem; animation: toast-in .2s ease-out; }
.toast.error { border-left-color: #ff7881; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .mobile-brand { display: block; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -270px; width: 250px; transition: left .2s; box-shadow: 12px 0 30px rgba(5,25,42,.2); }
  .sidebar.open { left: 0; }
  .menu-button { display: block; }
  .loading-state { left: 0; }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .context-title { margin-right: 0; flex: 1; }
  .context-controls { width: 100%; }
  .select-control { min-width: 0; flex: 1; }
}
@media (max-width: 640px) {
  .login-panel { padding: 1.25rem; }
  .view { padding: 1rem; }
  .metric-grid, .settings-grid, .report-cards, .report-summary { grid-template-columns: 1fr; }
  .metric-card { min-height: 112px; }
  .view-heading, .table-tools { align-items: stretch; flex-direction: column; }
  .context-controls { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .bar-chart { gap: .2rem; }
  .chart-label { writing-mode: vertical-rl; transform: rotate(180deg); }
  .report-sheet { min-height: 0; padding: 1.1rem; }
  .report-header { align-items: flex-start; }
  .report-emblem { width: 54px; height: 54px; }
  .report-header h2 { font-size: 1.25rem; }
  .report-cards > div { border-right: 0; border-bottom: 1px solid #ced9e4 !important; }
  .report-cards > div:last-child { border-bottom: 0 !important; }
  .report-summary div + div { border-left: 0; border-top: 1px solid rgba(255,255,255,.25); }
  .signature-row { gap: .7rem; }
}

@page { size: A4 portrait; margin: 10mm; }
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .toast-region, .loading-state, .view:not(#view-report) { display: none !important; }
  .app-shell, .workspace, #view-report { display: block !important; }
  #view-report { padding: 0; }
  .report-sheet { width: 100%; min-height: 277mm; padding: 8mm; border: 0; box-shadow: none; break-inside: avoid; }
  .report-cards { margin: 4mm 0; }
  .report-cards > div { padding: 3mm; }
  .report-table { margin: 3mm 0; }
  .report-table td { padding: 2.5mm; }
  .signature-row { margin-top: 19mm; }
  .report-sheet footer { margin-top: 10mm; }
}
