/* ═══════════════════════════════════════════════════
   Alpine AI Terminal — style.css
   ═══════════════════════════════════════════════════ */

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

:root {
  --bg: #0a0e14;
  --bg2: #0d1117;
  --bg3: #161b22;
  --bg4: #1c232d;
  --border: #21262d;
  --border-strong: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #238636;
  --accent-hover: #2ea043;
  --accent-soft: #2ea04322;
  --blue: #388bfd;
  --amber: #f0ad4e;
  --red: #e05252;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
header h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

#status-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--text-dim);
}

/* status dot */
.state-dot { display: inline-flex; align-items: center; gap: 6px; }
.state-dot::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 0 0 transparent;
}
#state.loading { color: var(--amber); }
#state.loading::before { background: var(--amber); animation: pulse 1.2s infinite; }
#state.running { color: var(--accent-hover); }
#state.running::before { background: var(--accent-hover); box-shadow: 0 0 8px 1px var(--accent-hover); }
#state.error { color: var(--red); }
#state.error::before { background: var(--red); }
#state.paused { color: var(--amber); }
#state.paused::before { background: var(--amber); }

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

.hidden { display: none !important; }

main { flex: 1; display: flex; overflow: hidden; }
#split-container { display: flex; width: 100%; height: 100%; }

/* ── VM Panel ── */
#vm-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.terminal-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-hover);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
}
.view-tabs { display: flex; gap: 2px; background: var(--bg3); border-radius: 6px; padding: 2px; }
.view-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-ui);
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.view-tab:hover { color: var(--text); }
.view-tab.active { background: var(--accent); color: #fff; }

#terminal-status {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
}

/* ── Terminal area ── */
#terminal-area {
  flex: 1;
  position: relative;
  min-height: 0;
  background: #05070a;
}
.vm-view {
  position: absolute;
  inset: 0;
  display: none;
}
.vm-view.active { display: flex; }

#serial-view { flex-direction: column; }
#serial-output {
  flex: 1;
  width: 100%;
  min-height: 0;
  background: #05070a;
  color: #c8e6c9;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 4;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-hover) #05070a;
}
#serial-output::-webkit-scrollbar { width: 8px; height: 8px; }
#serial-output::-webkit-scrollbar-track { background: #05070a; }
#serial-output::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
#serial-output::-webkit-scrollbar-thumb:hover { background: var(--accent-hover); }

/* Screen (VGA) view */
#screen-view { align-items: center; justify-content: center; overflow: auto; background: #000; }
#screen {
  color: #fff;
  transform-origin: center center;
}
#screen .screen-text {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 14px;
  white-space: pre;
  color: #fff;
}
#screen .screen-canvas { display: none; }

/* ── VM input bar ── */
#vm-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.prompt-sign { color: var(--accent-hover); font-family: var(--font-mono); font-weight: 700; }
#vm-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}
#vm-input:focus { border-color: var(--accent); }
#vm-input:disabled { opacity: .5; cursor: not-allowed; }

/* ── Footer ── */
#vm-panel footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.controls { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  padding: 5px 12px;
  background: var(--bg4);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--border-strong); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent-hover); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { color: #ff9c9c; border-color: #5c2b2b; }
.btn.danger:hover:not(:disabled) { background: #3d1f1f; }
.btn.icon { padding: 5px 9px; font-size: 14px; }

.info {
  margin-left: auto;
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

/* ── AI Panel ── */
#ai-panel {
  width: 400px;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  flex-shrink: 0;
  min-height: 0;
}

#ai-header {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
#ai-model {
  flex: 1;
  min-width: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
}
#ai-model:focus { border-color: var(--accent); }

#auto-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg3);
  user-select: none;
  white-space: nowrap;
}
#auto-toggle-wrap:hover { border-color: var(--accent); }
#auto-toggle { width: 14px; height: 14px; cursor: pointer; accent-color: var(--accent); }

#ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
#ai-messages::-webkit-scrollbar { width: 8px; }
#ai-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* messages */
.msg {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.msg-user { background: #12233b; align-self: flex-end; max-width: 88%; border: 1px solid #1b3355; }
.msg-ai {
  background: var(--bg);
  border: 1px solid var(--border);
  align-self: flex-start;
  max-width: 100%;
  width: 100%;
}
.msg-system {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-dim);
  align-self: center;
  max-width: 95%;
  font-size: 11.5px;
  text-align: center;
  padding: 5px 10px;
}
.msg-vm {
  background: #05070a;
  border: 1px solid #1a1f2e;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #9fb3c8;
  align-self: flex-start;
  max-width: 100%;
  width: 100%;
}
.msg-vm .label {
  color: var(--accent-hover);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  font-family: var(--font-ui);
  font-size: 11px;
}
.msg-vm pre { margin: 0; white-space: pre-wrap; word-break: break-word; }

/* markdown inside ai messages */
.msg-ai code {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #ffd9a0;
}
.msg-ai pre.code-block {
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  position: relative;
}
.msg-ai pre.code-block code {
  background: none;
  border: none;
  padding: 0;
  color: #c8e6c9;
  font-size: 12.5px;
  line-height: 1.5;
}
.msg-ai .cmd-line {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #06140a;
  border: 1px solid #1c3a24;
  border-left: 3px solid var(--accent-hover);
  border-radius: 5px;
  padding: 6px 10px;
  margin: 6px 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: #b6f0c4;
}
.msg-ai .cmd-line::before { content: '❯'; color: var(--accent-hover); font-weight: 700; }
.msg-ai strong { color: #fff; }
.msg-ai a { color: var(--blue); }

.copy-btn {
  position: absolute;
  top: 6px; right: 6px;
  background: var(--bg4);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.msg-ai pre.code-block:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ── AI input ── */
#ai-input-bar {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
#ai-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  outline: none;
  max-height: 140px;
  line-height: 1.4;
}
#ai-input:focus { border-color: var(--accent); }

/* ── Toasts ── */
#toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  background: var(--bg4);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12.5px;
  max-width: 320px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: toastIn .2s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
.toast.fade { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ── Responsive ── */
@media (max-width: 900px) {
  #split-container { flex-direction: column; }
  #ai-panel { width: 100%; height: 45%; border-top: 1px solid var(--border); }
  #vm-panel { border-right: none; }
}
