/* Energy Attic brand: navy #2A3080, green #41B700, sky #6AA8DA.
   Chart series use slightly adjusted steps (#4650B8 / #2E9000) that pass contrast + color-blind checks. */
:root {
  --navy: #2A3080; --navy-2: #3a42a0; --green: #41B700; --green-ink: #2a7a00; --sky: #6AA8DA;
  --s-inv: #4650B8; --s-col: #2E9000;
  --bg: #f4f6fb; --surface: #ffffff; --ink: #1d2140; --ink-2: #4a4f6e; --muted: #6b7090; --line: #e1e4ef;
  --good: #1f7a1f; --bad: #b42318; --warn: #a15c00;
  --r: 12px; --shadow: 0 1px 2px rgba(20, 24, 60, .06), 0 2px 8px rgba(20, 24, 60, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 15px; line-height: 1.45; }
h1, h2, h3 { color: var(--navy); line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; } h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
a { color: var(--navy-2); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .pad { padding: 1.5rem; }
.err { color: var(--bad); } .ok { color: var(--good); font-weight: 600; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { background: #eef0f8; padding: 1px 5px; border-radius: 4px; }

/* header */
.demo-banner { background: #fff4d6; color: #5c3d00; border-bottom: 1px solid #f0d58a; padding: .5rem 1rem; text-align: center; font-size: .9rem; }
.top { display: flex; align-items: center; gap: 1rem; background: var(--surface); border-bottom: 4px solid var(--green); padding: .6rem 1.25rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand img { height: 40px; display: block; }
.top nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.top nav a { text-decoration: none; color: var(--ink-2); padding: .45rem .75rem; border-radius: 8px; font-weight: 600; font-size: .92rem; }
.top nav a.on { background: var(--navy); color: #fff; }
.top nav a:not(.on):hover { background: #eceefa; }
.who { margin-left: auto; display: flex; gap: .75rem; align-items: center; color: var(--muted); font-size: .88rem; }
main { max-width: 1240px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }

/* controls */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--navy); padding: .5rem .9rem; border-radius: 8px; cursor: pointer; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn:disabled { opacity: .6; cursor: progress; }
.link { background: none; border: 0; color: var(--navy-2); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.link.danger { color: var(--bad); }
input, select { font: inherit; padding: .45rem .55rem; border: 1px solid #c9cde0; border-radius: 8px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 3px solid rgba(65, 183, 0, .45); outline-offset: 1px; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: flex-end; background: var(--surface); padding: .8rem 1rem; border-radius: var(--r); box-shadow: var(--shadow); }
.f { display: flex; flex-direction: column; gap: .2rem; font-size: .78rem; color: var(--muted); font-weight: 600; }
.f.grow { flex: 1 1 180px; } .f.narrow input { width: 90px; }
.chk { display: flex; gap: .4rem; align-items: center; font-size: .9rem; color: var(--ink-2); }
.spacer { flex: 1; }
.chip { font-size: .82rem; padding: .3rem .7rem; border-radius: 999px; background: #e9f6e1; color: var(--green-ink); text-decoration: none; font-weight: 600; }
.chip.bad { background: #fde8e6; color: var(--bad); } .chip.warn { background: #fff1d6; color: var(--warn); }
.range-note { margin: .9rem 0 .2rem; font-size: .9rem; }

/* KPI cards */
.sec { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.1rem 0 .5rem; }
.grid { display: grid; gap: .75rem; }
.grid.money { grid-template-columns: repeat(4, 1fr); }
.grid.jobs { grid-template-columns: repeat(6, 1fr); }
.card { text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: .85rem 1rem; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: .15rem; min-width: 0; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--navy-2); transform: translateY(-1px); }
.card .lbl { font-size: .82rem; font-weight: 600; color: var(--ink-2); }
.card .kv { font-size: 1.6rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: .8rem; color: var(--muted); }
.card .cmp { font-size: .8rem; margin-top: .2rem; } .card .vs { color: var(--muted); }
.card.invoiced { border-top: 4px solid var(--s-inv); } .card.collected { border-top: 4px solid var(--s-col); }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; } .delta.good { color: var(--good); } .delta.bad { color: var(--bad); } .delta.flat { color: var(--muted); font-weight: 500; }
.dim { opacity: .5; pointer-events: none; }
.notice { display: block; width: 100%; text-align: left; font: inherit; margin-top: .9rem; background: #fff7e0; border: 1px solid #f1d58c; color: #5c3d00; border-radius: var(--r); padding: .7rem 1rem; cursor: pointer; }
.notice.static { cursor: default; } .notice.bad { background: #fde8e6; border-color: #f4b8b1; color: #7a1a12; }

/* panels & tables */
.panel { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 1rem 1.15rem; margin-top: 1rem; }
.panel-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; } .panel-head h2 { margin: 0; }
.legend { display: flex; gap: .4rem; align-items: center; font-size: .85rem; color: var(--ink-2); }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin: 0 .25rem 0 .5rem; vertical-align: middle; }
.key.inv { background: var(--s-inv); } .key.col { background: var(--s-col); }
.chart { position: relative; margin-top: .5rem; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; } .chart .axis { fill: var(--muted); font-size: 11px; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln.inv { stroke: var(--s-inv); } .chart .ln.col { stroke: var(--s-col); }
.chart .dot { stroke: #fff; stroke-width: 2; } .chart .dot.inv { fill: var(--s-inv); } .chart .dot.col { fill: var(--s-col); }
.chart .xhair { stroke: #9aa0bf; stroke-dasharray: 3 3; }
.tip { position: absolute; top: 4px; width: 190px; background: var(--ink); color: #fff; font-size: .8rem; padding: .5rem .6rem; border-radius: 8px; pointer-events: none; }
.tip .key { margin-left: 0; }
.how dl { display: grid; grid-template-columns: 220px 1fr; gap: .4rem 1rem; margin: .8rem 0 0; font-size: .9rem; }
.how dt { font-weight: 700; color: var(--navy); } .how dd { margin: 0; color: var(--ink-2); }
.how summary { cursor: pointer; font-weight: 700; color: var(--navy); }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 2px solid var(--line); padding: .45rem .5rem; white-space: nowrap; }
td { border-bottom: 1px solid var(--line); padding: .5rem; vertical-align: top; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.excl td, tr.off td { color: var(--muted); }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; border-radius: 999px; background: #e6e8f6; color: var(--navy); white-space: nowrap; }
.pill.grey { background: #eceef3; color: var(--muted); } .pill.green { background: #e3f4da; color: var(--green-ink); }
.pill.red { background: #fde8e6; color: var(--bad); } .pill.amber { background: #fff1d6; color: var(--warn); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 18, 45, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 20; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: min(1100px, 100%); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; } .modal-body { padding: 1rem 1.1rem 1.2rem; }
.x { font-size: 1.6rem; background: none; border: 0; cursor: pointer; color: var(--muted); line-height: 1; }
.row-actions { margin: .2rem 0 .7rem; }
.stack { display: flex; flex-direction: column; gap: .55rem; align-items: flex-start; max-width: 520px; }
.stack input:not([type=radio]) { width: 100%; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem; } legend { font-size: .85rem; color: var(--muted); }
.inline { display: flex; gap: .6rem; flex-wrap: wrap; }

/* categories */
.rule-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: .6rem; }
.tab { font: inherit; background: none; border: 0; padding: .45rem .7rem; cursor: pointer; color: var(--ink-2); border-bottom: 3px solid transparent; font-weight: 600; }
.tab.on { color: var(--navy); border-bottom-color: var(--green); }
.vals { display: flex; flex-wrap: wrap; gap: .4rem; max-height: 260px; overflow-y: auto; }
.val { font: inherit; font-size: .85rem; border: 1px solid #cfd3e6; background: #f7f8fd; border-radius: 999px; padding: .25rem .65rem; cursor: pointer; color: var(--ink); }
.val:hover { border-color: var(--navy-2); } .val.sm { font-size: .78rem; padding: .1rem .5rem; margin: 0 .2rem .2rem 0; }

table.rules { table-layout: fixed; min-width: 640px; }
table.rules th:nth-child(1) { width: 26%; } table.rules th:nth-child(2) { width: 24%; } table.rules th:nth-child(3) { width: 10%; }
table.rules th:nth-child(5) { width: 8%; } table.rules th:nth-child(6) { width: 9%; }

/* sync */
.status { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 1rem; align-items: start; }
.status > div { display: flex; flex-direction: column; gap: .15rem; }
.status .lbl { font-size: .8rem; color: var(--muted); font-weight: 600; } .status .big { font-size: 1.15rem; font-weight: 700; }
.status .act { align-items: flex-end; text-align: right; }

/* login */
.center-card { max-width: 420px; margin: 10vh auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 2rem; text-align: center; }
.center-card form { display: flex; flex-direction: column; gap: .6rem; text-align: left; margin-top: 1rem; }
.login-logo { width: 100%; max-width: 320px; } .center-card h1 { font-size: 1.2rem; }

.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .65rem 1rem; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* responsive */
@media (max-width: 1100px) { .grid.jobs { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 820px) {
  .grid.money { grid-template-columns: repeat(2, 1fr); }
  .status { grid-template-columns: 1fr 1fr; } .status .act { grid-column: 1 / -1; align-items: flex-start; text-align: left; }
  .how dl { grid-template-columns: 1fr; } .how dd { margin-bottom: .5rem; }
}
@media (max-width: 560px) {
  main { padding: .75rem .75rem 3rem; }
  .top { padding: .5rem .75rem; gap: .5rem; } .brand img { height: 30px; }
  .who span { display: none; }
  .top nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .top nav a { white-space: nowrap; padding: .4rem .6rem; font-size: .88rem; }
  .grid.jobs { grid-template-columns: repeat(2, 1fr); }
  .card { padding: .7rem .75rem; } .card .kv { font-size: 1.3rem; }
  .filters .f { flex: 1 1 40%; } .filters .f select, .filters .f input { width: 100%; }
  .status { grid-template-columns: 1fr; }
  table.drill td:nth-child(5), table.drill th:nth-child(5) { display: none; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }
