:root {
  color-scheme: light;
  --bg: #f4f5f3;
  --surface: #fcfcfb;
  --surface-2: #eef0ec;
  --border: #dcdfd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7d7c77;
  --accent: #1b6fd0;
  --accent-ink: #ffffff;
  --danger: #c23b3a;
  --good: #1a7f4b;
  --series-1: #2a78d6;   /* revenue */
  --series-2: #eb6834;   /* costs */
  --series-3: #1baf7a;   /* other expenses */
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121311; --surface: #1a1a19; --surface-2: #232422; --border: #33352f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8e8d85;
    --accent: #3987e5; --danger: #e66767; --good: #3fb46f;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
h2.mt { margin-top: 24px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 8px 0 0; }
.spacer { flex: 1; }
.mono { font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--danger); }
.pos { color: var(--good); }

/* top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, var(--series-3), var(--series-1)); display: inline-block; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--text-2); padding: 8px 12px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 14px; }
select, input[type=text], input[type=number], input[type=date], input[type=month], input[type=password], textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { width: 100%; resize: vertical; }

.btn { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.wide { width: 100%; justify-content: center; margin-top: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 2px 6px; }
.btn.link.danger { color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid2 .card { margin-bottom: 0; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.tile .sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--text-2); font-weight: 500; font-size: 13px; }
th.num, td.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tr.total td { font-weight: 600; border-top: 2px solid var(--border); }
td.wrap { white-space: normal; max-width: 320px; }
.pnl th:first-child, .pnl td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 190px; }
.pnl tbody tr:hover td:first-child { background: var(--surface-2); }
.pnl tr.section td { font-weight: 600; background: var(--surface-2); }
.pnl tr.section td:first-child { background: var(--surface-2); }
.pnl tr.indent td:first-child { padding-left: 24px; color: var(--text-2); }
.pnl tr.key td { font-weight: 600; }
.pnl tr.memo td { color: var(--text-3); font-style: italic; }
.pnl td.total-col, .pnl th.total-col { font-weight: 600; border-left: 1px solid var(--border); }
.empty { color: var(--text-3); text-align: center; padding: 24px; }
.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 10px; }

/* chart */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--text-2); font-size: 12px; }
.chart .bar { shape-rendering: geometricPrecision; }
.chart .hit { fill: transparent; }
.chart .tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.chart .tooltip b { font-weight: 600; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin: 4px 0 8px; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }

/* forms */
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: 140px; }
form label { display: block; margin: 10px 0 0; font-size: 13px; color: var(--text-2); }
form label input, form label select, form label textarea { display: block; width: 100%; margin-top: 4px; color: var(--text); }
form button { margin-top: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .row2, .row3 { grid-template-columns: 1fr; } }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--surface); border-radius: 14px; padding: 20px; width: 100%; max-width: 520px; max-height: 95vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); color: #fff; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card .brand { font-size: 20px; margin-bottom: 4px; }
.login-card label { display: block; margin-top: 16px; font-size: 13px; color: var(--text-2); }
.login-card input { width: 100%; margin-top: 6px; font-size: 16px; }
