/* style.css — chat.prim.sh */

/* ── Reset + Tokens ─────────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --surface: #111;
  --surface-2: #161616;
  --surface-3: #1a1a1a;
  --border: #1e1e1e;
  --text: #e0e0e0;
  --text-dim: #aaa;
  --muted: #666;
  --accent: #00ff88;
  --accent-dim: #00cc6a;
  --accent-glow: rgba(0, 255, 136, 0.08);
  --user-bg: #1a2a1f;
  --user-border: #1e3a25;
  --font: "SF Mono", SFMono-Regular, "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 280px;
  --header-h: 52px;
  --input-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.screen {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen[hidden] {
  display: none !important;
}

.accent {
  color: var(--accent);
}

/* ── Auth Screen ────────────────────────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-container {
  text-align: center;
  padding: 2rem;
  max-width: 360px;
}

.auth-logo {
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1rem;
  letter-spacing: -0.05em;
}

.auth-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.03em;
}

.auth-sub {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 1.5rem;
}

.auth-desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.auth-error {
  color: #ff6b6b;
  font-size: 0.8rem;
  margin-top: 1rem;
}

.auth-hint {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 1.5rem;
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.75rem 2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    opacity 0.15s,
    transform 0.1s;
}
.btn-primary:hover {
  opacity: 0.9;
}
.btn-primary:active {
  transform: scale(0.98);
}
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.1s;
}
.btn-icon:hover {
  background: var(--surface-2);
}

.btn-text {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s;
  width: 100%;
}
.btn-text:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.2s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.sidebar-logo {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.sidebar-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
}

.conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s;
}
.conv-item:hover {
  background: var(--surface-2);
}
.conv-item.active {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
}

/* ── Chat Main ──────────────────────────────────────────────────────── */
.chat-main {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin-left: var(--sidebar-w);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.menu-btn {
  display: none;
}

.chat-header-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
}

.balance {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  padding: 4px 10px;
  background: var(--accent-glow);
  border: 1px solid rgba(0, 255, 136, 0.15);
  border-radius: 20px;
  white-space: nowrap;
}

/* ── Messages ───────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  gap: 12px;
}

.empty-logo {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.3;
}

.empty-state p {
  font-size: 1rem;
}

.msg {
  max-width: 720px;
  margin: 0 auto 16px;
  padding: 0;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.msg-user .msg-bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 10px 14px;
  max-width: 85%;
  word-break: break-word;
}

.msg-assistant {
  display: flex;
  justify-content: flex-start;
}

.msg-assistant .msg-bubble {
  background: transparent;
  padding: 10px 0;
  max-width: 100%;
  word-break: break-word;
  color: var(--text-dim);
  line-height: 1.65;
}

.msg-bubble code {
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

.msg-bubble pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.5;
}

.msg-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

/* ── Streaming cursor ───────────────────────────────────────────────── */
.streaming .msg-bubble::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.6s steps(1) infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* ── Tool indicators ────────────────────────────────────────────────── */
.tool-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.tool-indicator .tool-spinner {
  display: inline-block;
  width: 8px;
  overflow: hidden;
  color: var(--accent);
  animation: termActivity 0.8s steps(4) infinite;
}

@keyframes termActivity {
  0% {
    content: "|";
  }
  25% {
    content: "/";
  }
  50% {
    content: "-";
  }
  75% {
    content: "\\";
  }
}

.tool-spinner::before {
  content: "|";
  animation: spin 0.6s steps(4) infinite;
}

@keyframes spin {
  0% {
    content: "|";
  }
  25% {
    content: "/";
  }
  50% {
    content: "-";
  }
  75% {
    content: "\\";
  }
}

.tool-indicator.done {
  border-color: rgba(0, 255, 136, 0.2);
  color: var(--accent-dim);
}

.tool-indicator.done .tool-spinner {
  animation: none;
}

.tool-indicator.done .tool-spinner::before {
  content: "ok";
  animation: none;
  color: var(--accent);
}

/* ── Input Area ─────────────────────────────────────────────────────── */
.input-area {
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s;
}

.input-row:focus-within {
  border-color: #333;
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 150px;
  overflow-y: auto;
}

.chat-input::placeholder {
  color: var(--muted);
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    opacity 0.15s,
    transform 0.1s;
}

.btn-send:hover {
  opacity: 0.9;
}
.btn-send:active {
  transform: scale(0.95);
}
.btn-send:disabled {
  opacity: 0.2;
  cursor: not-allowed;
  transform: none;
}

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .chat-main {
    margin-left: 0;
  }

  .menu-btn {
    display: flex;
  }

  .msg-user .msg-bubble {
    max-width: 90%;
  }
}

/* ── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #333;
}

/* ── Focus ──────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* ── Selection ──────────────────────────────────────────────────────── */
::selection {
  background: rgba(0, 255, 136, 0.2);
  color: var(--text);
}
