:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e3e5ea;
  --text: #1a1d23;
  --text-dim: #6b7280;
  --accent: #1a4d8f;
  --accent-hover: #143b6e;
  --ok: #2d8659;
  --ok-bg: #e8f5ee;
  --error: #b3261e;
  --error-bg: #fbecea;
  --muted: #f3f4f6;
  --warning-bg: #fff5d9;
  --tag-bg: #eef2f7;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 8px; }
p.sub { color: var(--text-dim); margin: 0 0 20px; }

/* Topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand a { color: var(--text); font-weight: 600; font-size: 15px; }
.brand .version { color: var(--text-dim); font-size: 11px; margin-left: 8px; font-variant: tabular-nums; }
.topnav { display: flex; align-items: center; gap: 18px; }
.topnav a { color: var(--text-dim); font-size: 13px; }
.topnav a:hover { color: var(--accent); }
.entity-pill {
  background: var(--tag-bg); border-radius: 12px; padding: 3px 10px;
  font-size: 12px; color: var(--text);
}
.logout-form { display: inline; margin: 0; }
.linkish {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font: inherit; font-size: 13px; padding: 0;
}
.linkish:hover { color: var(--accent); text-decoration: underline; }

.container { max-width: 1200px; margin: 24px auto; padding: 0 24px; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash-error { background: var(--error-bg); color: var(--error); }
.flash-info { background: var(--tag-bg); color: var(--text); }

/* Login */
.login-wrap { max-width: 380px; margin: 80px auto; }
.login-wrap h1 { text-align: center; margin-bottom: 8px; }
.login-wrap .sub { text-align: center; margin-bottom: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 20px;
}
.form-stack label { display: block; margin-bottom: 14px; }
.form-stack label span { display: block; color: var(--text-dim); font-size: 12px; margin-bottom: 4px; }
.form-stack input[type="text"], .form-stack input[type="password"], .form-stack input[type="date"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 4px; font: inherit;
}
button.primary {
  background: var(--accent); color: white; border: none; border-radius: 4px;
  padding: 9px 14px; font: inherit; font-weight: 500; cursor: pointer;
}
button.primary:hover { background: var(--accent-hover); }

/* Dashboard entity cards */
.entity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.entity-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 18px; color: var(--text);
}
.entity-card:hover { border-color: var(--accent); text-decoration: none; }
.entity-card .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.entity-card h2 { margin: 0; font-size: 16px; }
.entity-card dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.entity-card dt { color: var(--text-dim); }
.entity-card dd { margin: 0; font-variant: tabular-nums; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--tag-bg); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px;
}
.badge.type-s_corp { background: #e7eefb; color: #1a4d8f; }
.badge.type-partnership { background: #eaf3ed; color: #2d8659; }

/* Tables */
.report-section { margin-bottom: 28px; }
.ledger {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  font-variant: tabular-nums;
}
.ledger th, .ledger td { padding: 7px 12px; text-align: left; }
.ledger thead th {
  background: var(--muted); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
}
.ledger tbody tr { border-bottom: 1px solid var(--border); }
.ledger tbody tr:last-child { border-bottom: none; }
.ledger td.num, .ledger th.num { text-align: right; }
.ledger td.dim { color: var(--text-dim); font-size: 12px; }
.ledger td.strong { font-weight: 600; }
.ledger tfoot .totals th { border-top: 2px solid var(--text); padding-top: 10px; }
.ledger tfoot .diff th { font-weight: 600; }
.ledger tfoot .diff.ok th { color: var(--ok); }
.ledger tfoot .diff.error th { color: var(--error); }
.muted { color: var(--text-dim); opacity: 0.7; }

.tag {
  display: inline-block; font-size: 10px; padding: 1px 6px;
  margin-left: 6px; border-radius: 10px; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tag-system { background: var(--tag-bg); color: var(--text-dim); }

.filterbar {
  display: flex; gap: 12px; align-items: end; margin-bottom: 16px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
}
.filterbar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }

.ok-banner, .error-banner {
  margin-top: 16px; padding: 10px 14px; border-radius: 6px; font-size: 13px;
}
.ok-banner { background: var(--ok-bg); color: var(--ok); }
.error-banner { background: var(--error-bg); color: var(--error); }

.ledger tfoot .net-row th { font-size: 15px; }
.ledger tfoot .net-row.positive th { color: var(--ok); }
.ledger tfoot .net-row.negative th { color: var(--error); }

.ledger.register tbody tr.opening td,
.ledger.register tbody tr.closing td { background: var(--muted); }
.ledger.register td .dim { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
