:root {
    --bg: #f4f6f8; --card: #fff; --ink: #1f2933; --muted: #6b7280; --line: #e5e7eb;
    --accent: #1f6feb; --accent-ink: #fff; --good: #137333; --bad: #b3261e; --shade: #f9fafb;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { background: #fde8e8; color: var(--bad); padding: .5rem .75rem; border-radius: 6px; margin-bottom: .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 360px; }
.login-card h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.login-card form { display: grid; gap: .6rem; margin: 1rem 0; }
input, select { padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 6px; font-size: .95rem; background: #fff; }
button { cursor: pointer; border: 0; border-radius: 6px; padding: .55rem .9rem; background: var(--accent); color: var(--accent-ink); font-size: .95rem; }
button.secondary { background: #eef2f7; color: var(--ink); }
button.link, .link { background: none; color: var(--accent); padding: 0; }
#google-btn { display: flex; justify-content: center; margin: .5rem 0; }

/* App shell */
.topbar { display: flex; align-items: center; gap: 1rem; background: #fff; border-bottom: 1px solid var(--line); padding: .6rem 1rem; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a { padding: .35rem .6rem; border-radius: 6px; color: var(--ink); }
.nav a:hover { background: var(--shade); text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.content { max-width: 1100px; margin: 1.25rem auto; padding: 0 1rem; }
.content.wide { max-width: 1500px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.25rem; box-shadow: 0 1px 2px rgba(0,0,0,.03); margin-bottom: 1rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > .card { flex: 1; min-width: 240px; }
h2 { font-size: 1.15rem; margin: .2rem 0 1rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--shade); }

.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: .75rem; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
form.inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.grid, form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem; align-items: end; }
label { display: grid; gap: .2rem; font-size: .8rem; color: var(--muted); }
.kpi { font-size: 1.6rem; font-weight: 700; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.badge { font-size: .75rem; padding: .1rem .4rem; border-radius: 999px; background: #eef2f7; color: var(--muted); }
dialog { border: 0; border-radius: 10px; padding: 1.25rem; max-width: 480px; width: 92%; }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tab { background: none; color: var(--muted); border-radius: 6px 6px 0 0; padding: .5rem .9rem; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }

/* Action links in list rows */
td.actions, th.actions { white-space: nowrap; }

/* Formatted reports (income statement / balance sheet) */
.report-scroll { overflow-x: auto; }
.inline-check { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--ink); }
table.report { font-size: .72rem; white-space: nowrap; }
table.report td, table.report th { padding: .14rem .5rem; border-bottom: 0; }
table.report thead th { border-bottom: 1px solid var(--line); }
table.report tr:hover td { background: transparent; }
/* Extra breathing room before each section header (gap after the prior subtotal). */
table.report tr.section td { font-weight: 700; background: var(--shade); padding-top: 1.15rem; padding-bottom: .35rem; }
table.report tbody tr.section:first-child td { padding-top: .4rem; }
table.report tr.subtotal td { font-weight: 600; border-top: 1px solid var(--line); }
table.report tr.net td { font-weight: 700; font-style: italic; background: var(--shade); }
table.report tr.total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
table.report td.pct, table.report th.pct { color: var(--muted); }
/* Collapsible parent/child rows (depth padding is inline per row; caret is a spacer on leaves) */
table.report .toggle { user-select: none; color: var(--muted); display: inline-block; width: 1.1em; text-align: center; }
table.report tr.has-children > td:first-child { cursor: pointer; }
