:root {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #171b25;
  --surface-3: #1e2330;
  --border: #262b38;
  --border-soft: #1c202b;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --muted-2: #5b6478;
  --accent: #7c6fee;
  --accent-strong: #6355e0;
  --accent-soft: rgba(124, 111, 238, .16);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, .14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, .14);
  --bad: #f2495c;
  --bad-soft: rgba(242, 73, 92, .14);
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 232px;
  --topbar-h: 60px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
code, .mono { font-family: "JetBrains Mono", "Cascadia Code", "Consolas", monospace; }

/* ---------- shell: sidebar + topbar + content ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px 20px;
  font-weight: 700; font-size: 15px; letter-spacing: .2px; color: var(--text);
}
.sidebar-brand .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: var(--radius-sm); color: var(--muted); font-size: 13.5px; font-weight: 500;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav a.active { background: var(--accent-soft); color: #cfc9ff; }
.sidebar-nav .icon { width: 16px; text-align: center; opacity: .85; font-size: 14px; }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 12px; margin-top: 12px; }
.sidebar-foot .pubkey-mini {
  font-size: 10.5px; color: var(--muted-2); word-break: break-all; line-height: 1.5;
  background: var(--surface-2); padding: 8px 9px; border-radius: var(--radius-sm);
}
.sidebar-foot .pubkey-mini b { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
  background: rgba(18, 21, 28, .85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; z-index: 5;
}
.search-form { flex: 1; max-width: 480px; }
.search-box {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; height: 36px;
}
.search-box:focus-within { border-color: var(--accent); }
.search-box .glyph { color: var(--muted-2); font-size: 13px; }
.search-box input {
  border: none; background: transparent; padding: 0; height: 100%; flex: 1;
  color: var(--text); font-size: 13.5px;
}
.search-box input:focus { outline: none; }
.search-box kbd {
  font-family: inherit; font-size: 11px; color: var(--muted-2); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px;
}
.topbar-spacer { flex: 1; }
.topbar .logout { margin: 0; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; width: 100%; }

/* ---------- headings ---------- */
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }
.eyebrow { color: var(--muted-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; margin: 0 0 6px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.card.danger { border-color: #3a1c22; }
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { width: 100%; max-width: 360px; }
.login-brand { display: flex; align-items: center; gap: 9px; justify-content: center; margin-bottom: 22px; font-weight: 700; font-size: 16px; }
.login-brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- KPI tiles ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi-tile {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 15px 16px;
}
.kpi-tile .kpi-label { font-size: 11.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.kpi-tile .kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.kpi-tile .kpi-value.ok { color: var(--ok); }
.kpi-tile .kpi-value.bad { color: var(--bad); }
.kpi-tile .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- product grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; margin-bottom: 22px; }
.product-card {
  display: block; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 18px;
  transition: border-color .12s ease;
}
.product-card:hover { border-color: var(--accent); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; position: relative; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.on::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 1px solid var(--ok);
  opacity: .55; animation: pulse 2s ease-out infinite;
}
.status-dot.off { background: var(--muted-2); }
@keyframes pulse { 0% { transform: scale(.6); opacity: .6; } 100% { transform: scale(2); opacity: 0; } }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stat-row { display: flex; gap: 20px; margin-top: 12px; color: var(--muted); flex-wrap: wrap; font-size: 13px; }
.bind-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.bind-grid code { display: block; margin: 6px 0; }

/* ---------- forms ---------- */
label { display: block; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; margin-top: 5px; padding: 9px 11px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13.5px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 8px; flex-direction: row; }
label.check input { width: auto; margin: 0; }
.field-hint { font-size: 11.5px; color: var(--muted-2); margin-top: 4px; font-weight: 400; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid button { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.inline-form input { width: auto; flex: 1; min-width: 140px; }

.btn {
  padding: 9px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.logout { margin: 0; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--muted-2); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.ellipsis { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.mono, .cell-mono { font-family: "JetBrains Mono", "Cascadia Code", "Consolas", monospace; font-size: 12px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; background: var(--surface-3); font-weight: 500; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.muted { color: var(--muted); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.slug { background: var(--surface-2); padding: 2px 8px; border-radius: 6px; font-size: 12px; color: var(--muted); font-family: "JetBrains Mono", monospace; }
.pubkey { display: block; word-break: break-all; background: var(--surface-2); padding: 12px; border-radius: 8px; margin: 10px 0; font-size: 12.5px; font-family: "JetBrains Mono", monospace; }
.muted { color: var(--muted); }
.hint { color: var(--muted-2); font-size: 12.5px; margin-top: 10px; }
.error { color: var(--bad); font-size: 13.5px; background: var(--bad-soft); padding: 8px 12px; border-radius: 8px; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.back:hover { color: var(--text); }

.customer-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px;
  background: var(--surface-2); border-radius: 20px; font-size: 12.5px;
}
.customer-chip .avatar {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700;
}
.customer-chip.empty { color: var(--muted-2); background: transparent; border: 1px dashed var(--border); padding: 3px 10px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .big { font-size: 28px; margin-bottom: 8px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; z-index: 20; transition: left .15s; }
  .sidebar.open { left: 0; }
  .form-grid, .bind-grid { grid-template-columns: 1fr; }
  .container { padding: 20px 16px 40px; }
}
