:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c232d;
  --line: #263042;
  --text: #e6edf3;
  --muted: #8b98a9;
  --up: #2ecc8f;
  --down: #ff6b6b;
  --accent: #4c8dff;
  --warn: #e2b23c;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 15px; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }

/* ------------------------------- login ------------------------------- */
.loginpage { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.loginbox {
  width: 100%; max-width: 22rem; padding: 1.5rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.loginbox h1 { display: flex; align-items: center; gap: 10px; font-size: 17px; margin-bottom: 1rem; }
.loginbox form { display: flex; flex-direction: column; gap: .8rem; }
.loginbox label { display: flex; flex-direction: column; gap: .3rem; font-size: 12px; color: var(--muted); }
.loginbox input {
  font-size: 15px; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 9px; padding: .55rem .7rem;
}
.loginbox .btn { width: 100%; text-align: center; padding: .6rem; }
.loginerror {
  margin: 0; padding: .5rem .65rem; border-radius: 9px; font-size: 12px;
  color: var(--down); background: rgba(255, 107, 107, .12); border: 1px solid rgba(255, 107, 107, .35);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: #11161d;
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.stamp { color: var(--muted); font-size: 12px; }

.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04101f; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.mini { padding: 3px 8px; font-size: 12px; }
.btn.danger { color: var(--down); }
.btn:disabled { opacity: .55; cursor: default; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px 18px 4px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.tile .value { font-size: 19px; font-weight: 650; margin-top: 6px; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

.panel { margin: 14px 18px 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 140px; align-items: center; gap: 10px; }
.bar-track { background: var(--panel2); border-radius: 6px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #4c8dff, #7a5cff); }
/* Fixed width steps instead of inline styles so a strict CSP can never block the bars. */
.w-2 { width: 2%; } .w-5 { width: 5%; } .w-10 { width: 10%; } .w-15 { width: 15%; }
.w-20 { width: 20%; } .w-25 { width: 25%; } .w-30 { width: 30%; } .w-35 { width: 35%; }
.w-40 { width: 40%; } .w-45 { width: 45%; } .w-50 { width: 50%; } .w-55 { width: 55%; }
.w-60 { width: 60%; } .w-65 { width: 65%; } .w-70 { width: 70%; } .w-75 { width: 75%; }
.w-80 { width: 80%; } .w-85 { width: 85%; } .w-90 { width: 90%; } .w-95 { width: 95%; }
.w-100 { width: 100%; }
.bar-label { color: var(--muted); font-size: 12px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

main { padding: 18px; display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head .stats { color: var(--muted); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid #1e2634; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover { background: #1a212c; }
td.num, th.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 10px; border: 1px solid var(--line); color: var(--muted); }
.tag.CORE { color: var(--up); border-color: #1f5c42; }
.tag.ACCUMULATE { color: var(--accent); border-color: #24406e; }
.tag.EXIT { color: var(--down); border-color: #6b2b2b; }
.tag.TARGET { color: var(--warn); border-color: #6b5720; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 14px; color: var(--muted); font-size: 13px; }
.foot { padding: 8px 18px 28px; }

.modal { position: fixed; inset: 0; background: rgba(2, 6, 12, .72); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(560px, 100%); max-height: 88vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-foot { display: flex; gap: 10px; padding: 14px 16px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.form .field { display: grid; gap: 5px; }
.form .field.wide { grid-column: 1 / -1; }
.form label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.form input, .form select {
  background: #0f141b; border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 14px; width: 100%;
}
.form input:focus, .form select:focus { outline: none; border-color: var(--accent); }
.form .hint { color: var(--muted); font-size: 11px; }
.error { color: var(--down); padding: 0 16px 14px; margin: 0; font-size: 13px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 30; }

/* ---------------------------------------------------------------- analytics */
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tab { background: transparent; color: var(--muted); border: 0; padding: 6px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.goal-track { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; height: 16px; overflow: hidden; }
.goal-fill { height: 100%; width: 0; background: linear-gradient(90deg, #2ecc8f, #4c8dff); transition: width .4s ease; }
.goal-meta { margin-top: 10px; font-size: 13px; }

.an-health { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; }
.hcard { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 6px; align-content: start; }
.hval { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; justify-self: start; padding: 2px 9px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .05em; border: 1px solid var(--line); color: var(--muted); }
.badge.OPTIMAL { color: var(--up); border-color: #1f5c42; }
.badge.MODERATE { color: var(--accent); border-color: #24406e; }
.badge.LOW { color: var(--warn); border-color: #6b5720; }
.badge.HIGH, .badge.AGGRESSIVE { color: var(--down); border-color: #6b2b2b; }

.attr-cards { display: none; }
.attr-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.attr-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 600; }
.attr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: 13px; }
.attr-grid .muted { display: block; font-size: 11px; }
.attr-grid b { font-variant-numeric: tabular-nums; }
tr.attr-total td { border-top: 2px solid var(--line); background: #131a23; font-weight: 650; }
.an-note { margin: 14px 18px 0; line-height: 1.5; }
.an-foot { margin: 10px 0 0; }
.trend-head { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 10px; font-size: 13px; }
.trend-head b { font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 90px; display: block; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; }

@media (max-width: 720px) {
  .bar-row { grid-template-columns: 92px 1fr 96px; }
  .form { grid-template-columns: 1fr; }
  th, td { padding: 7px 8px; }
  /* Analytics switches from table (desktop) to stacked cards (mobile). */
  #an-attr { display: none; }
  .attr-cards { display: grid; gap: 10px; }
  .tabs { order: 3; }
}

/* ------------------------------------------------------------ dashboard */
.who { font-size: 12px; }
.logout { display: inline; }
.dash-card .card-head { cursor: pointer; }
.dash-card .card-head::after { content: "▾"; color: var(--muted); margin-left: 10px; }
.dash-card:not(.open) .card-head::after { content: "▸"; }
.dash-card:not(.open) .dash-body { display: none; }
.dash-card .dash-body { margin-top: 6px; }
.dash-card .dash-body .table-wrap { margin-top: 0; }
