/* NormanMax demo chat UI — dark ops-console, Provectus tokens */

:root {
  --bg: #14161f;
  --surface: #1c1f2e;
  --surface-raised: #21243372;
  --border: #2a2d3a;
  --text: #e8e6e1;
  --text-dim: #8a8f9e;
  --accent: #7fa892;
  --accent-hover: #93b8a4;
  --amber: #d9a441;
  --decline-border: #8a8f9e;
  --error: #c2705c;
  --text-mid: #b7bcc7;

  --radius: 6px;
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;
  --sp-4: 40px;

  --font-ui: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: var(--font-ui);
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  animation: fade-up 0.4s ease-out both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.app-header .title-block {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}

.app-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.app-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.status-dot-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.status-dot.streaming {
  background: var(--amber);
  animation: pulse-dot 1.1s ease-in-out infinite;
}

.status-dot.error {
  background: var(--error);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

@media (max-width: 480px) {
  .btn-label { display: none; }
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- Layout: transcript + drawer ---------- */

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.transcript-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

#transcript {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}

.transcript-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.empty-state {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: var(--sp-4) 0;
}

.empty-hint {
  margin: 0 0 var(--sp-2);
}

.suggested-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* ---------- Messages ---------- */

.turn { display: flex; flex-direction: column; }

.msg-user {
  align-self: flex-end;
  max-width: 78%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-agent {
  width: 100%;
  border-left: 2px solid transparent;
  padding-left: var(--sp-2);
}

.msg-agent[data-status="declined"] {
  border-left-color: var(--decline-border);
}

.msg-agent[data-status="error"] {
  border-left-color: var(--error);
}

.working-cue {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-1);
}

.working-cue .dots span {
  display: inline-block;
  opacity: 0.25;
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.working-cue .dots span:nth-child(2) { animation-delay: 0.2s; }
.working-cue .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.25; }
  30% { opacity: 1; }
}

.tool-skeleton { padding: 2px 0; margin-bottom: var(--sp-2); }
.skeleton-bar {
  display: block;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.95; }
}

/* ---------- Tool call cards ---------- */

.tool-calls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--sp-2);
}

.tool-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.tool-card-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: left;
}

.tool-card-header:hover { color: var(--accent-hover); }

.tool-glyph { color: var(--text-dim); }
.tool-card[data-state="done"] .tool-glyph { color: var(--accent); }
.tool-card[data-state="error"] .tool-glyph { color: var(--error); }

.tool-name { font-weight: 600; }
.tool-status { color: var(--text-dim); margin-left: auto; }
.tool-card[data-state="error"] .tool-status { color: var(--error); }

.tool-card-body {
  border-top: 1px solid var(--border);
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-card-body.hidden { display: none; }

.tool-io-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.tool-io {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-1);
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Answer + charts ---------- */

.answer-content {
  font-size: 14.5px;
}

.answer-content p:first-child { margin-top: 0; }
.answer-content pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.answer-content code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
}
.answer-content table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}
.answer-content th, .answer-content td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}

.charts { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-2); }
.chart-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--sp-2);
  height: 260px;
}

/* ---------- Verification + badges ---------- */

.verification-strip {
  margin-top: var(--sp-2);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-hover);
  background: rgba(127, 168, 146, 0.12);
  border: 1px solid rgba(127, 168, 146, 0.35);
  border-radius: var(--radius);
  padding: 6px 12px;
  width: fit-content;
}

.verification-strip .check-icon { color: var(--accent); font-weight: 700; }
.verification-strip button.toggle-checks {
  background: none;
  border: none;
  color: var(--accent-hover);
  text-decoration: underline;
  font-size: 12px;
  font-weight: 500;
  padding: 0;
}

.checks-list {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: var(--sp-1) var(--sp-2);
}
.checks-list.hidden { display: none; }
.check-row { display: flex; gap: 8px; padding: 3px 0; }
.check-row .check-status-pass { color: var(--accent); }
.check-row .check-status-fail { color: var(--error); }
.check-row .check-status-skip { color: var(--text-dim); }

.not-vetted-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--sp-1);
  border: 1px solid var(--amber);
  color: var(--amber);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: fit-content;
}

/* ---------- Turn footer ---------- */

.turn-footer {
  margin-top: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11.5px;
}

/* Single-line action row: trace id · latency · spacer · thumbs · pencil.
   flex-wrap:nowrap is deliberate — items never wrap or reorder onto a second
   line; overflow-x is the narrow-viewport safety valve instead of a wrap. */
.footer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  color: var(--text-mid);
}

.footer-spacer { flex: 1 1 auto; }

.footer-latency {
  font-family: var(--font-mono);
  color: var(--text-mid);
  white-space: nowrap;
}

