:root {
    --bg: #f4f5f7;
    --fg: #1f2329;
    --muted: #6b7280;
    --border: #d9dce1;
    --accent: #2563eb;
    --accent-fg: #fff;
    --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    color: var(--fg);
    background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.sidebar {
    display: flex;
    flex-direction: column;
    width: 260px;
    flex-shrink: 0;
    padding: 16px;
    background: #fff;
    border-right: 1px solid var(--border);
}

.sidebar-brand { font-weight: 700; font-size: 16px; padding: 6px 8px 16px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-nav .section-link {
    display: block;
    padding: 8px 8px;
    color: var(--fg);
    font-weight: 600;
    border-radius: 6px;
}
.sidebar-nav .section-link.active { background: #eef2ff; color: var(--accent); }

.report-groups { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 8px; }
.report-group-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 7px 8px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--fg);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.report-group-toggle:hover { background: #f4f5f7; }
.report-group-toggle .chevron { color: var(--muted); font-size: 11px; transition: transform .12s ease; }
.report-group.open .report-group-toggle .chevron { transform: rotate(90deg); }

.report-list { list-style: none; margin: 0; padding: 0 0 4px 8px; display: none; }
.report-group.open .report-list { display: block; }
.report-list li { margin: 0; }
.report-list a {
    display: block;
    padding: 6px 8px;
    color: var(--muted);
    border-radius: 6px;
    border-left: 2px solid var(--border);
}
.report-list a:hover { text-decoration: none; color: var(--fg); }
.report-list a.active { color: var(--fg); font-weight: 600; border-left-color: var(--accent); }

.sidebar-user {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 8px 4px;
    border-top: 1px solid var(--border);
    color: var(--muted);
}
.sidebar-user form { margin: 0; }

.content { flex: 1; padding: 24px; max-width: 1200px; }

h1 { font-size: 20px; margin: 0 0 16px; }

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

button, .btn {
    font: inherit;
    padding: 8px 16px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--accent-fg);
    border-radius: 6px;
    cursor: pointer;
}
button:hover, .btn:hover { opacity: .92; text-decoration: none; }

button.link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
}
button.link.danger, .danger { color: var(--danger); }

.form { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.form input, .form select, .filters input, .filters select {
    font: inherit;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }

.login-wrap { max-width: 360px; margin: 8vh auto 0; padding: 0 16px; }

.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 16px; }
.alert.error { background: #fde8e8; color: var(--danger); }

.muted { color: var(--muted); }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

table.report {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
table.report th, table.report td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
table.report thead th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.report tfoot td { font-weight: 700; background: #fafbfc; }
table.report.fixed { table-layout: fixed; }
table.report.fixed td, table.report.fixed th { overflow-wrap: anywhere; }
table.report .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.report .chain { color: var(--muted); max-width: 460px; white-space: pre-line; }

.pager {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
    color: var(--muted);
}

table.tree td.source { padding-left: calc(12px + var(--depth, 0) * 22px); }
table.tree .toggle {
    background: none;
    border: none;
    color: var(--muted);
    padding: 0 6px 0 0;
    cursor: pointer;
    font-size: 12px;
}
table.tree .toggle-spacer { display: inline-block; width: 12px; }
table.tree tr.collapsed-row { display: none; }
table.tree tr.depth-0 td { font-weight: 600; }

.actions { display: flex; gap: 12px; align-items: center; }
.actions form { margin: 0; }

/* Standalone sidebar sub-list (not inside a collapsible .report-group). */
.report-list.standalone { display: block; margin: 2px 0 8px; }

.period-quick { display: flex; gap: 8px; margin: -4px 0 16px; }
.period-quick a {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 13px;
}
.period-quick a:hover { text-decoration: none; color: var(--fg); }
.period-quick a.active { background: #eef2ff; color: var(--accent); border-color: var(--accent); }
