/* Netra AI console — instrument-bench identity.
   Palette: slate bench + the four pipeline stages as the accent system.
   splitter #5EC8F2 · deepcrush #B48AF2 · autogram #F2A65E · replicator #58D68A */

:root {
  --bg: #0e141a;
  --panel: #141c24;
  --panel-2: #1a242d;
  --line: #24313c;
  --line-soft: #1d2831;
  --ink: #e8f0ee;
  --dim: #8ba0a0;
  --dimmer: #5f7377;
  --teal: #35d0ba;
  --danger: #f27e6b;
  --stage-split: #5ec8f2;
  --stage-crush: #b48af2;
  --stage-gram: #f2a65e;
  --stage-rep: #58d68a;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Space Grotesk", var(--sans);
  --radius: 9px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
::selection { background: rgba(53, 208, 186, 0.25); }

.wordmark { font-family: var(--display); font-weight: 700; font-size: 27px; letter-spacing: -0.02em; }
.wordmark .tick { color: var(--teal); }
.wordmark.small { font-size: 18px; }
.dim { color: var(--dim); }

/* ---- auth gate ---- */
.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(60vw 45vh at 82% 8%, rgba(53, 208, 186, 0.08), transparent 60%),
    radial-gradient(50vw 40vh at 12% 96%, rgba(180, 138, 242, 0.06), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(390px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.auth-sub { color: var(--dim); margin: 8px 0 24px; font-size: 13.5px; line-height: 1.6; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin: 12px 0 0; }

/* ---- buttons ---- */
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, filter 0.12s;
}
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #06231e; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: rgba(242, 126, 107, 0.4); }
.btn.ghost { background: none; border: none; color: var(--dim); padding: 4px 6px; }
.btn.ghost:hover { color: var(--ink); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: default; filter: none; }

/* The sign-in control is our own button now (the API owns the OAuth redirect),
   so this container only has to reserve the same slot the GIS iframe used to
   occupy — the card's proportions are unchanged. */
.auth-actions { display: flex; justify-content: center; min-height: 44px; }

/* ---- console layout ---- */
.console { display: grid; grid-template-columns: 260px 1fr 300px; height: 100vh; }
@media (max-width: 1040px) { .console { grid-template-columns: 220px 1fr; } .ops { display: none; } }

/* sidebar */
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 12px;
  min-width: 0;
}
.sidebar-head { padding: 2px 4px 6px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.conv-empty { padding: 8px 10px; font-size: 12.5px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  text-align: left; background: none; border: none;
  border-radius: 7px; padding: 8px 10px; cursor: pointer;
  color: var(--dim); width: 100%; min-width: 0;
  border-left: 2px solid transparent;
}
.conv-item:hover { background: var(--panel-2); color: var(--ink); }
.conv-item.active { background: var(--panel-2); color: var(--ink); border-left-color: var(--teal); }
.conv-item .st { flex: none; font-size: 10px; }
.conv-item .st-active { color: var(--stage-rep); }
.conv-item .st-creating { color: var(--stage-gram); }
.conv-item .st-expired { color: var(--dimmer); }
.conv-item .st-failed, .conv-item .st-deleted { color: var(--danger); }
.conv-item-id { font-family: var(--mono); font-size: 12px; }
.conv-item-tenant {
  margin-left: auto; font-size: 10px; color: var(--dimmer);
  font-family: var(--mono); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 90px;
}
.creating-item { color: var(--stage-gram); }

/* Bottom-left credential signal: whether the delegated Google refresh token is
   in place. Not-connected is a warning state with a real call to action — the
   old subtle ghost button let users miss the one step netra ops depend on. */
.google-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  border: 1px solid rgba(240, 179, 91, 0.55); border-radius: 8px;
  padding: 9px 10px; background: var(--panel-2);
}
.google-card.connected { border-color: var(--line); }
.google-dot { width: 8px; height: 8px; border-radius: 50%; background: #f0b35b; box-shadow: 0 0 8px rgba(240, 179, 91, 0.5); flex: none; }
.google-card.connected .google-dot { background: var(--stage-rep); box-shadow: 0 0 8px rgba(88, 214, 138, 0.5); }
.google-label { font-size: 11.5px; color: var(--dim); flex: 1 1 auto; min-width: 0; }
.google-card.connected .google-label { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.google-connect {
  flex: 1 0 100%; text-align: center; font-size: 12px; font-weight: 600;
  color: #0b1114; background: var(--teal); border-radius: 7px; padding: 7px 10px;
}
.google-connect:hover { background: var(--teal); filter: brightness(1.12); }

.sidebar-foot {
  border-top: 1px solid var(--line); padding-top: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.user-email { font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat column */
.chat { display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
}
.conv-title { font-family: var(--display); font-size: 17px; font-weight: 600; margin: 0; }
.conv-meta { display: flex; align-items: center; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.conv-id { font-family: var(--mono); font-size: 11px; color: var(--dimmer); }
.conv-tenant {
  font-family: var(--mono); font-size: 11px; color: var(--stage-split);
  border: 1px solid rgba(94, 200, 242, 0.3); border-radius: 5px; padding: 1px 7px;
}
.chat-head-actions { display: flex; gap: 8px; }

.status-chip { font-family: var(--mono); font-size: 11px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--dim); }
.status-chip.active { color: var(--stage-rep); border-color: rgba(88, 214, 138, 0.4); }
.status-chip.creating { color: var(--stage-gram); border-color: rgba(242, 166, 94, 0.4); }
.status-chip.expired { color: var(--dim); }
.status-chip.failed, .status-chip.deleted { color: var(--danger); border-color: rgba(242, 126, 107, 0.4); }

.banner {
  margin: 12px 22px 0; padding: 10px 14px; border-radius: 8px;
  border: 1px solid rgba(242, 166, 94, 0.4); background: rgba(242, 166, 94, 0.08);
  color: var(--stage-gram); font-size: 13.5px;
}
.banner.error { border-color: rgba(242, 126, 107, 0.45); background: rgba(242, 126, 107, 0.08); color: var(--danger); }

.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; text-align: center; max-width: 40ch; }
.empty-mark { font-family: var(--display); font-weight: 700; font-size: 30px; letter-spacing: -0.02em; margin-bottom: 10px; }
.empty-mark .tick { color: var(--teal); }

.msg { max-width: 74ch; animation: rise 0.16s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg .who { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); margin-bottom: 5px; }
.msg .body { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 10px 14px; white-space: normal; overflow-wrap: break-word; }
.msg.user { align-self: flex-end; }
.msg.user .who { text-align: right; }
.msg.user .body { background: rgba(53, 208, 186, 0.1); border-color: rgba(53, 208, 186, 0.32); }

/* markdown-rendered message bodies */
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 8px; }
.msg .body ul, .msg .body ol { margin: 0 0 8px; padding-left: 22px; }
.msg .body li { margin: 2px 0; }
.msg .body li::marker { color: var(--dim); }
.msg .body h1, .msg .body h2, .msg .body h3, .msg .body h4, .msg .body h5, .msg .body h6 {
  margin: 12px 0 6px; font-family: var(--display); font-weight: 600; line-height: 1.25;
}
.msg .body h1 { font-size: 1.28em; }
.msg .body h2 { font-size: 1.18em; }
.msg .body h3 { font-size: 1.07em; }
.msg .body h4, .msg .body h5, .msg .body h6 { font-size: 1em; color: var(--dim); }
.msg .body strong { font-weight: 600; color: var(--ink); }
.msg .body em { font-style: italic; }
.msg .body a { color: var(--teal); text-decoration: underline; }
.msg .body code {
  font-family: var(--mono); font-size: 0.86em; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.msg .body pre.md-code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 0 0 8px; overflow-x: auto;
}
.msg .body pre.md-code code { background: none; border: 0; padding: 0; font-size: 12px; line-height: 1.5; white-space: pre; }
.msg .body blockquote.md-bq { margin: 0 0 8px; padding: 2px 0 2px 12px; border-left: 3px solid var(--line); color: var(--dim); }

.tool-chip {
  display: inline-block; font-family: var(--mono); font-size: 11.5px; color: var(--stage-split);
  border: 1px dashed rgba(94, 200, 242, 0.45); border-radius: 6px; padding: 3px 8px; margin: 2px 0;
}

/* continuation note when the agent resumes after a detached op finishes */
.system-note {
  align-self: center; max-width: 60ch; text-align: center;
  font-family: var(--mono); font-size: 11px; color: var(--dimmer);
  border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line);
  padding: 6px 0; margin: 2px 0;
}

/* creating panel */
.creating-panel { margin: auto; text-align: center; max-width: 44ch; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.creating-title { font-family: var(--display); font-weight: 600; font-size: 20px; margin: 6px 0 2px; }
.spinner-lg { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--teal); animation: spin 0.9s linear infinite; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--stage-gram); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .spinner-lg { animation: none; } }

.composer { display: flex; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid var(--line); }
.composer textarea {
  flex: 1; resize: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 11px 13px; max-height: 30vh; line-height: 1.5;
}
.composer textarea:focus { border-color: rgba(53, 208, 186, 0.5); outline: none; }

/* ops rail */
.ops { border-left: 1px solid var(--line); background: var(--panel); padding: 16px 14px; overflow-y: auto; }
.ops-title { font-family: var(--display); font-size: 14px; font-weight: 600; margin: 0; }
.ops-sub { color: var(--dim); font-size: 12px; margin: 4px 0 14px; }
.ops-list { display: flex; flex-direction: column; gap: 10px; }
.op-card { border: 1px solid var(--line); border-left: 3px solid var(--dimmer); border-radius: 8px; background: var(--panel-2); padding: 10px 12px; font-size: 12.5px; animation: rise 0.16s ease-out; }
.op-card.running { border-left-color: var(--stage-gram); }
.op-card.completed { border-left-color: var(--stage-rep); }
.op-card.failed, .op-card.timed_out, .op-card.aborted, .op-card.cancelled { border-left-color: var(--danger); }
.op-card .op-cmd { font-family: var(--mono); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-card .op-row { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; color: var(--dim); font-family: var(--mono); font-size: 10.5px; }
.op-card .op-log { margin-top: 8px; max-height: 90px; overflow: hidden; font-family: var(--mono); font-size: 10px; line-height: 1.45; color: var(--dim); white-space: pre-wrap; border-top: 1px dashed var(--line); padding-top: 6px; }
.op-cancel { margin-left: 8px; }

/* dialog */
.dialog-scrim { position: fixed; inset: 0; background: rgba(4, 8, 10, 0.6); display: grid; place-items: center; z-index: 50; animation: fade 0.12s ease-out; }
@keyframes fade { from { opacity: 0; } }
.dialog { width: min(440px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5); }
.dialog-title { font-family: var(--display); font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.dialog-sub { font-size: 13px; margin: 0 0 18px; line-height: 1.55; }
.field-label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.field-select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 10px 11px; cursor: pointer; }
.field-select:focus { border-color: rgba(53, 208, 186, 0.5); outline: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 10px 16px; font-size: 13.5px; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45); z-index: 60; animation: rise 0.16s ease-out; }
.toast.error { border-color: rgba(242, 126, 107, 0.5); color: var(--danger); }
