:root {
  --bg: #050505;
  --surface: #0b0b0b;
  --surface-2: #111;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.35);
  --text: #f4f1e9;
  --muted: #8d8b86;
  --accent: #fff;
  --danger: #d56d6d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -15%, rgba(255,255,255,.09), transparent 32rem),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }

.noise {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
}

.app, .locked {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 22px 16px calc(36px + var(--safe-bottom));
}

.locked {
  min-height: 100vh;
  display: grid;
  align-content: center;
  text-align: center;
}

.locked-eye {
  width: 132px;
  height: 62px;
  margin: 0 auto 30px;
  border: 1px solid var(--line-strong);
  border-radius: 100% 0 100% 0;
  transform: rotate(45deg);
  box-shadow: inset 0 0 35px rgba(255,255,255,.1);
}

.locked-eye::after {
  content: "";
  display: block;
  width: 28px;
  height: 28px;
  margin: 16px auto;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 28px rgba(255,255,255,.65);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(22px, 6vw, 36px); letter-spacing: -.05em; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.035em; }
h3 { margin: 0; font-size: 13px; font-weight: 500; letter-spacing: -.02em; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }
.owner-button {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  letter-spacing: .05em;
  white-space: nowrap;
}
.topbar > div:first-child { min-width: 0; }

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255,255,255,.025);
  font-size: 22px;
}

.setup-card {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(135deg, rgba(255,255,255,.07), transparent 45%),
    var(--surface);
}
.setup-card.connected { border-color: rgba(255,255,255,.22); }
.setup-head { display: flex; justify-content: space-between; align-items: start; }
.setup-state {
  padding: 5px 8px;
  border: 1px solid rgba(213,109,109,.5);
  color: var(--danger);
  font-size: 9px;
  letter-spacing: .06em;
}
.setup-card.connected .setup-state { border-color: rgba(255,255,255,.4); color: var(--text); }
.setup-intro { margin: 10px 0 18px; color: #b5b2aa; font-size: 12px; line-height: 1.55; }
.setup-steps { display: grid; gap: 0; margin: 0 0 18px; padding: 0; list-style: none; counter-reset: setup; }
.setup-steps li {
  position: relative;
  min-height: 54px;
  padding: 7px 0 11px 42px;
  border-left: 1px solid var(--line);
  counter-increment: setup;
}
.setup-steps li:last-child { min-height: auto; border-left-color: transparent; }
.setup-steps li::before {
  content: counter(setup, decimal-leading-zero);
  position: absolute;
  top: 0;
  left: -15px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  font-size: 9px;
}
.setup-steps strong { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 500; }
.setup-steps span { display: block; color: var(--muted); font-size: 10px; line-height: 1.45; }
.setup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.setup-note { margin: 14px 0 0; color: #777; font-size: 9px; line-height: 1.5; }
.setup-card.connected .setup-steps { display: none; }
.setup-card.connected .setup-intro { margin-bottom: 14px; }

.signal-card {
  position: relative;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #000;
}

.signal-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(1) contrast(1.22) brightness(.55);
  transform: scale(1.02);
  animation: breathe 9s ease-in-out infinite alternate;
}

.signal-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 20%, rgba(0,0,0,.15) 48%, #000 100%);
}

.scanline {
  position: absolute;
  z-index: 1;
  inset: -30% 0 auto;
  height: 22%;
  background: linear-gradient(transparent, rgba(255,255,255,.09), transparent);
  animation: scan 5s linear infinite;
}

.signal-copy {
  position: absolute;
  z-index: 2;
  right: 18px;
  bottom: 18px;
  left: 18px;
}

.signal-state {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 12px;
  letter-spacing: .08em;
}

.signal-state::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px #fff;
  animation: pulse 1.6s ease-in-out infinite;
}

