:root {
  --bg: #0b0f14;
  --surface: #131a22;
  --surface2: #1a232e;
  --line: #24303d;
  --text: #e8eef4;
  --muted: #8b9bab;
  --accent: #00d5c8;
  --accent2: #7c5cff;
  --grad: linear-gradient(135deg, #00d5c8 0%, #4f8cff 55%, #7c5cff 100%);
  --bad: #ff5c5c;
  --warn: #ffb020;
  --good: #2ecc71;
  --radius: 18px;
  --tap: 52px; /* generous touch targets */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: #05070a;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- phone frame (desktop only) ---------- */
.stage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 70% -10%, #10202b 0%, transparent 60%),
    radial-gradient(900px 500px at 10% 110%, #171030 0%, transparent 55%),
    #05070a;
}
.phone {
  position: relative;
  width: 393px;
  height: 852px;
  border-radius: 56px;
  border: 11px solid #10131a;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .65), 0 0 0 1px #2a3038;
  overflow: hidden;
  background: var(--bg);
}
.notch {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  width: 118px; height: 32px;
  background: #05070a;
  border-radius: 20px;
  z-index: 60;
}
.screen {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (max-width: 700px) {
  .stage { display: block; min-height: 100dvh; }
  .phone {
    width: 100%; height: 100dvh;
    border: none; border-radius: 0; box-shadow: none;
  }
  .notch { display: none; }
}

.hidden { display: none !important; }

/* ---------- app chrome ---------- */
#app { display: flex; flex-direction: column; height: 100%; }

#appbar {
  padding: 58px 18px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(11,15,20,.98), rgba(11,15,20,.92));
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.orb {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--grad);
  box-shadow: 0 0 18px rgba(0, 213, 200, .45);
  flex: none;
}
.orb.small { width: 26px; height: 26px; }
.brand h1 { font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.brand .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demo-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  color: #082421; background: var(--accent);
  padding: 3px 8px; border-radius: 999px;
}
.iconbtn {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
.iconbtn:active { background: var(--surface2); }

#main { flex: 1; overflow: hidden; position: relative; }
.view { height: 100%; overflow-y: auto; padding: 16px 16px 20px; }
.view::-webkit-scrollbar { display: none; }

/* ---------- tab bar ---------- */
#tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: rgba(13, 18, 24, .97);
  padding: 6px 10px calc(14px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1;
  min-height: var(--tap);
  border: none; background: none;
  color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  border-radius: 14px;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab .badge {
  position: absolute;
  margin-left: 26px; margin-top: -34px;
  background: var(--bad); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* ---------- cards & lists ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.section-title {
  font-size: 13px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin: 18px 2px 10px;
  display: flex; align-items: center; justify-content: space-between;
}

.health-strip { display: flex; gap: 10px; }
.health-cell {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: center;
}
.health-cell .num { font-size: 22px; font-weight: 800; }
.health-cell .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.health-cell.ok .num { color: var(--good); }
.health-cell.warn .num { color: var(--warn); }
.health-cell.bad .num { color: var(--bad); }

.action-item {
  display: flex; gap: 12px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  min-height: var(--tap);
  cursor: pointer;
}
.action-item:active { background: var(--surface2); }
.sev-dot {
  width: 12px; height: 12px; border-radius: 50%;
  margin-top: 5px; flex: none;
  box-shadow: 0 0 10px currentColor;
}
.sev-90 { color: var(--bad); background: var(--bad); }
.sev-60 { color: var(--warn); background: var(--warn); }
.sev-low { color: var(--muted); background: var(--muted); box-shadow: none; }
.action-body { flex: 1; min-width: 0; }
.action-title { font-size: 15px; font-weight: 700; }
.action-sub { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.action-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.pill {
  font-size: 11px; font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.pill.open { color: var(--bad); border-color: rgba(255,92,92,.4); }
.pill.validated { color: var(--warn); border-color: rgba(255,176,32,.4); }
.pill.resolved { color: var(--good); border-color: rgba(46,204,113,.4); }
.chev { color: var(--muted); font-size: 18px; margin-top: 8px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.chip {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.chip.active { background: rgba(0, 213, 200, .12); border-color: var(--accent); color: var(--accent); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
  line-height: 1.5;
}
.empty .big { font-size: 34px; margin-bottom: 10px; }

/* ---------- devices ---------- */
.dev-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 8px;
  min-height: var(--tap);
  cursor: pointer;
}
.dev-item:active { background: var(--surface2); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.status-dot.up { background: var(--good); box-shadow: 0 0 8px rgba(46,204,113,.6); }
.status-dot.down { background: var(--bad); box-shadow: 0 0 8px rgba(255,92,92,.6); }
.dev-name { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-model { font-size: 12px; color: var(--muted); }

/* ---------- chat ---------- */
#view-ask { display: flex; flex-direction: column; padding: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px 16px 8px; }
.chat-log::-webkit-scrollbar { display: none; }
.msg { display: flex; margin-bottom: 12px; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble {
  background: var(--grad);
  color: #041014;
  font-weight: 600;
  border-bottom-right-radius: 6px;
}
.msg.marvis .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg.marvis.thinking .bubble { color: var(--muted); font-style: italic; }
.msg-card { width: 100%; }
.msg-card .action-item, .msg-card .dev-item { margin-bottom: 8px; }

.chip-row {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 8px 16px;
  flex: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-row .chip { flex: none; }

.chat-input-row {
  display: flex; gap: 10px;
  padding: 8px 16px 12px;
  flex: none;
}
.chat-input-row input {
  flex: 1;
  min-height: var(--tap);
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 18px;
  font-size: 15px;
  outline: none;
}
.chat-input-row input:focus { border-color: var(--accent); }
.sendbtn {
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  border: none;
  background: var(--grad);
  color: #041014;
  font-size: 20px;
  cursor: pointer;
  flex: none;
}

/* inline confirm card in chat */
.confirm-card {
  background: var(--surface);
  border: 1px solid rgba(255,176,32,.5);
  border-radius: var(--radius);
  padding: 14px;
}
.confirm-card .q { font-size: 14px; margin-bottom: 12px; line-height: 1.4; }
.btn-row { display: flex; gap: 10px; }
.btn {
  flex: 1;
  min-height: var(--tap);
  border-radius: 14px;
  border: none;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
}
.btn.primary { background: var(--grad); color: #041014; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; }

/* ---------- bottom sheet ---------- */
#sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 40;
}
#sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 86%;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  border-top: 1px solid var(--line);
  z-index: 50;
  display: flex; flex-direction: column;
  animation: slideup .22s ease-out;
}
@keyframes slideup { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-grab { width: 44px; height: 5px; background: var(--line); border-radius: 3px; margin: 10px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 10px 18px; flex: none; }
.sheet-head h2 { font-size: 18px; flex: 1; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(22px + env(safe-area-inset-bottom)); }
.sheet-body::-webkit-scrollbar { display: none; }

.kv { display: flex; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); font-size: 13px; flex: none; width: 42%; }
.kv .v { font-size: 13.5px; word-break: break-word; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

.fixbox {
  background: rgba(0, 213, 200, .07);
  border: 1px solid rgba(0, 213, 200, .35);
  border-radius: var(--radius);
  padding: 14px;
  margin: 14px 0;
}
.fixbox .fixtitle { font-weight: 700; font-size: 14px; color: var(--accent); margin-bottom: 6px; }
.fixbox p { font-size: 13.5px; line-height: 1.45; color: var(--text); margin-bottom: 12px; }

.diag-result {
  background: var(--surface2);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 10px 0;
  font-size: 13.5px;
  line-height: 1.5;
}
.diag-result p { margin-bottom: 8px; }
.diag-result p:last-child { margin-bottom: 0; }

/* ---------- toast ---------- */
#toast {
  position: absolute;
  bottom: 110px; left: 50%;
  transform: translateX(-50%);
  background: #202c38;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 70;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
#toast.ok { border-color: rgba(46,204,113,.5); }
#toast.err { border-color: rgba(255,92,92,.5); }

/* ---------- login ---------- */
.login {
  height: 100%;
  display: flex; flex-direction: column;
  justify-content: center;
  padding: 34px;
  background:
    radial-gradient(500px 320px at 85% -5%, rgba(124, 92, 255, .18), transparent 60%),
    radial-gradient(420px 300px at 0% 100%, rgba(0, 213, 200, .12), transparent 60%),
    var(--bg);
}
.login .orb.hero {
  width: 74px; height: 74px;
  margin: 0 auto 18px;
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 24px rgba(0,213,200,.4); }
  50% { box-shadow: 0 0 48px rgba(124,92,255,.6); }
}
.login h1 { text-align: center; font-size: 26px; font-weight: 800; }
.login .tag { text-align: center; color: var(--muted); font-size: 13.5px; margin: 6px 0 30px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin: 0 4px 6px; font-weight: 600; }
.field input, .field select {
  width: 100%;
  min-height: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 16px;
  font-size: 15px;
  outline: none;
  appearance: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.login .btn.primary { width: 100%; margin-top: 8px; flex: none; }
.login.picker {
  justify-content: flex-start;
  padding-top: 74px;
  overflow-y: auto;
}
.login.picker h1 { font-size: 22px; }
.login.picker .dev-item { background: var(--surface); }

.login .demolink {
  margin-top: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  background: none; border: none;
  cursor: pointer;
  min-height: 44px;
  width: 100%;
}
.login .demolink b { color: var(--accent); }
.login .err {
  color: var(--bad);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
  margin-bottom: 8px;
}
.spin {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid rgba(4,16,20,.3);
  border-top-color: #041014;
  border-radius: 50%;
  animation: rot .7s linear infinite;
  vertical-align: -4px;
}
@keyframes rot { to { transform: rotate(360deg); } }
