/* ═══════════════════════════════════════════════════════════
   CYNATIVE AI — tmux / Hacker Terminal Theme
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0a0e0a;
  --bg-secondary: #0c100c;
  --bg-tertiary: #111611;
  --surface: rgba(0, 255, 65, 0.03);
  --surface-hover: rgba(0, 255, 65, 0.07);
  --border: #00ff4125;
  --border-strong: #00ff4140;
  --text-primary: #c8e6c8;
  --text-secondary: #6b9b6b;
  --text-muted: #3d6b3d;
  --accent: #00ff41;
  --accent-dim: #00cc33;
  --accent-glow: rgba(0, 255, 65, 0.15);
  --cyan: #00f3ff;
  --orange: #ff6b00;
  --red: #ff3333;
  --yellow: #ccff00;
  --user-msg: #00ff41;
  --assistant-msg: #c8e6c8;
  --radius: 0px;
  --radius-sm: 0px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Courier New', monospace;
  --transition: 0.15s ease;
}

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

body {
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  font-size: 13px;
}

::selection {
  background: rgba(0, 255, 65, 0.25);
  color: #fff;
}

/* ═══ tmux Layout ═══ */
.app {
  display: flex;
  flex-direction: row;
  height: 100dvh;
  width: 100vw;
}

/* ═══ Sidebar (Left Pane) ═══ */
.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 255, 65, 0.06);
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  font-size: 0.9rem;
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}

.logo h1 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.new-chat-btn {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.new-chat-btn:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.session-item {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 2px solid transparent;
}

.session-item:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.session-item.active {
  background: var(--surface-hover);
  color: var(--accent);
  border-left: 2px solid var(--accent);
}

.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  display: none;
  padding: 0 4px;
  font-family: var(--font-mono);
}

.session-item:hover .delete-btn {
  display: block;
}

.delete-btn:hover {
  color: var(--red);
}

/* Sidebar scrollbar */
.session-list::-webkit-scrollbar {
  width: 3px;
}

.session-list::-webkit-scrollbar-track {
  background: transparent;
}

.session-list::-webkit-scrollbar-thumb {
  background: var(--border);
}

/* ═══ Main Content (Right Pane) ═══ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ═══ Header (tmux Status Bar) ═══ */
.header {
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 255, 65, 0.06);
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  font-family: var(--font-mono);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 8px;
  border: 1px solid var(--border);
  background: transparent;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ═══ Chat Container ═══ */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

.chat-container::-webkit-scrollbar {
  width: 3px;
}

.chat-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
  background: var(--border);
}

/* ═══ Welcome Screen ═══ */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  animation: fadeIn 0.6s ease;
  margin: auto;
}

.welcome-icon {
  font-size: 2rem;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  animation: pulse 3s ease-in-out infinite;
}

