/* =========================================================================
   ChaTEFgpt — Dark theme stylesheet
   ========================================================================= */

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

:root {
  --bg-page:       #0d1117;
  --bg-header:     #161b22;
  --bg-bubble-bot: #1c2432;
  --bg-bubble-usr: #1f4068;
  --bg-code:       #0d1117;
  --bg-code-line:  #161b22;
  --bg-input:      #161b22;
  --bg-options:    #1a2233;

  --border:        #30363d;
  --border-accent: #388bfd;

  --text-primary:  #e6edf3;
  --text-muted:    #8b949e;
  --text-code:     #79c0ff;
  --text-linenum:  #484f58;

  --accent-blue:   #388bfd;
  --accent-green:  #3fb950;
  --accent-red:    #f85149;
  --accent-orange: #d29922;
  --accent-flag:   #bc8cff;

  --font-ui:   'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --header-h: 56px;
  --inputbar-h: 72px;
}

/* ── Light theme overrides ────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-page:       #f6f8fa;
  --bg-header:     #ffffff;
  --bg-bubble-bot: #ffffff;
  --bg-bubble-usr: #0969da;
  --bg-code:       #f6f8fa;
  --bg-code-line:  #eaeef2;
  --bg-input:      #ffffff;
  --bg-options:    #eaeef2;

  --border:        #d0d7de;
  --border-accent: #0969da;

  --text-primary:  #1f2328;
  --text-muted:    #656d76;
  --text-code:     #0550ae;
  --text-linenum:  #9aa4b0;

  --accent-blue:   #0969da;
  --accent-green:  #1a7f37;
  --accent-red:    #cf222e;
  --accent-orange: #7d4e00;
  --accent-flag:   #6e40c9;
}

html, body {
  height: 100%;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.logo-bracket {
  color: var(--accent-blue);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
}

.logo-main {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.logo-tag {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--accent-blue); color: var(--text-primary); }

/* ── Chat container ───────────────────────────────────────────────────── */
.chat-container {
  position: fixed;
  top: var(--header-h);
  bottom: var(--inputbar-h);
  left: 0; right: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-log {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Message rows ─────────────────────────────────────────────────────── */
.msg-row {
  display: flex;
  gap: 12px;
  animation: fadeUp 0.18s ease;
}

.msg-row.user { flex-direction: row-reverse; }

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

/* Avatar dots */
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
  margin-top: 2px;
}

.msg-row.bot  .msg-avatar { background: var(--accent-blue);  color: #fff; }
.msg-row.user .msg-avatar { background: var(--bg-bubble-usr); color: #fff; }

/* Bubble wrapper */
.msg-content {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-row.user .msg-content { align-items: flex-end; }

/* ── Bubble types ─────────────────────────────────────────────────────── */
.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  word-break: break-word;
}

/* Bot text */
.bubble-text {
  background: var(--bg-bubble-bot);
  border-color: var(--border);
}

/* User text */
.bubble-user {
  background: var(--bg-bubble-usr);
  border-color: #2d5986;
}
[data-theme="light"] .bubble-user {
  color: #ffffff;
  border-color: #0550ae;
}

/* Success */
.bubble-success {
  background: #0d2818;
  border-color: var(--accent-green);
  color: #7ee787;
}
[data-theme="light"] .bubble-success {
  background: #e6f4ea;
  color: #1a7f37;
}

/* Error */
.bubble-error {
  background: #2d1117;
  border-color: var(--accent-red);
  color: #ff9898;
}
[data-theme="light"] .bubble-error {
  background: #ffeef0;
  color: #b91c1c;
}

/* Flag reveal */
.bubble-flag {
  background: #1a0f2e;
  border: 1px solid var(--accent-flag);
  border-radius: var(--radius-md);
  padding: 16px 20px;
}
[data-theme="light"] .bubble-flag {
  background: #f3eaff;
}

.flag-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-flag);
  margin-bottom: 8px;
}

.flag-value {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: #e2c4ff;
  letter-spacing: 0.05em;
  word-break: break-all;
}
[data-theme="light"] .flag-value { color: #5a2ca0; }

/* ── Code block ───────────────────────────────────────────────────────── */
.bubble-code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0;
  overflow: hidden;
  max-width: 100%;
  width: 100%;
}

.code-header {
  background: var(--bg-code-line);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-red    { background: #f85149; }
.dot-yellow { background: #d29922; }
.dot-green  { background: #3fb950; }

.code-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-x: auto;
  display: block;
}

.code-table td {
  padding: 1px 0;
  vertical-align: top;
  white-space: pre;
}

.code-linenum {
  color: var(--text-linenum);
  text-align: right;
  padding: 2px 14px 2px 14px;
  user-select: none;
  min-width: 42px;
  border-right: 1px solid var(--border);
}

.code-line {
  padding: 2px 16px 2px 14px;
  color: var(--text-code);
  width: 100%;
}

.code-table tr:hover .code-linenum,
.code-table tr:hover .code-line {
  background: rgba(255,255,255,0.035);
}
[data-theme="light"] .code-table tr:hover .code-linenum,
[data-theme="light"] .code-table tr:hover .code-line {
  background: rgba(0,0,0,0.04);
}

/* ── Options block ────────────────────────────────────────────────────── */
.bubble-options {
  background: var(--bg-options);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.option-letter {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-orange);
  min-width: 22px;
}

.option-text {
  color: var(--text-primary);
  line-height: 1.5;
}

/* ── Inline text formatting (rendered by JS) ─────────────────────────── */
.bubble strong { color: var(--text-primary); font-weight: 600; }
.bubble em     { color: var(--text-muted); font-style: italic; }
.bubble code   {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: rgba(110,118,129,0.15);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text-code);
}
.bubble ul  { padding-left: 1.4em; margin-top: 4px; }
.bubble li  { margin-bottom: 3px; }
.bubble hr  { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ── Typing indicator ─────────────────────────────────────────────────── */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 2px;
}
.typing-dots span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: blink 1.2s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* ── Input bar ────────────────────────────────────────────────────────── */
.input-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--inputbar-h);
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 20px;
  z-index: 100;
}

.input-form {
  display: flex;
  width: 100%;
  max-width: 820px;
  gap: 10px;
}

.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  padding: 9px 14px;
  outline: none;
  transition: border-color 0.15s;
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--accent-blue); }