.signal-meta { margin: 7px 0 0; color: #aaa; font-size: 11px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.metrics article { padding: 16px 12px; border-right: 1px solid var(--line); }
.metrics article:last-child { border-right: 0; }
.metrics strong { display: block; margin-bottom: 5px; font-size: 20px; font-weight: 500; }
.metrics span { color: var(--muted); font-size: 9px; letter-spacing: .06em; text-transform: uppercase; }

.toolbar { margin: 36px 0 30px; }
.search {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-strong);
}
.search span { color: var(--muted); font-size: 20px; }
.search input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.search input::placeholder { color: #666; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
}
.filter.active { border-color: var(--text); color: #050505; background: var(--text); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.section-head span { color: var(--muted); font-size: 11px; }

.trace-list { display: grid; gap: 10px; }
.trace {
  position: relative;
  overflow: hidden;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: linear-gradient(135deg, rgba(255,255,255,.035), transparent 45%);
}
.trace::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 2px; background: #777; }
.trace[data-type="delete"]::before { background: #fff; }
.trace.saved { border-color: var(--line-strong); box-shadow: inset 0 0 24px rgba(255,255,255,.035); }
.trace-head { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.trace-kind { color: var(--text); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.trace-time { color: var(--muted); font-size: 9px; white-space: nowrap; }
.trace-chat { margin: 0 0 3px; font-size: 12px; }
.trace-author { margin: 0 0 14px; color: var(--muted); font-size: 10px; }
.trace-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; font-size: 13px; line-height: 1.55; }
.trace-diff { display: grid; gap: 7px; }
.trace-diff p { margin: 0; padding: 9px 10px; background: rgba(255,255,255,.03); font-size: 12px; line-height: 1.45; }
.trace-diff s { color: #8b6b6b; text-decoration-thickness: 1px; }
.trace-diff mark { color: #fff; background: rgba(255,255,255,.17); }
.trace-media { margin: 12px 0 0; color: var(--muted); font-size: 10px; }
.trace-actions { display: flex; gap: 8px; margin-top: 15px; }
.trace-actions button { padding: 8px 10px; border: 1px solid var(--line); background: transparent; font-size: 9px; }
.trace-actions button:last-child { margin-left: auto; color: var(--muted); }

.empty { padding: 54px 20px; color: var(--muted); text-align: center; }
.empty span { font-size: 34px; }
.empty p { margin-top: 10px; }
.load-more { width: 100%; margin-top: 12px; padding: 13px; border: 1px solid var(--line); background: transparent; }

.billing-card { margin-top: 34px; padding: 18px; border: 1px solid var(--line-strong); background: #0d0d0d; }
.billing-card p:not(.eyebrow) { margin: 12px 0 18px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.primary-button, .secondary-button, .danger-button { width: 100%; padding: 14px; border: 1px solid var(--text); background: var(--text); color: #050505; }
.secondary-button { border-color: var(--line-strong); color: var(--text); background: transparent; }
.danger-button { border-color: rgba(213,109,109,.55); color: var(--danger); background: transparent; }

.sheet {
  width: min(calc(100% - 24px), 720px);
  max-height: 82vh;
  margin: auto auto 8px;
  padding: 20px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--text);
  background: rgba(8,8,8,.98);
}
.sheet::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(6px); }
.sheet header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.context-list { display: grid; gap: 8px; }
.context-item { padding: 12px; border-left: 1px solid var(--line-strong); background: rgba(255,255,255,.025); }
.context-item p { margin: 0; font-size: 12px; line-height: 1.5; }
.context-item small { display: block; margin-bottom: 7px; color: var(--muted); }
.settings-copy { color: var(--muted); font-size: 12px; line-height: 1.6; }
.legal-links { display: flex; gap: 18px; }
.legal-links a { color: var(--text); text-underline-offset: 4px; }

.owner-sheet { max-height: 94vh; margin-bottom: 0; }
.owner-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 22px;
  border: 1px solid var(--line);
}
.owner-summary article { padding: 12px; border-right: 1px solid var(--line); }
.owner-summary article:last-child { border-right: 0; }
.owner-summary span, .owner-summary small { display: block; color: var(--muted); font-size: 8px; }
.owner-summary strong { display: block; margin: 8px 0 5px; font-size: 18px; font-weight: 500; }
.owner-block { margin-top: 12px; padding: 16px; border: 1px solid var(--line); background: rgba(255,255,255,.02); }
.owner-access-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 8px; }
.owner-access-form input {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-strong);
  outline: none;
  color: var(--text);
  background: #070707;
}
.owner-access-form button { width: auto; min-width: 100px; }
.invite-result { display: grid; gap: 8px; margin-top: 10px; }
.invite-result code { padding: 11px; overflow-wrap: anywhere; border: 1px dashed var(--line); color: #b5b2aa; font-size: 9px; }
.text-button { padding: 0; border: 0; color: var(--muted); background: transparent; font-size: 9px; text-decoration: underline; text-underline-offset: 3px; }
.owner-users { display: grid; gap: 8px; }
.owner-user { padding: 12px; border-left: 2px solid var(--text); background: rgba(255,255,255,.025); }
.owner-user.disabled { border-left-color: #444; opacity: .68; }
.owner-user-head { display: flex; justify-content: space-between; gap: 12px; }
.owner-user-head strong { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 500; }
.owner-user-head code { color: var(--muted); font-size: 9px; }
.owner-connection { color: var(--muted); font-size: 8px; white-space: nowrap; }
.owner-connection.online { color: var(--text); }
.owner-user p { margin: 10px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.owner-user small { display: block; margin-top: 11px; color: var(--muted); }
.owner-user button { margin-top: 11px; padding: 9px; font-size: 9px; }
.owner-payments { display: grid; }
.owner-payments article { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.owner-payments article:last-child { border-bottom: 0; }
.owner-payments strong, .owner-payments span { display: block; font-size: 10px; }
.owner-payments span, .owner-payments time { margin-top: 4px; color: var(--muted); font-size: 8px; }
.owner-empty { margin: 0; color: var(--muted); font-size: 10px; }
.owner-system { margin-top: 20px; padding: 14px; border-left: 1px solid var(--line-strong); color: var(--muted); font-size: 9px; line-height: 1.55; }
.owner-system p { margin-bottom: 8px; }
.owner-system p:last-child { margin-bottom: 0; }

.legal-page {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 48px 0 80px;
  line-height: 1.7;
}
.legal-page header { margin-bottom: 42px; padding-bottom: 22px; border-bottom: 1px solid var(--line-strong); }
.legal-page h1 { margin-bottom: 10px; }
.legal-page h2 { margin: 34px 0 10px; }
.legal-page p, .legal-page li { color: #b5b2aa; font-size: 13px; }
.legal-page a { color: var(--text); }

.toast {
  position: fixed;
  z-index: 40;
  right: 14px;
  bottom: calc(16px + var(--safe-bottom));
  left: 14px;
  max-width: 620px;
  margin: auto;
  padding: 13px 15px;
  transform: translateY(140%);
  border: 1px solid var(--line-strong);
  background: #111;
  font-size: 11px;
  transition: transform .25s ease;
}
.toast.visible { transform: translateY(0); }

@keyframes breathe { from { transform: scale(1.02); filter: grayscale(1) contrast(1.22) brightness(.48); } to { transform: scale(1.08); filter: grayscale(1) contrast(1.32) brightness(.66); } }
@keyframes scan { to { transform: translateY(650%); } }
@keyframes pulse { 50% { opacity: .3; box-shadow: 0 0 2px #fff; } }

@media (max-width: 430px) {
  .app { padding-right: 12px; padding-left: 12px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics article:nth-child(2) { border-right: 0; }
  .metrics article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .signal-card { min-height: 235px; }
  .setup-actions { grid-template-columns: 1fr; }
  .owner-summary { grid-template-columns: repeat(2, 1fr); }
  .owner-summary article:nth-child(2) { border-right: 0; }
  .owner-summary article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
