/* selfievo-ui · v0.3.0
   Customer-facing chat surface with terminal-grade ergonomics.
   Dark-theme palette + Inter Tight + Space Grotesk headings + JetBrains
   Mono for composer/code. Three breakpoints:
     ≥1024px — two-pane side-by-side (chat 3fr / render 2fr)
      768px–1023px — two-pane stacked
     <768px  — single-pane with tab switcher (CSS-only via :has() radios)
*/

:root {
  --bg: #0a0a0f;
  --fg: #e8e8ed;
  --muted: #7a7a8e;
  --card: #14141c;
  --rule: #1f1f2a;
  --accent: #4285F4;
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --user: #94c590;
  --assistant: #c2b89f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter Tight", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* When .session is in body, take full viewport (no centering). */
body:has(.session) {
  display: block;
  align-items: stretch;
  justify-content: stretch;
}

/* ---------- Landing / sign-in ---------- */

.login-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  max-width: 420px;
  padding: 2rem;
}

.login-logo img { height: 72px; }

.login-title {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
}

.login-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.login-error {
  color: var(--error);
  font-size: 0.85rem;
  background: var(--error-bg);
  padding: 0.5rem 1rem;
  border-radius: 8px;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  background: #fff;
  color: #333;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: box-shadow 0.2s;
}

.google-btn:hover {
  box-shadow: 0 2px 12px rgba(255, 255, 255, 0.15);
}

.google-btn svg { width: 20px; height: 20px; }

/* ---------- Customers picker (placeholder for v0.2) ---------- */

main { padding: 16px; }

.customers     { max-width: 540px; margin: 80px auto; padding: 0 1rem; }
.customers h1  { font-family: "Space Grotesk", system-ui, sans-serif; font-size: 1.4rem; margin-bottom: 1.5rem; }
.customers-header {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 2rem; padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}
.signed-in    { color: var(--muted); font-size: 0.9rem; flex: 1; }
.logout-link  { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.logout-link:hover { text-decoration: underline; }
.customer-list { list-style: none; padding: 0; }
.customer-list li { margin-bottom: 0.5rem; }
.customer-btn  {
  width: 100%; padding: 14px 16px; text-align: left;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--rule); border-radius: 8px;
  cursor: pointer; font: inherit;
  font-family: "Space Grotesk", system-ui, sans-serif;
  transition: border-color 0.15s, background 0.15s;
}
.customer-btn:hover { border-color: var(--accent); background: var(--rule); }
.customers-empty {
  color: var(--muted); font-size: 0.9rem;
  background: var(--card); padding: 1rem;
  border-radius: 8px; line-height: 1.6;
}
.customers-empty code { color: var(--fg); background: var(--rule); padding: 1px 4px; border-radius: 3px; }
.customers-empty a { color: var(--accent); }

/* ---------- Feedback buttons (legacy — used by render_card.html partial) ---------- */

.feedback-buttons { display: flex; gap: 8px; margin-top: 10px; }
.feedback-buttons button { padding: 6px 12px; border: 0; cursor: pointer; border-radius: 4px; font: inherit; }
.btn-apply  { background: var(--user);     color: var(--bg); }
.btn-reject { background: var(--error);    color: #fff; }
.btn-replan { background: var(--muted);    color: var(--bg); }

/* ---------- v0.3.0: Session two-pane chat surface ---------- */

.session-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
  flex-wrap: wrap;
}

.customer-badge {
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
}

.sid {
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
}

