/* ============================================================
   OpsGPT — Design System
   参考 Linear / Vercel 深色设计风格
   ============================================================ */

:root {
  /* Colors */
  --bg-base:      #0d0d0f;
  --bg-surface:   #111114;
  --bg-elevated:  #18181c;
  --bg-overlay:   #1e1e24;
  --bg-hover:     #25252d;
  --bg-active:    #2a2a35;

  --border:       rgba(255,255,255,0.07);
  --border-focus: rgba(14,165,233,0.5);

  --text-primary:   #f0f0f5;
  --text-secondary: #8b8b9e;
  --text-tertiary:  #55556a;
  --text-accent:    #0ea5e9;

  --accent:         #0ea5e9;
  --accent-hover:   #38bdf8;
  --accent-dim:     rgba(14,165,233,0.15);

  --success:        #22c55e;
  --warning:        #f59e0b;
  --error:          #ef4444;
  --error-dim:      rgba(239,68,68,0.12);

  /* Radii */
  --r-sm:  4px;
  --r-md:  8px;
  --r-lg:  12px;
  --r-xl:  16px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.5);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.6);
  --shadow-lg:  0 12px 32px rgba(0,0,0,0.7);
  --shadow-glow: 0 0 40px rgba(14,165,233,0.12);

  /* Layout */
  --navbar-h:    48px;
  --sidebar-w:   360px;
  --toolbar-h:   36px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.page   { width: 100%; height: 100vh; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar              { width: 5px; height: 5px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: var(--bg-active); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover  { background: var(--text-tertiary); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-bg {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 60% 40%, rgba(14,165,233,0.08) 0%, transparent 70%),
              var(--bg-base);
  z-index: 0;
}
.login-glow {
  position: absolute; top: 20%; left: 50%; transform: translateX(-50%);
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(14,165,233,0.06), transparent 65%);
  pointer-events: none;
}

.login-container {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
}

.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.login-header { text-align: center; margin-bottom: 32px; }

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.brand-name {
  font-size: 20px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text-primary);
}
.brand-sm { margin-bottom: 0; }

.login-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.form-field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary); letter-spacing: 0.3px;
}

.input-wrapper {
  position: relative; display: flex; align-items: center;
}
.input-icon {
  position: absolute; left: 12px; color: var(--text-tertiary);
  pointer-events: none; flex-shrink: 0;
}
.field-input {
  width: 100%;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px 10px 38px;
  font-size: 14px; color: var(--text-primary);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.08);
}
.field-input.readonly { color: var(--text-secondary); cursor: default; }

.toggle-password-btn {
  position: absolute; right: 10px;
  background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); padding: 4px;
  border-radius: var(--r-sm);
  transition: color 0.15s;
}
.toggle-password-btn:hover { color: var(--text-secondary); }

.form-error {
  display: flex; align-items: center; gap: 6px;
  background: var(--error-dim);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: var(--r-md);
  padding: 8px 12px;
  font-size: 13px; color: var(--error);
}

.btn-login {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent);
  color: white; font-size: 14px; font-weight: 600;
  border: none; border-radius: var(--r-md);
  padding: 11px 20px; cursor: pointer; width: 100%;
  margin-top: 4px;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 0 0 0 rgba(14,165,233,0.4);
}
.btn-login:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 16px rgba(14,165,233,0.35);
}
.btn-login:active:not(:disabled) { transform: scale(0.98); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

.login-footer {
  margin-top: 24px; text-align: center;
  font-size: 12px; color: var(--text-tertiary); line-height: 1.6;
}
.login-footer code {
  background: var(--bg-hover); padding: 1px 5px;
  border-radius: var(--r-sm); font-family: var(--font-mono);
  color: var(--text-secondary); font-size: 11px;
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
.app-layout {
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

/* ── Navbar ──────────────────────────────────────────────── */
.navbar {
  height: var(--navbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 50;
}
.navbar-left, .navbar-right {
  display: flex; align-items: center; gap: 12px;
}
.nav-divider {
  width: 1px; height: 18px;
  background: var(--border);
}

/* Status indicator */
.terminal-status-indicator {
  display: flex; align-items: center; gap: 6px;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connecting { background: var(--warning); animation: pulse-warn 1.2s ease infinite; }
.status-dot.connected  { background: var(--success); }
.status-dot.disconnected { background: var(--error); }
@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
.status-text { font-size: 12px; color: var(--text-secondary); }

/* User badge */
.user-badge { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; color: var(--text-secondary); }

/* Buttons */
.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); padding: 6px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.icon-btn-sm {
  background: none; border: none; cursor: pointer;
  color: var(--text-tertiary); padding: 4px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.icon-btn-sm:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-ghost {
  background: none; border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 12px; font-weight: 500;
  border-radius: var(--r-md); cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: all 0.15s;
}
.btn-sm { padding: 5px 10px; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: rgba(255,255,255,0.12); }

/* ── Main Body ───────────────────────────────────────────── */
.main-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================================
   AI SIDEBAR
   ============================================================ */
.ai-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.4,0,0.2,1),
              opacity 0.2s;
}
.ai-sidebar.collapsed {
  width: 0; opacity: 0; pointer-events: none;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
}
.sidebar-actions { display: flex; gap: 4px; }

/* Messages */
.messages-area {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 2px;
}

/* Welcome */
.welcome-message {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 32px 16px 16px;
  gap: 8px;
}
.welcome-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); margin-bottom: 4px;
}
.welcome-message h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.welcome-message p  { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

.quick-prompts {
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center; margin-top: 8px;
}
.quick-prompt-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 11px;
  border-radius: var(--r-lg); padding: 5px 10px;
  cursor: pointer; transition: all 0.15s;
  font-family: var(--font-sans);
}
.quick-prompt-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.12);
}

