:root {
  color-scheme: light;
  --bg: #f3efe8;
  --bg-deep: #e7e1d6;
  --ink: #1c1916;
  --muted: #3e3a34;
  --line: rgba(60, 48, 32, 0.14);
  --card: rgba(255, 252, 248, 0.82);
  --card-solid: #fffcf8;
  --teal: #0d5c59;
  --teal-deep: #0a4745;
  --teal-soft: #e5f3f1;
  --rust: #6e241c;
  --rust-soft: #fdeceb;
  --amber: #6a4510;
  --amber-soft: #f8efd8;
  --good: #145c38;
  --good-soft: #e5f4eb;
  --elev-1: inset 0 1px 0 rgba(255, 255, 255, 0.75), 0 1px 2px rgba(40, 32, 22, 0.04), 0 12px 28px rgba(40, 32, 22, 0.06);
  --elev-2: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 2px rgba(40, 32, 22, 0.05), 0 22px 50px rgba(40, 32, 22, 0.1);
  --elev-3: inset 0 1px 0 rgba(255, 255, 255, 0.88), 0 2px 4px rgba(40, 32, 22, 0.05), 0 28px 70px rgba(40, 32, 22, 0.14);
  --sans: system-ui, "Segoe UI", "Helvetica Neue", sans-serif;
  --radius: 28px;
  --space: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { scroll-padding-top: 112px; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 480px at 0% -10%, #faf6ef 0%, transparent 58%),
    radial-gradient(720px 420px at 100% 0%, rgba(190, 220, 214, 0.45), transparent 55%),
    radial-gradient(640px 420px at 80% 100%, rgba(232, 216, 190, 0.55), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(380px 240px at 14% 12%, rgba(255, 255, 255, 0.72), transparent 70%),
    radial-gradient(460px 300px at 92% 18%, rgba(176, 210, 204, 0.28), transparent 72%);
}
body > * { position: relative; z-index: 1; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button, .primary, .ghost, .danger {
  transition: transform 160ms ease, background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
button:active:not(:disabled) { transform: scale(0.98); }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.skip {
  position: absolute;
  left: 16px;
  top: 12px;
  z-index: 40;
  transform: translateY(-160%);
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.skip:focus { transform: none; }
:focus-visible {
  outline: 3px solid rgba(13, 92, 89, 0.55);
  outline-offset: 2px;
}

#gate:not([hidden]) {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(32px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  box-shadow: var(--elev-2);
  padding: 28px;
  backdrop-filter: blur(22px) saturate(1.15);
}
#gate .card {
  width: min(420px, 100%);
  box-shadow: var(--elev-3);
  background: rgba(255, 252, 248, 0.92);
}
.mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 46%),
    var(--teal);
  color: #f7fffe;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 10px 18px rgba(13, 92, 89, 0.22);
}
h1, h2, h3 {
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0;
}
h1 { font-size: 2rem; margin-top: 16px; }
h2 { font-size: 1.35rem; }
.lede { color: var(--muted); margin: 8px 0 20px; }
label, .filter-label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 12px;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  padding: 12px 14px;
  min-height: 44px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.primary, .ghost, .danger {
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  border: 1px solid transparent;
}
.primary {
  background: var(--teal);
  color: #f7fffe;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 8px 18px rgba(13, 92, 89, 0.22);
}
.primary:hover { background: var(--teal-deep); }
.ghost {
  background: rgba(255, 255, 255, 0.55);
  border-color: var(--line);
}
.ghost:hover { background: var(--teal-soft); border-color: rgba(13, 92, 89, 0.22); }
.danger {
  background: var(--rust-soft);
  color: var(--rust);
  border-color: #e7b7b0;
  font-weight: 600;
}
.danger:hover { background: #f8dcd9; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 12rem; }
.error, .hint {
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.error {
  background: var(--rust-soft);
  color: var(--rust);
  border: 1px solid #e7b7b0;
}
.hint {
  background: var(--teal-soft);
  color: #0e3f3d;
  border: 1px solid rgba(13, 92, 89, 0.16);
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  width: min(1180px, calc(100% - 32px));
  margin: max(16px, env(safe-area-inset-top)) auto 0;
  padding: 14px 18px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 24px;
  background: rgba(255, 252, 248, 0.78);
  box-shadow: var(--elev-1);
  backdrop-filter: blur(22px) saturate(1.12);
  position: sticky;
  top: 12px;
  z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand strong { display: block; font-size: 1.05rem; }
.brand p { margin: 0; color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.stage {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 48px;
}
.banner {
  margin: 0 0 20px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(248, 239, 216, 0.92);
  color: #4a3208;
  border: 1px solid rgba(138, 100, 32, 0.22);
  box-shadow: var(--elev-1);
}
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.panel {
  border-radius: 32px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  padding: 24px;
  backdrop-filter: blur(20px) saturate(1.12);
}
.panel-dash {
  background: rgba(255, 252, 248, 0.66);
  box-shadow: var(--elev-1);
}
.panel-chat {
  background: rgba(255, 252, 248, 0.9);
  box-shadow: var(--elev-3);
}
.panel-head { margin-bottom: 16px; }
.panel-head p { margin: 6px 0 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); gap: 8px; margin: 8px 0 16px; }
.apps { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 8px 0 16px; }
.stat, .app-card, .module, .msg, .record, .secret-box {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 8px 20px rgba(40, 32, 22, 0.05);
}
.stat { padding: 12px 14px; min-width: 0; }
.stat b {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat span, .muted { color: var(--muted); }
.app-card { padding: 14px; min-width: 180px; flex: 1; }
.app-card p { margin: 8px 0 0; }
.chart { margin: 8px 0 16px; }
.chart figcaption { font-weight: 600; margin-bottom: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 160px) 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}
.bar-track { height: 10px; background: var(--bg-deep); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--teal); border-radius: 999px; }
.bar-label, .bar-value { font-size: 0.875rem; }
.bar-value { font-variant-numeric: tabular-nums; }
.modules {
  display: grid;
  gap: 8px;
  max-height: 540px;
  overflow: auto;
  padding-right: 4px;
}
.module { padding: 14px; }
.module header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.module header strong { line-height: 1.35; min-width: 0; flex: 1; }
.module, .app-card, .stat { min-width: 0; }
.module .ghost { margin-top: 8px; }
.pill {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  background: var(--bg-deep);
  color: var(--ink);
  white-space: nowrap;
}
.pill.reached, .pill.connected { background: var(--good-soft); color: var(--good); }
.pill.partial { background: var(--amber-soft); color: var(--amber); }
.pill.unreachable, .pill.not_pulled, .pill.not_connected, .pill.not_supported {
  background: var(--rust-soft);
  color: var(--rust);
}
.module p { margin: 8px 0 0; color: var(--muted); }
.chat {
  display: flex;
  flex-direction: column;
  min-height: 70dvh;
}
.log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 12px;
  min-height: 180px;
}
.empty {
  margin: auto;
  text-align: center;
  max-width: 36rem;
  padding: 28px 8px;
  color: var(--muted);
}
.empty-title {
  margin: 0 0 6px;
  color: var(--ink);
  font-weight: 600;
}
.msg { padding: 14px 16px; max-width: min(720px, 100%); white-space: pre-wrap; }
.msg.user {
  align-self: flex-end;
  background: var(--teal);
  color: #f7fffe;
  border-color: transparent;
  border-radius: 22px 22px 8px 22px;
  box-shadow: 0 10px 24px rgba(13, 92, 89, 0.18);
}
.msg.assistant { align-self: flex-start; border-radius: 22px 22px 22px 8px; }
.msg.refused {
  border-color: #e4b4ae;
  background: #fdeceb;
  color: #5c241c;
}
.msg .who {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: 0.8;
}
.msg .chart, .msg .record { color: var(--ink); background: var(--card-solid); }
.records { display: grid; gap: 8px; margin-top: 12px; }
.record { padding: 12px 14px; }
.record h3 { font-size: 1.05rem; }
dl { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; gap: 6px 12px; margin: 8px 0 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.composer {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 10;
  margin-top: 8px;
  background: rgba(255, 252, 248, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 24px;
  padding: 12px;
  box-shadow: var(--elev-2);
  backdrop-filter: blur(18px);
}
.composer:focus-within {
  border-color: rgba(13, 92, 89, 0.35);
  box-shadow: var(--elev-3);
}
.composer form { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.composer .primary { min-width: 88px; }
.composer label { margin-bottom: 0; }
#prompts { margin-bottom: 8px; }
#prompts .ghost {
  display: inline-flex;
  align-items: center;
  text-align: left;
  background: rgba(255, 255, 255, 0.7);
}
.admin-grid {
  display: grid;
  gap: 20px;
}
.admin-grid > .card { width: auto; }
.span-2 { grid-column: 1 / -1; }
.secret-box { padding: 16px; margin-top: 8px; }
.advanced {
  margin-top: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.admin-grid .card code, .card code {
  font-size: 0.9em;
  background: var(--bg-deep);
  padding: 1px 6px;
  border-radius: 6px;
}
.cred-status {
  margin: 0 0 16px;
  padding: 14px 16px;
  background: var(--teal-soft);
  border-radius: 18px;
  grid-template-columns: minmax(120px, 150px) 1fr;
}
.cred-status dd {
  word-break: break-all;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
#pull { margin: 4px 0 16px; }
#customers { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 520px; }
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table th { font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.modules, .log { scrollbar-width: thin; scrollbar-color: rgba(60, 48, 32, 0.28) transparent; }

@media (prefers-reduced-motion: no-preference) {
  .msg { animation: rise 200ms ease-out; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 901px) {
  #shell:not([hidden]):has(.layout) {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  #shell:has(.layout) .stage {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 16px;
  }
  #shell:has(.layout) .layout {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }
  .panel-dash, .panel-chat {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .panel-chat {
    position: static;
    height: auto;
    max-height: none;
    min-height: 0;
  }
  .panel-dash #dashboard {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .panel-dash .modules { max-height: none; }
  .log { min-height: 0; overflow: auto; }
  .panel-chat .composer { position: static; }
}
@media (min-width: 1100px) {
  .admin-grid { grid-template-columns: 1.15fr 0.85fr; }
}
@media (max-width: 900px) {
  .top, .stage { width: min(1180px, calc(100% - 20px)); }
  .layout { grid-template-columns: 1fr; }
  .panel-chat { order: -1; min-height: auto; height: auto; position: static; }
  .chat { min-height: auto; }
  .log { overflow: visible; }
  .modules { max-height: none; }
  .composer form { grid-template-columns: 1fr; }
  .composer .primary { width: 100%; }
  .panel { padding: 16px; border-radius: 24px; }
  dl, .cred-status { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  #prompts { flex-direction: column; align-items: stretch; }
  #prompts .ghost { width: 100%; }
  h1 { font-size: 1.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  button:active:not(:disabled) { transform: none; }
}