.status-pill {
  background: var(--rule);
  color: var(--muted);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.cost-badge {
  margin-left: auto;
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 2px 10px;
  background: var(--rule);
  border-radius: 4px;
}

.end-session-form { margin: 0; }
.end-session-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.end-session-btn:hover { color: var(--error); border-color: var(--error); }

/* ---------- Pane tabs (mobile only — visible <768px) ---------- */

.pane-tabs {
  display: none;
  gap: 4px;
}
.pane-tab {
  background: var(--rule);
  color: var(--muted);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
#pane-chat-radio:checked ~ main .pane-tab[for="pane-chat-radio"],
#pane-render-radio:checked ~ main .pane-tab[for="pane-render-radio"] {
  background: var(--accent);
  color: #fff;
}

/* ---------- Layout: ≥1024px two-pane ---------- */

.session {
  display: grid;
  grid-template-columns: 3fr 2fr;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  width: 100%;
}
.session > .session-header,
.session > .composer {
  grid-column: 1 / -1;
}

.pane {
  overflow-y: auto;
  padding: 16px;
}
.pane-chat { border-right: 1px solid var(--rule); }

.render-empty {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
  font-style: italic;
}

/* ---------- Streaming chat bubbles ---------- */

.chat-message {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: 8px;
  border-left: 3px solid var(--rule);
}
.chat-user      { border-left-color: var(--user); }
.chat-assistant { border-left-color: var(--assistant); }
.chat-message[aria-busy="true"]::after {
  content: "▋";
  color: var(--accent);
  animation: blink 1s step-end infinite;
  margin-left: 2px;
}
@keyframes blink {
  50% { opacity: 0; }
}
.chat-token { display: inline; }
.chat-role {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.chat-body { margin-top: 6px; white-space: pre-wrap; }

/* ---------- Tool use / result cards ---------- */

.tool-use {
  margin: 10px 0;
  padding: 8px 12px;
  background: var(--rule);
  border-radius: 6px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  border-left: 3px solid var(--accent);
}

.tool-result {
  margin: 8px 0;
}
.tool-result summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}
.tool-result-error summary { color: var(--error); }
.tool-result pre {
  background: var(--rule);
  padding: 10px;
  margin-top: 6px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

/* ---------- Render cards (right pane) ---------- */

.render-card {
  margin-bottom: 16px;
  padding: 14px;
  background: var(--card);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.render-card header {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: baseline;
}
.render-verb {
  color: var(--accent);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.1em;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-weight: 600;
}
.render-target {
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
}
.render-diff {
  background: var(--bg);
  padding: 10px;
  border-radius: 4px;
  overflow-x: auto;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.render-diff del { background: rgba(239, 68, 68, 0.15); text-decoration: line-through; color: #f59191; }
.render-diff ins { background: rgba(148, 197, 144, 0.15); text-decoration: underline; color: var(--user); }

/* ---------- Error card ---------- */

.error-card {
  margin: 12px 0;
  padding: 10px 14px;
  background: var(--error-bg);
  border-left: 3px solid var(--error);
  border-radius: 6px;
  color: var(--error);
}

/* ---------- Composer ---------- */

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
  background: var(--card);
  position: relative;
}
.composer textarea {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 40px;
  max-height: 200px;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.composer-send {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
}
.composer-send:hover { filter: brightness(1.1); }

/* ---------- Completions dropdown ---------- */

.completions-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 16px;
  right: 16px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  list-style: none;
  padding: 4px 0;
  margin: 0;
  z-index: 10;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}
.completion-item {
  padding: 6px 12px;
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
}
.completion-item:hover, .completion-item.active {
  background: var(--rule);
}
.completion-item.active { color: var(--accent); }
.c-label { font-weight: 500; }
.c-desc {
  color: var(--muted);
  font-family: "Inter Tight", system-ui, sans-serif;
  font-size: 12px;
}

/* ---------- Responsive: 768–1023px stacked panes ---------- */

@media (max-width: 1023px) {
  .session {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1fr auto;
  }
  .pane-chat {
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }
}

/* ---------- Responsive: <768px tabbed single-pane ---------- */

@media (max-width: 767px) {
  .session {
    grid-template-rows: auto 1fr auto;
  }
  .pane-tabs { display: flex; }
  /* Default: chat visible. */
  .pane-render { display: none; }
  /* When render radio is checked, swap. */
  body:has(#pane-render-radio:checked) .pane-chat { display: none; }
  body:has(#pane-render-radio:checked) .pane-render { display: block; }

  .session-header { gap: 8px; padding: 6px 10px; }
  .cost-badge { margin-left: 0; }
  .composer { padding: 8px 10px; }
}

/* ---------- v0.3.2: Thinking-state pulse ---------- */

.chat-thinking::before {
  content: "thinking";
  display: inline-block;
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: 0.1em;
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: "thinking"; }
  25%  { content: "thinking."; }
  50%  { content: "thinking.."; }
  75%  { content: "thinking..."; }
  100% { content: "thinking"; }
}
.chat-thinking .chat-body { display: none; }
.chat-thinking[aria-busy="false"]::before { display: none; }
.chat-thinking[aria-busy="false"] .chat-body { display: block; }
