:root {
  --ink: #17241c;
  --muted: #6e7b72;
  --green-950: #123c28;
  --green-800: #205b3c;
  --green-650: #2f704b;
  --green-100: #e7f0e9;
  --cream: #f6f4ed;
  --paper: #fffefa;
  --line: #dfe5df;
  --red: #a74135;
  --red-bg: #f9e9e6;
  --amber: #8a641b;
  --amber-bg: #fff3d8;
  --shadow: 0 12px 32px rgba(25, 59, 38, .07);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--cream); }
body { margin: 0; min-height: 100vh; }
a { color: var(--green-650); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
small { display: block; color: var(--muted); }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 255px; padding: 28px 18px 18px; display: flex; flex-direction: column; background: var(--green-950); color: #fff; z-index: 30; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 30px; }
.brand strong { display: block; font-family: Georgia, serif; font-size: 17px; }
.brand small { color: #a8c0b0; font-size: 10px; margin-top: 2px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px 11px 18px 11px; background: #d9e9d2; color: var(--green-950); font: 700 22px Georgia, serif; }
.brand-mark.large { width: 54px; height: 54px; margin: 0 auto 22px; border-radius: 16px 16px 25px 16px; font-size: 30px; }
.sidebar nav { display: grid; gap: 3px; }
.sidebar nav a { display: flex; gap: 12px; align-items: center; min-height: 43px; padding: 0 13px; color: #dbe7de; border-radius: 10px; font-size: 14px; }
.sidebar nav a span { width: 19px; text-align: center; color: #a8c0b0; font-size: 18px; }
.sidebar nav a:hover, .sidebar nav a.active { color: #fff; background: rgba(255,255,255,.1); }
.sidebar nav a.active span { color: #d6ebb5; }
.nav-secondary { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.1); }
.user-block { display: grid; grid-template-columns: 34px 1fr auto; gap: 9px; align-items: center; margin-top: 20px; padding: 13px 6px 0; border-top: 1px solid rgba(255,255,255,.1); }
.user-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: #d9e9d2; color: var(--green-950); font-weight: 700; }
.user-block strong { display: block; font-size: 12px; }
.user-block small { color: #9bb3a3; font-size: 10px; }
.user-block form { margin: 0; }
.icon-button { border: 0; background: transparent; color: #a8c0b0; font-size: 17px; }
.mobile-header, .menu-backdrop { display: none; }

.main { margin-left: 255px; padding: 38px 42px 70px; max-width: 1680px; min-height: 100vh; }
.page-header { display: flex; justify-content: space-between; gap: 30px; align-items: flex-end; margin: 0 0 27px; }
.page-header h1 { margin: 5px 0 4px; font: 600 34px/1.15 Georgia, "Times New Roman", serif; letter-spacing: -.6px; }
.page-header p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--green-650); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 9px; color: var(--muted); font-size: 13px; }
.title-line, .header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.header-actions form { margin: 0; }

.button { display: inline-flex; justify-content: center; align-items: center; min-height: 40px; padding: 0 17px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; font-size: 13px; transition: .15s ease; }
.button.primary { background: var(--green-650); color: #fff; box-shadow: 0 5px 14px rgba(47,112,75,.18); }
.button.primary:hover { background: var(--green-800); transform: translateY(-1px); }
.button.ghost { border-color: #cfd9d1; background: rgba(255,255,255,.55); color: var(--green-800); }
.button.small { min-height: 31px; padding: 0 11px; font-size: 11px; }
.button.wide { width: 100%; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 20px; }
.stats-grid.compact { grid-template-columns: repeat(3, minmax(0,1fr)); }
.stat-card { min-height: 132px; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); }
.stat-card.accent { background: var(--green-950); border-color: var(--green-950); color: #fff; }
.stat-card.warning { background: var(--amber-bg); border-color: #eed59f; }
.stat-card > span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-card.accent > span, .stat-card.accent small { color: #bcd0c2; }
.stat-card strong { display: block; margin: 12px 0 5px; font: 600 27px Georgia, serif; white-space: nowrap; }
.stat-card strong.text-value { font-size: 20px; white-space: normal; }
.stat-card small { font-size: 11px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, .8fr); gap: 20px; }
.detail-grid { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(320px,.65fr); gap: 20px; }
.split-grid { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(320px,.7fr); gap: 20px; align-items: start; }
.side-stack { display: grid; gap: 20px; align-content: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.panel-head { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.panel h2 { margin: 0; font: 600 19px Georgia, serif; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.panel-head > a, .compact-actions a { font-size: 12px; font-weight: 700; }
.compact-actions { display: flex; gap: 12px; }
.table-panel { margin-bottom: 20px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 16px; background: #f2f5f1; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; text-align: left; white-space: nowrap; }
td { padding: 14px 16px; border-bottom: 1px solid #ebeeeb; font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcf9; }
td small { margin-top: 3px; max-width: 440px; }
.num { text-align: right; white-space: nowrap; }
.debt { color: var(--red) !important; }
.credit { color: var(--green-650) !important; }
.account-link { color: var(--ink); font-weight: 750; }
.account-link small { font-weight: 400; }
.row-arrow { display: grid; place-items: center; width: 30px; height: 30px; margin-left: auto; border-radius: 50%; background: var(--green-100); }
.empty { padding: 26px !important; color: var(--muted); text-align: center; }

.activity-list { padding: 4px 18px; }
.activity { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; padding: 14px 2px; color: var(--ink); border-bottom: 1px solid #ebeeeb; }
.activity:last-child { border-bottom: 0; }
.activity strong { display: block; font-size: 12px; }
.activity b { font-size: 12px; }
.activity-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--red-bg); color: var(--red); font-weight: 900; }
.activity-icon.income { background: var(--green-100); color: var(--green-650); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: -5px 0 18px; }
.search { display: grid; grid-template-columns: 28px minmax(250px,520px) auto; align-items: center; width: min(690px,100%); border: 1px solid var(--line); background: var(--paper); border-radius: 11px; overflow: hidden; }
.search span { text-align: right; color: var(--muted); }
.search input { min-height: 43px; padding: 0 12px; border: 0; background: transparent; outline: 0; }
.search button { align-self: stretch; padding: 0 17px; border: 0; border-left: 1px solid var(--line); background: var(--green-100); color: var(--green-800); font-weight: 700; }
.result-count { color: var(--muted); font-size: 12px; }

.badge, .status { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; background: var(--green-100); color: var(--green-800); font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-draft, .status-processing { background: #edf0ee; color: #59665e; }
.status-reviewed, .status-review, .status-proposed { background: var(--amber-bg); color: var(--amber); }
.status-posted, .status-completed { background: var(--green-100); color: var(--green-800); }
.status-reversed, .status-cancelled, .status-failed, .status-error, .status-unmatched { background: var(--red-bg); color: var(--red); }
.status-duplicate { background: #eeeaf5; color: #65537b; }

.account-hero { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 1px; margin-bottom: 20px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--line); box-shadow: var(--shadow); }
.account-hero > div { min-height: 125px; padding: 22px; background: var(--paper); }
.account-hero span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.account-hero strong { display: block; margin: 10px 0 4px; font: 600 21px Georgia, serif; }
.timeline { padding: 20px; }
.timeline-item { position: relative; padding: 0 0 23px 25px; border-left: 1px solid #ced8d0; }
.timeline-item:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline-item i { position: absolute; left: -5px; top: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--green-650); box-shadow: 0 0 0 4px var(--green-100); }
.timeline-item strong, .timeline-item span { display: block; font-size: 12px; }
.timeline-item span { color: var(--muted); margin-top: 4px; }
.timeline-item small { margin-top: 5px; color: var(--green-650); }
.meter-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }

.form-panel { padding: 26px; max-width: 900px; }
.form-panel h2 { margin-bottom: 20px; }
.stack-form { display: grid; gap: 17px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.stack-form label { display: grid; gap: 7px; color: #344138; font-size: 12px; font-weight: 700; }
.stack-form input, .stack-form select, .stack-form textarea, .inline-form select, .row-menu input { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #ccd6ce; border-radius: 8px; background: #fff; color: var(--ink); outline: 0; }
.stack-form input:focus, .stack-form select:focus, .stack-form textarea:focus { border-color: var(--green-650); box-shadow: 0 0 0 3px var(--green-100); }
.stack-form .checkbox-field { display: flex; align-items: center; }
.stack-form .checkbox-field input { width: 18px; min-height: 18px; order: -1; }
.form-actions { display: flex; gap: 9px; margin-top: 5px; padding-top: 18px; border-top: 1px solid var(--line); }
.errorlist { margin: 0; padding: 0; list-style: none; color: var(--red); font-size: 11px; font-weight: 500; }
.messages { position: fixed; top: 18px; right: 22px; display: grid; gap: 8px; max-width: 410px; z-index: 100; }
.message { padding: 13px 16px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: var(--shadow); font-size: 13px; }
.message.error { background: var(--red); }
.message.success { background: var(--green-800); }

.simple-list { padding: 5px 20px; }
.simple-list > div { min-height: 64px; display: flex; justify-content: space-between; gap: 15px; align-items: center; border-bottom: 1px solid var(--line); }
.simple-list > div:last-child { border-bottom: 0; }
.simple-list strong { display: block; font-size: 13px; }
.simple-list b { color: var(--green-800); font-size: 13px; white-space: nowrap; }
.allocation-panel { max-width: 1000px; }
.money-input { width: 110px; min-height: 34px; padding: 5px 8px; text-align: right; border: 1px solid #ccd6ce; border-radius: 7px; }
.allocation-footer { display: flex; justify-content: flex-end; gap: 30px; align-items: center; padding: 20px; background: #f5f7f3; border-top: 1px solid var(--line); }
.allocation-footer span { display: block; color: var(--muted); font-size: 10px; }
.receipt-summary { display: grid; grid-template-columns: 42px 1fr auto; gap: 15px; align-items: center; padding: 24px; border-bottom: 1px solid var(--line); }
.receipt-summary p { margin: 5px 0 0; color: var(--muted); }
.receipt-summary > strong { color: var(--green-650); font: 600 22px Georgia,serif; }
.inline-form { display: flex; gap: 7px; min-width: 300px; }
.inline-form select { min-height: 31px; padding: 3px 7px; font-size: 11px; }
.error-text { color: var(--red); }
.import-summary { display: flex; gap: 1px; background: var(--line); }
.import-summary > div { flex: 1; padding: 25px; background: var(--paper); }
.import-summary span, .import-summary strong { display: block; }
.import-summary span { color: var(--muted); font-size: 11px; }
.import-summary strong { margin-top: 7px; font: 600 28px Georgia,serif; }
.error-list { margin: 20px; padding: 12px 18px; border-radius: 9px; background: var(--red-bg); color: var(--red); font-size: 12px; }
.view-tabs { display:flex; gap:6px; margin:0 0 18px; padding:5px; overflow:auto; border:1px solid var(--line); border-radius:10px; background:#eef3ef; }
.view-tabs a { padding:9px 15px; border-radius:7px; color:var(--muted); white-space:nowrap; font-size:12px; font-weight:700; }
.view-tabs a.active { background:var(--paper); color:var(--green-800); box-shadow:0 1px 4px rgba(0,0,0,.08); }
.monthly-matrix th,.monthly-matrix td { min-width:92px; }
.monthly-matrix th:first-child,.monthly-matrix td:first-child { position:sticky; left:0; z-index:2; min-width:210px; background:var(--paper); }
.monthly-matrix thead th:first-child { background:#edf3ee; }
.variance-cell,.variance-row { background:#fff2df !important; }
.report-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.report-card { min-height: 150px; display: grid; grid-template-columns: 44px 1fr auto; gap: 18px; align-items: start; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.report-card > span { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--green-100); color: var(--green-800); font-weight: 800; }
.report-card h2 { margin: 1px 0 7px; font: 600 19px Georgia,serif; }
.report-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.report-card b { color: var(--green-650); font-size: 11px; }
code { padding: 3px 6px; border-radius: 5px; background: #edf0ee; font-size: 11px; }
.row-menu { position: relative; }
.row-menu summary { cursor: pointer; list-style: none; }
.row-menu form { position: absolute; right: 0; top: 20px; display: grid; gap: 6px; width: 220px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); z-index: 5; }
.row-menu button { min-height: 30px; border: 0; border-radius: 6px; background: var(--red-bg); color: var(--red); }

.auth-body { background: var(--green-950); }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 45px; background: radial-gradient(circle at 15% 25%, rgba(117,160,125,.3), transparent 26%), var(--green-950); }
.login-shell { width: min(980px,100%); display: grid; grid-template-columns: 1.15fr .75fr; gap: 80px; align-items: center; }
.login-intro { color: #fff; }
.login-intro .eyebrow { color: #b9d391; }
.login-intro h1 { margin: 17px 0 20px; font: 500 54px/1.04 Georgia,serif; letter-spacing: -1.2px; }
.login-intro > p { max-width: 560px; color: #c1d1c6; font-size: 17px; line-height: 1.55; }
.login-note { display: inline-flex; gap: 10px; align-items: center; margin-top: 28px; padding: 11px 14px; border: 1px solid rgba(255,255,255,.15); border-radius: 9px; color: #dce8df; font-size: 12px; }
.login-note span { color: #cce4a6; }
.login-card { padding: 38px; border: 1px solid rgba(255,255,255,.4); border-radius: 18px; background: var(--paper); box-shadow: 0 25px 70px rgba(0,0,0,.24); }
.login-card h2 { margin: 0; text-align: center; font: 600 25px Georgia,serif; }
.login-card > p { margin: 7px 0 25px; color: var(--muted); text-align: center; font-size: 12px; }
.login-card > small { margin-top: 20px; text-align: center; font-size: 10px; }

@media (max-width: 1120px) {
  .main { padding: 32px 28px 60px; }
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .mobile-header { position: sticky; top: 0; z-index: 25; display: flex; height: 58px; padding: 0 18px; justify-content: space-between; align-items: center; background: var(--green-950); color: #fff; }
  .mobile-brand { color: #fff; font: 600 17px Georgia,serif; }
  .menu-button { border: 0; background: transparent; color: #fff; font-size: 23px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .menu-open .sidebar { transform: translateX(0); }
  .menu-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.35); }
  .menu-open .menu-backdrop { display: block; }
  .main { margin-left: 0; padding: 24px 16px 50px; }
  .page-header { align-items: flex-start; flex-direction: column; gap: 17px; }
  .page-header h1 { font-size: 29px; }
  .header-actions { width: 100%; }
  .header-actions .button, .header-actions form { flex: 1; }
  .header-actions form .button { width: 100%; }
  .stats-grid, .stats-grid.compact, .account-hero, .split-grid, .form-grid { grid-template-columns: 1fr; }
  .report-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 112px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .search { grid-template-columns: 28px 1fr; }
  .search button { display: none; }
  .compact-actions { flex-direction: column; }
  .messages { left: 15px; right: 15px; max-width: none; }
  .login-shell { grid-template-columns: 1fr; gap: 30px; }
  .login-intro { display: none; }
  .auth-main { padding: 22px; }
  .login-card { padding: 30px 24px; }
  .allocation-footer { align-items: stretch; flex-direction: column; }
  .monthly-matrix th:not(:first-child),.monthly-matrix td:not(:first-child) { min-width:105px; }
}
