:root {
  --bg: #0b1220;
  --card: #131c2e;
  --card-2: #1b2740;
  --text: #e6edf6;
  --muted: #8aa0bd;
  --accent: #38bdf8;
  --accent-2: #2563eb;
  --ok: #22c55e;
  --mid: #f59e0b;
  --hi: #ef4444;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100svh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
}

/* ---- Login ---- */
.card {
  background: var(--card);
  border: 1px solid #243049;
  border-radius: var(--radius);
  padding: 28px 24px;
}
.login {
  width: min(92vw, 360px);
  text-align: center;
}
.logo {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  display: grid; place-items: center;
  font-size: 32px; font-weight: 800;
  color: #fff;
  border-radius: 18px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
}
.login h1 { margin: 6px 0 2px; font-size: 22px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid #2b3a59;
  border-radius: 12px;
  outline: none;
}
input[type="password"]:focus { border-color: var(--accent); }
button {
  font-size: 16px;
  font-weight: 600;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  color: #06121f;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  cursor: pointer;
}
button:disabled { opacity: .6; }
.msg { color: var(--hi); min-height: 1.2em; margin: 12px 0 0; font-size: 14px; }

/* ---- App shell ---- */
.topbar {
  position: sticky; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: rgba(11,18,32,.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #1d2740;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid #2b3a59;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
}

#view { padding: 16px 16px 96px; max-width: 720px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--card);
  border: 1px solid #243049;
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 6px; }
.bar {
  margin-top: 12px; height: 8px;
  background: #233149; border-radius: 99px; overflow: hidden;
}
.bar span {
  display: block; height: 100%; width: 0%;
  background: var(--ok); transition: width .4s ease;
}
.bar span.mid { background: var(--mid); }
.bar span.hi { background: var(--hi); }
.updated { color: var(--muted); font-size: 13px; text-align: center; margin-top: 18px; }

.soon-text { color: var(--muted); }
.soon-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.soon-list li {
  background: var(--card);
  border: 1px solid #243049;
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--muted);
}
.soon-list b { color: var(--text); }

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
  background: rgba(11,18,32,.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid #1d2740;
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 12px;
  padding: 10px;
  font-size: 14px; font-weight: 600;
}
.tab.active { color: var(--text); background: var(--card-2); }

/* ---- role badge + topbar spacer ---- */
.spacer { flex: 1; }
.badge {
  font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 99px;
  color: var(--muted); background: var(--card-2);
  border: 1px solid #2b3a59; margin-right: 10px;
  text-transform: uppercase; letter-spacing: .5px;
}
.badge.owner { color: #06121f; background: linear-gradient(160deg, var(--accent), var(--accent-2)); border-color: transparent; }

/* ---- role-based visibility ---- */
.owner-only { display: none; }
body[data-role="owner"] .owner-only { display: block; }
body[data-role="owner"] .viewer-only { display: none; }

/* ---- console ---- */
.console-log {
  min-height: 220px; max-height: 52vh; overflow-y: auto;
  background: #0a0f1a; border: 1px solid #243049; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.cline { white-space: pre-wrap; word-break: break-word; }
.cline.cmd { color: var(--text); }
.cline.out { color: var(--accent); }
.cline.ok  { color: var(--ok); }
.cline.muted { color: var(--muted); }
.console-form {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid #2b3a59; border-radius: 12px;
  padding: 10px 12px;
}
.console-form .prompt { color: var(--accent); font-family: ui-monospace, monospace; }
#console-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.console-hint { color: var(--muted); font-size: 12px; text-align: center; margin: 10px 0 0; }
body[data-role="owner"] .console-hint.viewer-only { display: none; }
.muted { color: var(--muted); }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--card-2); color: var(--text);
  border: 1px solid #2b3a59; border-radius: 12px;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 50;
}

/* ---- home: force perf blocks to a 2×2 grid ---- */
.grid.stats { grid-template-columns: repeat(2, 1fr); }

/* ---- category rows (full-width, stacked) ---- */
.cats { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.cat {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid #243049; border-radius: var(--radius);
  padding: 16px 16px; color: var(--text); font-weight: 500;
}
.cat:active { background: var(--card-2); }
.cat-ico { font-size: 24px; line-height: 1; }
.cat-txt { display: flex; flex-direction: column; flex: 1; gap: 2px; }
.cat-txt b { font-size: 16px; }
.cat-txt small { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.cat-arrow { color: var(--muted); font-size: 22px; }

/* ---- drill-in detail ---- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.detail-title { font-weight: 700; font-size: 17px; }

.list-card {
  background: var(--card); border: 1px solid #243049; border-radius: 12px;
  padding: 14px 16px; margin-bottom: 12px;
}
.list-title { font-weight: 700; margin-bottom: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card-2); color: var(--text);
  border: 1px solid #2b3a59; border-radius: 99px;
  padding: 8px 14px; font-size: 13px; font-weight: 600;
}
.chip:active { border-color: var(--accent); }
.chip:disabled { opacity: .5; }
.back-chip { display: inline-block; margin-top: 14px; }

/* ---- catalog search ---- */
.search {
  width: 100%; padding: 14px 16px; font-size: 16px;
  color: var(--text); background: var(--card-2);
  border: 1px solid #2b3a59; border-radius: 12px; outline: none; margin-bottom: 10px;
}
.search:focus { border-color: var(--accent); }
.gen-btn {
  width: 100%; margin-bottom: 14px;
  background: transparent; color: var(--accent);
  border: 1px dashed #2b3a59; border-radius: 12px; padding: 12px;
  font-size: 14px; font-weight: 600;
}
.results { display: flex; flex-direction: column; gap: 8px; }
.result {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid #243049; border-radius: 12px;
  padding: 13px 15px; color: var(--text);
}
.result:active { background: var(--card-2); }
.result-name { font-weight: 600; font-size: 15px; }
.result-group { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---- spectrum viewer ---- */
.spectrum { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.spectrum-img {
  width: 100%; max-width: 640px; height: auto;
  background: #fff; border-radius: 12px; border: 1px solid #243049;
}
.dl-btn {
  display: inline-block; text-decoration: none;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #06121f; font-weight: 700; padding: 12px 20px; border-radius: 12px;
}
.err { color: var(--hi); font-weight: 600; }
