/* Jarvis PWA — instrument console
   Palette: void #060A12 · panel #0B1220 · line #1B2A41 · ice #9BE8FF · ember #FFB454
   Type: Rajdhani (display/labels) · IBM Plex Mono (data) · system sans (chat) */

:root {
  --void: #060a12;
  --panel: #0b1220;
  --panel-2: #0e1729;
  --line: #1b2a41;
  --line-soft: #14213466;
  --ice: #9be8ff;
  --ice-dim: #9be8ff99;
  --ember: #ffb454;
  --danger: #ff6b6b;
  --text: #e6eef7;
  --muted: #8da3bc;
  --display: "Rajdhani", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 70% -10%, #0d1b3a55 0%, transparent 60%),
    radial-gradient(900px 500px at 10% 110%, #07254033 0%, transparent 55%),
    var(--void);
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0b1220ee, #0b1220aa);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.ident {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.42em;
  margin: 0;
  color: var(--text);
  text-shadow: 0 0 18px #9be8ff33;
}

.ident-sub {
  font-family: var(--display);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--muted);
  white-space: nowrap;
}

.lamp {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  align-self: center;
  flex: none;
  background: var(--ice);
  box-shadow: 0 0 10px var(--ice), 0 0 26px #9be8ff66;
}

body[data-link="linking"] .lamp {
  background: var(--ember);
  box-shadow: 0 0 10px var(--ember);
  animation: breathe 1.1s ease-in-out infinite;
}

body[data-link="down"] .lamp {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
  animation: none;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.72); opacity: 0.55; }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.readout {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ice-dim);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

body[data-link="down"] .readout { color: var(--danger); }
body[data-link="linking"] .readout { color: var(--ember); }

.iconbtn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  transition: color 120ms, border-color 120ms;
}

.iconbtn:hover { color: var(--ice); border-color: var(--ice-dim); }

/* signature: the sweep — fires on every successful bridge call */
.sweep {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 1px;
  width: 100%;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--ice), transparent);
  background-size: 36% 100%;
  background-repeat: no-repeat;
  background-position: -40% 0;
  opacity: 0;
}

.sweep.run { animation: sweep 480ms ease-out 1; }

@keyframes sweep {
  0% { opacity: 1; background-position: -40% 0; }
  100% { opacity: 0; background-position: 140% 0; }
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--line-soft);
}

.tabs button {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 8px 14px 10px;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  color: var(--ice);
  border-bottom-color: var(--ice);
}

/* ---------- views ---------- */

.view { flex: 1; min-height: 0; display: none; }
body[data-view="chat"] .view-chat { display: flex; flex-direction: column; }
body[data-view="ops"] .view-ops { display: block; overflow-y: auto; }

/* ---------- chat ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.msg-jarvis { justify-content: flex-start; }

.msg-body {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-user .msg-body {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
}

.msg-jarvis .msg-body {
  background: linear-gradient(180deg, #0c1730, #0b1220);
  border: 1px solid var(--line);
  border-left: 2px solid var(--ice);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  box-shadow: 0 0 24px #9be8ff0d;
}

.sysnote {
  align-self: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  max-width: 92%;
  text-align: center;
}

.sysnote-err { color: var(--ember); border-color: #ffb45455; }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: linear-gradient(0deg, #0b1220f2, #0b1220cc);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.composer textarea {
  flex: 1;
  resize: none;
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  padding: 11px 13px;
  min-height: 44px;
  max-height: 140px;
}

.composer textarea::placeholder { color: #5d7390; }

.btn-send {
  appearance: none;
  border: 1px solid var(--ice-dim);
  background: linear-gradient(180deg, #11304a, #0b2236);
  color: var(--ice);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border-radius: var(--radius);
  padding: 0 18px;
  height: 44px;
  cursor: pointer;
  transition: box-shadow 120ms;
}

.btn-send:hover:not(:disabled) { box-shadow: 0 0 16px #9be8ff33; }
.btn-send:disabled { opacity: 0.45; cursor: default; }

/* ---------- ops ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  padding: 16px;
  max-width: 1000px;
  margin: 0 auto;
}

.card {
  background: linear-gradient(180deg, #0d182cdd, #0b1220dd);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px 16px;
  box-shadow: inset 0 1px 0 #ffffff08;
}

.card-wide { grid-column: 1 / -1; }

.card-title {
  margin: 0 0 10px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ice);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
}

.kv { margin: 0; display: grid; gap: 7px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-list { display: flex; flex-direction: column; gap: 8px; }

.tool-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 12px;
}

.tool-meta { min-width: 0; flex: 1; }

.tool-name {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ice);
}

.tool-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.btn-run {
  appearance: none;
  flex: none;
  background: transparent;
  border: 1px solid var(--ember);
  color: var(--ember);
  font-family: var(--display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}

.btn-run:hover:not(:disabled) { background: #ffb4541a; }
.btn-run:disabled { opacity: 0.4; }

.feed { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }

.feed-row {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 10px;
}

.feed-err { color: var(--ember); border-left-color: var(--ember); }

.feed-row details { margin-top: 4px; }
.feed-row summary { cursor: pointer; color: var(--ice-dim); font-size: 11px; }
.feed-row pre {
  margin: 6px 0 2px;
  padding: 8px 10px;
  background: var(--void);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11.5px;
  color: var(--text);
}

.feed-empty { font-family: var(--mono); font-size: 12px; color: #5d7390; padding: 4px 0; }

/* ---------- drawer ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: #02040adb;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms;
  z-index: 40;
}

.scrim.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(380px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: calc(16px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateX(102%);
  transition: transform 200ms ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.drawer.open { transform: translateX(0); }

.drawer-head { display: flex; align-items: center; justify-content: space-between; }

.drawer-head h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text);
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field > span {
  font-family: var(--display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field select {
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px 12px;
}

.field small { color: #5d7390; font-size: 11.5px; line-height: 1.45; }
.field code { color: var(--ice-dim); }

.btn-primary {
  appearance: none;
  border: 1px solid var(--ice-dim);
  background: linear-gradient(180deg, #11304a, #0b2236);
  color: var(--ice);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  margin-top: 4px;
}

.btn-primary:hover { box-shadow: 0 0 16px #9be8ff33; }

/* ---------- a11y + polish ---------- */

:focus-visible {
  outline: 2px solid var(--ice);
  outline-offset: 2px;
  border-radius: 6px;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 480px) {
  .ident-sub { display: none; }
  .wordmark { font-size: 17px; letter-spacing: 0.34em; }
  .msg-body { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .lamp, .sweep { animation: none !important; }
  .drawer, .scrim { transition: none; }
}