.trace-link {
  font-family: var(--font-mono);
  background: none;
  border: none;
  border-bottom: 1px dotted currentColor;
  padding: 0 0 2px;
  color: var(--text-mid);
  white-space: nowrap;
  flex-shrink: 0;
}
.trace-link:hover { color: var(--accent-hover); }

.fb-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid transparent;
  color: var(--text-mid);
  padding: 2px 6px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1;
}
.fb-btn:hover { border-color: var(--border); color: var(--text); }
.fb-btn.active { color: var(--accent); border-color: var(--border); }

.fb-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-1) var(--sp-2);
  background: var(--surface);
}
.fb-form.hidden { display: none; }

.fb-form textarea {
  width: 100%;
  min-height: 56px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 6px 8px;
}

.fb-attach-row { display: flex; align-items: center; }
.fb-attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mid);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 11px;
}
.fb-attach-btn:hover { border-color: var(--accent); color: var(--accent-hover); }
.fb-file-input { display: none; }

.fb-attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.fb-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-mid);
  background: var(--bg);
}
.fb-attach-chip-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  padding: 0 4px;
}
.fb-attach-chip-remove:hover { color: var(--error); }

.fb-attach-error {
  font-size: 11px;
  color: var(--error);
}
.fb-attach-error.hidden { display: none; }

.fb-form .fb-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  white-space: pre-wrap;
  border-left: 2px solid var(--border);
  padding-left: 6px;
}

.fb-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.fb-success {
  font-size: 11.5px;
  color: var(--accent);
}
.fb-success a { color: var(--accent-hover); }

/* ---------- Selection feedback popover ---------- */

#selection-popover {
  position: fixed;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  padding: 4px;
  display: none;
  max-width: calc(100vw - 16px);
}
#selection-popover.visible { display: block; }

#selection-popover::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  left: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
  bottom: -5px;
}
#selection-popover.caret-below::after {
  bottom: auto;
  top: -5px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-right: none;
}

#selection-popover button {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 4px;
}
#selection-popover button:hover { background: var(--bg); color: var(--accent-hover); }

#selection-feedback-panel {
  position: fixed;
  z-index: 41;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  padding: var(--sp-2);
  display: none;
}
#selection-feedback-panel.visible { display: block; }

/* ---------- Input bar ---------- */

.input-bar {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: var(--sp-2) var(--sp-3);
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.input-inner {
  width: 100%;
  max-width: 860px;
  display: flex;
  gap: var(--sp-1);
  align-items: flex-end;
  min-width: 0;
}

#chat-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 10px 12px;
  max-height: 160px;
}
#chat-input:focus {
  outline: none;
  border-color: var(--accent);
}

.send-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #10130f;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 13px;
}
.send-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

/* Width starts at 0 and is only ever reserved from the flex layout while
   .open — this is what keeps the main pane full-bleed at rest and removes
   the permanent seam; it only shifts when the drawer is actually shown. */
#audit-drawer {
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  border-left: 0 solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.22s ease, border-left-width 0.22s ease;
}
#audit-drawer.open {
  width: 380px;
  border-left-width: 1px;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-copy {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mid);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 8px;
  white-space: nowrap;
}
.drawer-copy:hover { border-color: var(--accent); color: var(--accent-hover); }
.drawer-copy.copied { border-color: var(--accent); color: var(--accent); }

.drawer-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
}
.drawer-close:hover { color: var(--text); }

.drawer-body {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.drawer-answer-block {
  padding: var(--sp-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-answer-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-mid);
  margin-bottom: 6px;
}
.drawer-answer-md { font-size: 13px; }

#audit-json {
  margin: 0;
  padding: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: normal;
}
/* Only genuinely unbroken runs (hashes, tokens, long unspaced SQL) force-break
   — everything else wraps naturally at spaces, which is what keeps the JSON's
   structural indentation intact instead of being mangled mid-line. */
.long-token {
  word-break: break-all;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  #audit-drawer {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
  }
  #audit-drawer.open { transform: translateY(0); }
}

@media (max-width: 480px) {
  .app-header { padding: var(--sp-1) var(--sp-2); }
  .app-title { font-size: 14px; }
  #transcript { padding: var(--sp-2); }
  .input-bar { padding: var(--sp-1) var(--sp-2); }
  .msg-user { max-width: 90%; }
  .app-subtitle { display: none; }
}

/* ---------- Login page ---------- */

.login-body {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-shell {
  width: 100%;
  max-width: 380px;
  padding: var(--sp-3);
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-3);
  animation: fade-up 0.4s ease-out both;
}

.login-header {
  text-align: center;
  margin-bottom: var(--sp-1);
}

.login-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.login-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-top: 4px;
}

.login-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mid);
}

.login-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 10px 12px;
}
.login-input:focus { outline: none; border-color: var(--accent); }

.login-submit { width: 100%; justify-content: center; }

.login-error {
  font-size: 12.5px;
  color: var(--error);
  text-align: center;
}
.login-error.hidden { display: none; }