.btn-send {
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  padding: 9px 18px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-send:hover   { background: #4c94f8; }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.input-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.input-hint code {
  font-size: 0.72rem;
  background: rgba(110,118,129,0.12);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  color: var(--text-muted);
}

.app-version {
  margin-left: 14px;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.45;
}

/* ── Reset confirmation modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.12s ease;
}
.modal-overlay[hidden] { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-box {
  background: var(--bg-header);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  max-width: 360px;
  width: calc(100% - 40px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.15s ease;
}

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

.modal-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.modal-body {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-danger {
  background: var(--accent-red);
  border: 1px solid transparent;
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-danger:hover { opacity: 0.82; }

/* ── Debug panel (internal testing only, hidden from normal participants) ── */
.debug-panel {
  position: fixed;
  bottom: calc(var(--inputbar-h) + 12px);
  right: 20px;
  width: 360px;
  background: #0a0e16;
  border: 1px solid var(--accent-orange);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  z-index: 300;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  animation: fadeUp 0.15s ease;
}

.debug-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #1a1200;
  border-bottom: 1px solid var(--accent-orange);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  color: var(--accent-orange);
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.debug-panel-close {
  background: transparent;
  border: none;
  color: var(--accent-orange);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.7;
}
.debug-panel-close:hover { opacity: 1; }

.debug-panel-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.debug-cmd {
  display: flex;
  gap: 10px;
  align-items: baseline;
  color: #c9a227;
}
.debug-cmd code {
  color: var(--accent-orange);
  background: rgba(210,153,34,0.1);
  border: none;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.76rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.debug-cmd span {
  color: var(--text-muted);
  font-size: 0.73rem;
  font-family: var(--font-ui);
}

.debug-panel-footer {
  padding: 6px 12px;
  border-top: 1px solid rgba(210,153,34,0.2);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-family: var(--font-ui);
  text-align: center;
  opacity: 0.6;
}

/* Debug inline bubble */
.bubble-debug {
  background: #1a1200;
  border-color: var(--accent-orange);
  color: var(--accent-orange);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
[data-theme="light"] .bubble-debug {
  background: #fff8e6;
  color: #7d4e00;
  border-color: var(--accent-orange);
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c8d0d9; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #9aa4b0; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .logo-tag { display: none; }
  .msg-content { max-width: 90%; }
  .code-table  { font-size: 0.74rem; }
}
