:root {
  --bg: #0f1217;
  --panel: #171b22;
  --panel-2: #1e242d;
  --border: #2a313c;
  --text: #e6e9ee;
  --muted: #8b94a3;
  --accent: #ff7a3d;
  --accent-2: #4a9eff;
  --ok: #3fb950;
  --err: #f85149;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); margin-top: 8px; min-height: 1em; font-size: .9rem; }

button { cursor: pointer; font: inherit; }
button.primary {
  background: var(--accent); color: #0f1217; border: none;
  padding: 8px 16px; border-radius: var(--radius); font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; }
button.link:hover { color: var(--text); }
button.danger { background: none; border: 1px solid var(--err); color: var(--err); padding: 4px 10px; border-radius: 8px; }
button.ghost { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 4px 10px; border-radius: 8px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }

/* login */
.login { display: grid; place-items: center; height: 100vh; }
.login-card { padding: 32px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card h1 span, .brand span { color: var(--accent); }
.login-card label, #entity-form label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.login-card input, #entity-form input, #entity-form select, #entity-form textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 8px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); }

/* app shell */
.app { display: grid; grid-template-columns: 230px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 14px; }
.brand { font-size: 1.25rem; font-weight: 700; margin-bottom: 22px; padding-left: 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
#nav a { padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .95rem; }
#nav a:hover { background: var(--panel-2); color: var(--text); }
#nav a.active { background: var(--panel-2); color: var(--text); border-left: 2px solid var(--accent); }
.sidebar-foot { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; padding-left: 8px; }

.main { overflow: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 28px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); }
.topbar h2 { margin: 0; font-size: 1.2rem; }
.list { padding: 20px 28px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--panel); }
td .row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: .75rem; border: 1px solid var(--border); }
.badge.on { color: var(--ok); border-color: var(--ok); }
.badge.off { color: var(--muted); }
code.mono { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: .85rem; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal-card { padding: 24px; width: 460px; max-height: 88vh; overflow: auto; }
.modal-card h3 { margin: 0 0 16px; }
#entity-form { display: flex; flex-direction: column; gap: 12px; }
#entity-form .checkbox { flex-direction: row; align-items: center; gap: 8px; }
#entity-form .checkbox input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* stats dashboard */
.stats-controls { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 22px; }
.stats-controls label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
.stats-controls input, .stats-controls select { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 8px; font: inherit; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric-val { font-size: 1.7rem; font-weight: 700; }
.metric-label { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 22px; }
.panel h4 { margin: 0 0 14px; font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 130px; align-items: center; gap: 12px; margin-bottom: 8px; }
.funnel-label { font-size: .88rem; }
.funnel-track { background: var(--panel-2); border-radius: 6px; height: 22px; overflow: hidden; }
.funnel-fill { background: linear-gradient(90deg, var(--accent-2), var(--accent)); height: 100%; }
.funnel-num { text-align: right; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: auto; }
.spark-legend { font-size: .8rem; margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px; margin-bottom: 22px; }
.grid2 .panel { margin-bottom: 0; padding: 0; overflow: hidden; }

/* toast */
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--panel-2); border: 1px solid var(--border); padding: 12px 18px; border-radius: 8px; z-index: 60; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }
