:root,
    :root[data-theme="light"] {
      color-scheme: light;
      --bg: #f8fbf7;
      --header: #eef6ed;
      --panel: #ffffff;
      --card: #ffffff;
      --soft: #edf6ed;
      --line: #dce6dc;
      --text: #233128;
      --muted: #657269;
      --brand: #2f7a3e;
      --brand-contrast: #ffffff;
      --accent: #2f7a3e;
      --accent-2: #079e99;
      --accent-soft: #c6d7c9;
      --chart-fill: #dce9de;
      --tree-2: #6ea67a;
      --tree-3: #a4c7aa;
      --tree-4: #c5dcc9;
      --warn: #9a6a00;
      --ok: #2f7a3e;
      --bad: #b42318;
      --shadow: 0 16px 40px rgba(36, 52, 40, .12);
    }
    :root[data-theme="dark"] {
      color-scheme: dark;
      --bg: #0d1117;
      --header: #0b1018;
      --panel: #161b22;
      --card: #161b22;
      --soft: #1c2129;
      --line: #30363d;
      --text: #c9d1d9;
      --muted: #8b949e;
      --brand: #58a6ff;
      --brand-contrast: #0d1117;
      --accent: #56d364;
      --accent-2: #39c5cf;
      --accent-soft: #30363d;
      --chart-fill: #1f2a22;
      --tree-2: #3fb950;
      --tree-3: #2ea043;
      --tree-4: #238636;
      --warn: #f2cc60;
      --ok: #56d364;
      --bad: #ff7b72;
      --shadow: 0 16px 40px rgba(0, 0, 0, .28);
    }
    * { box-sizing: border-box; }
    body { margin: 0; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
    header { padding: 24px; border-bottom: 1px solid var(--line); background: var(--header); }
.header-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.header-copy { min-width: 0; }
h1 { margin: 0 0 8px; font-size: 1.8rem; }
.sub { color: var(--muted); margin: 0; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.header-link { display: inline-flex; justify-content: center; align-items: center; }
.header-insights { display: grid; grid-template-columns: repeat(7, minmax(140px, 1fr)); gap: 10px; margin-top: 16px; }
    .insight { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
    .insight strong { display: block; color: var(--text); font-size: 1rem; overflow-wrap: anywhere; }
    .insight span { display: block; color: var(--muted); font-size: 0.78rem; margin-bottom: 4px; }
    .theme-toggle { flex: 0 0 auto; min-width: 132px; }
    .dashboard-panel { margin-top: 18px; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 18px; box-shadow: var(--shadow); }
    .dashboard-panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
    .panel-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
    .dashboard-panel h2 { margin: 0; color: var(--text); font-size: 1.5rem; }
    .dashboard-panel .panel-note { color: var(--muted); font-size: .86rem; margin-top: 4px; }
    .panel-badge { border: 1px solid var(--line); color: var(--brand); background: var(--soft); border-radius: 999px; padding: 6px 10px; font-size: .78rem; white-space: nowrap; }
    .term-strip { display: none; }
    .term-help { position: relative; }
    .term-help summary, .chart-help summary { list-style: none; cursor: pointer; border: 1px solid var(--line); background: var(--soft); color: var(--brand); border-radius: 999px; padding: 6px 10px; font-size: .78rem; font-weight: 700; }
    .term-help summary::-webkit-details-marker, .chart-help summary::-webkit-details-marker { display: none; }
    .term-help[open] summary, .chart-help[open] summary { background: var(--brand); color: var(--brand-contrast); }
    .term-help p, .chart-help p { margin: 8px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.35; }
    .term-help p { max-width: 280px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 10px; box-shadow: var(--shadow); }
    .dashboard-insight { display: none; }
    .dashboard-insight strong { display: block; color: var(--text); margin-bottom: 6px; }
    .dashboard-insight p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.4; }
    .management-alerts { border: 1px solid var(--line); background: var(--soft); border-radius: 8px; padding: 12px; margin: 14px 0 0; order: 3; }
    .management-alerts h3 { margin: 0 0 8px; font-size: .98rem; color: var(--text); }
    .alerts-list { display: grid; gap: 8px; }
    .alert-item { border: 1px solid var(--line); border-left-width: 5px; background: var(--card); border-radius: 8px; padding: 10px; }
    .alert-item strong { display: block; color: var(--text); font-size: .9rem; margin-bottom: 3px; }
    .alert-item p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.35; }
    .alert-item a { display: inline-block; margin-top: 6px; font-size: .82rem; }
    .alert-critical { border-left-color: var(--bad); }
    .alert-warning { border-left-color: var(--warn); }
    .alert-info { border-left-color: var(--brand); }
    .alert-empty { color: var(--muted); font-size: .86rem; margin: 0; }
    .dashboard-kpis { display: grid; grid-template-columns: repeat(4, minmax(170px, 1fr)); gap: 12px; }
    .kpi-card { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 12px; min-height: 84px; }
    .kpi-card span { display: block; color: var(--muted); font-size: .82rem; margin-bottom: 8px; }
    .kpi-card strong { display: block; color: var(--text); font-size: 1.22rem; line-height: 1.2; overflow-wrap: anywhere; }
    .kpi-card small { display: block; color: var(--muted); margin-top: 8px; font-size: .72rem; }
    .dashboard-panel { display: flex; flex-direction: column; }
    .dashboard-charts { display: grid; grid-template-columns: repeat(4, minmax(190px, 1fr)); gap: 12px; margin-top: 12px; order: 2; }
    .chart-card { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 12px; min-height: 210px; }
    .chart-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
    .chart-card h3 { margin: 0 0 8px; color: var(--text); font-size: .95rem; font-weight: 700; }
    .chart-card-head h3 { margin-bottom: 0; }
    .chart-help { display: none; }
    .chart-help summary { width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
    .chart-help p { position: absolute; top: 30px; right: 0; z-index: 10; width: min(280px, 80vw); border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 10px; box-shadow: var(--shadow); }
    .chart-value { color: var(--text); font-size: 1.16rem; margin-bottom: 8px; }
    .chart-slot { min-height: 128px; display: flex; align-items: center; justify-content: center; }
    .chart-empty { color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; padding: 16px; font-size: .86rem; }
    .chart-legend { display: flex; flex-wrap: wrap; gap: 7px 10px; color: var(--muted); font-size: .74rem; line-height: 1.35; margin-top: 8px; min-width: 0; }
    .chart-legend span { display: inline-flex; align-items: center; max-width: 100%; overflow-wrap: anywhere; white-space: normal; }
    .chart-note { color: var(--muted); font-size: .72rem; line-height: 1.35; margin-top: 8px; }
.history-meta { color: var(--muted); font-size: .68rem; line-height: 1.35; margin-top: 6px; text-align: center; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.legend-accent { background: var(--accent); }
.legend-accent-2 { background: var(--accent-2); }
.legend-accent-soft { background: var(--accent-soft); }
.rap-bars { width: 100%; min-height: 132px; display: grid; grid-template-columns: repeat(2, minmax(70px, 1fr)); gap: 12px; align-items: end; padding: 4px 8px 0; }
.rap-bar-item { min-width: 0; display: grid; gap: 6px; align-items: end; text-align: center; color: var(--muted); font-size: .72rem; }
.rap-bar-track { height: 104px; border: 1px solid var(--line); background: var(--soft); display: flex; align-items: end; justify-content: center; }
.rap-bar-fill { width: 100%; min-height: 2px; }
.rap-bar-fill.paid { background: var(--accent); }
.rap-bar-fill.open { background: var(--accent-2); }
.rap-bar-label { overflow-wrap: anywhere; }
.rap-bar-value { color: var(--text); font-weight: 700; overflow-wrap: anywhere; }
.stack-bar { width: 92px; height: 132px; display: flex; flex-direction: column-reverse; border: 1px solid var(--line); background: var(--soft); }
    .stack-paid { background: var(--accent); }
    .stack-open { background: var(--accent-2); }
    .treemap { width: 100%; height: 132px; display: grid; grid-template-columns: 2fr 1.15fr; grid-template-rows: 1.15fr .85fr; gap: 3px; }
    .tree-cell { background: var(--accent); color: var(--brand-contrast); padding: 7px; overflow: hidden; font-size: .67rem; display: flex; align-items: end; }
    .tree-cell:nth-child(2) { background: var(--tree-2); }
    .tree-cell:nth-child(3) { background: var(--tree-3); color: var(--text); }
    .tree-cell:nth-child(4) { background: var(--tree-4); color: var(--text); }
    main { padding: 20px; max-width: 1400px; margin: 0 auto; }
    .toolbar { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 10px; margin-bottom: 14px; }
    input, select, button { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 6px; padding: 10px 12px; font-size: 0.95rem; }
    button { cursor: pointer; color: var(--brand-contrast); background: var(--brand); border-color: var(--brand); font-weight: 700; }
    .summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .metric { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
    .metric strong { display: block; font-size: 1.35rem; color: var(--text); }
    .metric span { color: var(--muted); font-size: 0.85rem; }
    .table-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: 70vh; background: var(--panel); }
    table { width: 100%; border-collapse: collapse; min-width: 980px; }
    th, td { border-bottom: 1px solid var(--line); padding: 10px; text-align: left; vertical-align: top; }
    th { position: sticky; top: 0; background: var(--soft); z-index: 1; cursor: pointer; }
    tr:hover td { background: var(--soft); }
    a { color: var(--brand); text-decoration: none; }
    a:hover { text-decoration: underline; }
    .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 0.8rem; color: var(--muted); }
    .quality-badges { display: flex; flex-wrap: wrap; gap: 4px; }
    .quality-code { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; border-radius: 999px; border: 1px solid var(--line); background: var(--soft); color: var(--text); font-size: .72rem; font-weight: 700; }
    .quality-code.warn { color: var(--warn); }
    .quality-code.bad { color: var(--bad); }
    .quality-legend { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 10px; color: var(--muted); font-size: .82rem; }
    .site-footer { max-width: 1400px; margin: 24px auto 0; padding: 18px 20px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: .86rem; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
    .ok { color: var(--ok); }
    .bad { color: var(--bad); }
    .warn { color: var(--warn); }
    @media (max-width: 1100px) { .dashboard-kpis, .dashboard-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
    @media (max-width: 900px) { .header-top { display: block; } .theme-toggle { margin-top: 12px; width: 100%; } .toolbar, .summary, .header-insights, .dashboard-kpis, .dashboard-charts { grid-template-columns: 1fr; } main { padding: 12px; } .dashboard-panel-head, .panel-actions { display: block; } .panel-badge { display: inline-block; margin-top: 10px; } .site-footer { display: block; } }