.welcome h2 {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.welcome p {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}

/* ═══ Messages (Terminal Output Style) ═══ */
.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 90%;
  animation: slideUp 0.2s ease;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-label {
  font-size: 0.62rem;
  font-weight: 700;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.message.user .message-label {
  color: var(--cyan);
}

.message.assistant .message-label {
  color: var(--accent-dim);
}

.message-bubble {
  padding: 10px 14px;
  line-height: 1.65;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}

.message.user .message-bubble {
  background: rgba(0, 243, 255, 0.06);
  border-color: rgba(0, 243, 255, 0.2);
  color: var(--cyan);
}

.message.assistant .message-bubble {
  background: rgba(0, 255, 65, 0.02);
  border-color: var(--border);
  color: var(--text-primary);
}

/* ═══ Typing Indicator ═══ */
.typing {
  display: flex;
  gap: 5px;
  padding: 12px 14px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 0;
  background: var(--accent);
  animation: bounce 1.4s ease-in-out infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ═══ Input (Terminal Prompt) ═══ */
.input-area {
  padding: 10px 20px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-form {
  display: flex;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 3px 3px 3px 12px;
  transition: border-color var(--transition);
}

.input-wrapper::before {
  content: ">_";
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  padding-right: 8px;
  flex-shrink: 0;
  align-self: center;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 8px 0;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  outline: none;
}

textarea::placeholder {
  color: var(--text-muted);
}

button[type="submit"] {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: rgba(0, 255, 65, 0.08);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  font-family: var(--font-mono);
}

button[type="submit"]:hover {
  background: rgba(0, 255, 65, 0.15);
  border-color: var(--accent);
}

button[type="submit"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ═══ Animations ═══ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.7; }
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

@keyframes scanline {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

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

/* ═══ Login Overlay ═══ */
.login-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(10, 14, 10, 0.95);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 0 40px rgba(0, 255, 65, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-card h2 {
  margin: 14px 0 8px;
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.login-card p {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 20px;
}

#logoutBtn:hover {
  background: var(--surface-hover) !important;
  color: var(--accent);
  border-color: var(--accent);
}

/* ═══ Thinking Block (always visible) ═══ */
.thinking-block {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-dim);
  overflow: hidden;
  background: rgba(0, 255, 65, 0.02);
}

.thinking-label {
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(0, 255, 65, 0.03);
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}

.thinking-block .thinking-content {
  padding: 10px 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.55;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  font-style: normal;
  max-height: 300px;
  overflow-y: auto;
}

/* ═══ Markdown Rendered Content ═══ */
.message-bubble.rendered {
  white-space: normal;
}

.message-bubble.rendered p {
  margin: 0 0 8px;
  line-height: 1.65;
}

.message-bubble.rendered p:last-child {
  margin-bottom: 0;
}

.message-bubble.rendered code {
  background: rgba(0, 255, 65, 0.08);
  padding: 1px 5px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--accent);
  border: 1px solid var(--border);
}

.message-bubble.rendered pre {
  background: #000;
  border: 1px solid var(--border);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-bubble.rendered pre code {
  background: none;
  padding: 0;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--text-primary);
  border: none;
}

.message-bubble.rendered ul,
.message-bubble.rendered ol {
  margin: 6px 0;
  padding-left: 18px;
}

.message-bubble.rendered li {
  margin: 3px 0;
  line-height: 1.55;
}

.message-bubble.rendered a {
  color: var(--cyan);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.message-bubble.rendered a:hover {
  border-bottom-color: var(--cyan);
}

.message-bubble.rendered blockquote {
  border-left: 2px solid var(--accent);
  margin: 8px 0;
  padding: 6px 12px;
  color: var(--text-secondary);
  background: rgba(0, 255, 65, 0.03);
}

.message-bubble.rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.78rem;
}

.message-bubble.rendered th,
.message-bubble.rendered td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.message-bubble.rendered th {
  background: rgba(0, 255, 65, 0.05);
  font-weight: 700;
  color: var(--accent);
}

.message-bubble.rendered h1,
.message-bubble.rendered h2,
.message-bubble.rendered h3,
.message-bubble.rendered h4 {
  margin: 12px 0 6px;
  font-weight: 700;
  color: var(--accent);
}

.message-bubble.rendered h1 { font-size: 1rem; }
.message-bubble.rendered h2 { font-size: 0.92rem; }
.message-bubble.rendered h3 { font-size: 0.86rem; }
.message-bubble.rendered h4 { font-size: 0.82rem; }

.message-bubble.rendered hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.message-bubble.rendered strong {
  font-weight: 700;
  color: var(--text-primary);
}

/* ═══ Tool Status Indicator (inline) ═══ */
.tool-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  background: rgba(0, 255, 65, 0.06);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

.tool-status::before {
  content: "⚡";
}

/* ═══════════════════════════════════════════════════════════
   TOOL TERMINAL PANEL — Bottom Pane
   ═══════════════════════════════════════════════════════════ */
.tool-terminal {
  border-top: 1px solid var(--border-strong);
  background: #020804;
  display: flex;
  flex-direction: column;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 50vh;
  overflow: hidden;
  position: relative;
  font-family: var(--font-mono);
}

/* Resize handle */
.tool-terminal-resize {
  height: 4px;
  cursor: ns-resize;
  background: transparent;
  position: relative;
  z-index: 3;
  flex-shrink: 0;
}

.tool-terminal-resize:hover,
.tool-terminal-resize.dragging {
  background: var(--accent-glow);
}

/* CRT scanline overlay */
.tool-terminal::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 65, 0.012) 2px,
    rgba(0, 255, 65, 0.012) 4px
  );
  pointer-events: none;
  z-index: 1;
}

.tool-terminal.collapsed {
  max-height: 0;
}

.tool-terminal.collapsed .tool-terminal-body {
  display: none;
}

.tool-terminal.header-only {
  max-height: 34px;
}

.tool-terminal.header-only .tool-terminal-body {
  display: none;
}

/* ═══ Terminal Header (tmux-style pane title) ═══ */
.tool-terminal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(0, 255, 65, 0.05);
  border-bottom: 1px solid #00ff4120;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.tool-terminal-title {
  font-size: 0.68rem;
  font-weight: 700;
  color: #00ff41;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tool-terminal-badge {
  font-size: 0.58rem;
  font-weight: 900;
  color: #000;
  background: #00ff41;
  padding: 1px 5px;
  min-width: 14px;
  text-align: center;
  font-family: inherit;
}