/* Message bubbles */
.msg { margin-bottom: 16px; }

.msg-user {
  display: flex; justify-content: flex-end;
}
.msg-user .bubble {
  background: var(--accent);
  color: white;
  border-radius: var(--r-lg) var(--r-sm) var(--r-lg) var(--r-lg);
  max-width: 85%;
}

.msg-ai {
  display: flex; gap: 8px; align-items: flex-start;
}
.msg-ai-icon {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); flex-shrink: 0; margin-top: 2px;
}
.msg-ai .bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-sm) var(--r-lg) var(--r-lg) var(--r-lg);
  max-width: 85%;
}

.bubble {
  padding: 10px 14px;
  font-size: 13px; line-height: 1.6;
  word-break: break-word;
}

/* Code blocks inside AI messages */
.bubble pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px; margin: 8px 0;
  overflow-x: auto;
  font-family: var(--font-mono); font-size: 12px;
  line-height: 1.6; color: #c9d1d9;
}
.bubble code {
  background: var(--bg-base);
  padding: 1px 5px; border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: 12px;
  color: #79c0ff;
}
.bubble pre code { background: none; padding: 0; color: inherit; }

/* Command action block */
.cmd-block {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden; margin: 8px 0;
}
.cmd-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}
.cmd-label { font-size: 11px; color: var(--text-tertiary); font-family: var(--font-mono); }
.cmd-actions { display: flex; gap: 4px; }
.cmd-run-btn, .cmd-copy-btn {
  background: none; border: none; cursor: pointer;
  font-size: 11px; font-weight: 500;
  border-radius: var(--r-sm); padding: 3px 8px;
  transition: all 0.15s; font-family: var(--font-sans);
}
.cmd-run-btn {
  background: var(--accent-dim); color: var(--accent);
}
.cmd-run-btn:hover { background: rgba(14,165,233,0.25); }
.cmd-copy-btn { color: var(--text-tertiary); }
.cmd-copy-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.cmd-code {
  padding: 8px 12px;
  font-family: var(--font-mono); font-size: 12px;
  color: #c9d1d9; line-height: 1.6;
  word-break: break-all;
}

/* Thinking indicator */
.thinking {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0;
}
.thinking-dots {
  display: flex; gap: 4px;
}
.thinking-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-tertiary);
  animation: bounce 1.2s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40%           { transform: scale(1.2); opacity: 1; }
}
.thinking-text { font-size: 12px; color: var(--text-tertiary); }

/* Input Area */
.input-area {
  flex-shrink: 0;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
}
.input-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.06);
}
.ai-textarea {
  width: 100%;
  background: none; border: none; outline: none;
  color: var(--text-primary); font-family: var(--font-sans);
  font-size: 13px; line-height: 1.5;
  padding: 10px 12px 6px;
  resize: none; max-height: 120px;
}
.ai-textarea::placeholder { color: var(--text-tertiary); }
.input-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  padding: 4px 8px 6px;
}
.send-btn {
  background: var(--accent); border: none; cursor: pointer;
  color: white; width: 28px; height: 28px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.input-hint { font-size: 11px; color: var(--text-tertiary); margin-top: 6px; }


/* ============================================================
   TERMINAL
   ============================================================ */
.terminal-wrapper {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: #0d0d0f;
}

.terminal-toolbar {
  height: var(--toolbar-h);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; }
.toolbar-right { display: flex; gap: 4px; }

.traffic-lights { display: flex; gap: 6px; align-items: center; }
.tl {
  width: 11px; height: 11px; border-radius: 50%;
  flex-shrink: 0;
}
.tl-red    { background: #ff5f56; }
.tl-yellow { background: #ffbd2e; }
.tl-green  { background: #27c93f; }

.terminal-title {
  font-size: 12px; color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.terminal-container {
  flex: 1; overflow: hidden; padding: 4px 0 0 4px;
}
.terminal-container .xterm { height: 100% !important; }
.terminal-container .xterm-viewport { overflow-y: auto !important; }


/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999; pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 16px;
  font-size: 13px; color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  pointer-events: auto;
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error   { border-color: rgba(239,68,68,0.3); }
.toast-icon { flex-shrink: 0; }
.toast.success .toast-icon { color: var(--success); }
.toast.error   .toast-icon { color: var(--error); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateY(4px); }
}


/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }

  .ai-sidebar {
    position: fixed;
    top: var(--navbar-h); left: 0;
    height: calc(100vh - var(--navbar-h));
    z-index: 100;
    border-right: none;
    box-shadow: var(--shadow-lg);
  }
  .ai-sidebar.collapsed {
    width: 0; overflow: hidden;
  }
  .user-name { display: none; }
  .login-card { margin: 16px; padding: 28px 24px; }
}