.tool-terminal-badge[data-count="0"] {
  opacity: 0.3;
}

.tool-terminal-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: #00ff4180;
  font-size: 0.6rem;
  cursor: pointer;
  padding: 2px 4px;
  transition: transform 0.2s ease;
  font-family: inherit;
}

.tool-terminal.header-only .tool-terminal-toggle {
  transform: rotate(180deg);
}

/* ═══ Terminal Progress Bar ═══ */
.tool-terminal-progress {
  height: 2px;
  background: transparent;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.tool-terminal-progress.active {
  background: rgba(0, 255, 65, 0.08);
}

.tool-terminal-progress-bar {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanline 1.5s ease-in-out infinite;
}

.tool-terminal-progress:not(.active) .tool-terminal-progress-bar {
  display: none;
}

/* ═══ Terminal Body ═══ */
.tool-terminal-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px;
  font-size: 0.73rem;
  line-height: 1.6;
  position: relative;
  z-index: 2;
}

.tool-terminal-body::-webkit-scrollbar {
  width: 3px;
}

.tool-terminal-body::-webkit-scrollbar-track {
  background: transparent;
}

.tool-terminal-body::-webkit-scrollbar-thumb {
  background: #00ff4125;
}

/* ═══ Terminal Entries ═══ */
.tool-terminal-entry {
  padding: 6px 0;
  border-bottom: 1px solid #00ff410a;
  animation: terminalFadeIn 0.15s ease;
}

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

.tool-terminal-entry:last-child {
  border-bottom: none;
}

.tool-entry-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-entry-icon {
  font-size: 0.7rem;
  flex-shrink: 0;
  font-family: inherit;
  width: 12px;
  text-align: center;
}

.tool-entry-icon.running {
  color: #00ff41;
}

.tool-entry-icon.done {
  color: var(--accent-dim);
}

.tool-entry-name {
  font-weight: 600;
  color: #00ff4190;
  font-size: 0.73rem;
}

.tool-entry-caller {
  font-size: 0.56rem;
  padding: 1px 5px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tool-entry-caller.direct {
  color: #00ff41;
  background: rgba(0, 255, 65, 0.08);
  border: 1px solid #00ff4120;
}

.tool-entry-caller.programmatic {
  color: var(--orange);
  background: rgba(255, 107, 0, 0.08);
  border: 1px solid #ff6b0020;
}

.tool-entry-elapsed {
  margin-left: auto;
  font-size: 0.6rem;
  color: var(--text-muted);
  font-family: inherit;
  letter-spacing: 0.02em;
}

/* ═══ Inline CLI Args (on header line) ═══ */
.tool-entry-args {
  font-size: 0.66rem;
  color: #00ff4190;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* ═══ Always-Visible Output ═══ */
.tool-entry-output {
  margin-top: 3px;
  margin-left: 18px;
  display: flex;
  gap: 4px;
  cursor: pointer;
  transition: max-height 0.2s ease;
}

.tool-entry-output pre {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  color: #00ff4190;
  font-size: 0.66rem;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: inherit;
  line-height: 1.5;
  max-height: 400px;
  overflow-y: auto;
  transition: max-height 0.3s ease;
  width: 100%;
}

.tool-entry-output.collapsed pre {
  max-height: 3.6em;
  overflow: hidden;
}

.tool-entry-output.expanded pre::-webkit-scrollbar {
  width: 2px;
}

.tool-entry-output.expanded pre::-webkit-scrollbar-thumb {
  background: #00ff4120;
}

/* ═══ Responsive ═══ */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    transform: translateX(-100%);
    height: 100%;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.8);
  }

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

  .mobile-menu-btn {
    display: block;
  }
}