:root {
  --bg: #0b1020;
  --bg-elev: #121a30;
  --bg-card: #16203a;
  --bg-input: #0e162a;
  --border: #253255;
  --text: #e8eefc;
  --muted: #8ea0c9;
  --primary: #4f7cff;
  --primary-hover: #3d6bff;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --nav-h: 62px;
  --top-h: 54px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Toast */
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 9999; background: #1e293b; border: 1px solid var(--primary);
  color: #fff; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45); font-size: 13px; max-width: 90vw;
}
.toast.error { border-color: var(--danger); background: #3b1320; }
.toast.success { border-color: var(--success); background: #0f2f21; }

/* Buttons & Inputs */
button, select, input, textarea {
  font: inherit; color: inherit;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 9px; padding: 8px 14px;
  cursor: pointer; font-weight: 500; transition: all .15s ease; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #223055; border-color: #30416e; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #2c3e6b; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: #41558a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-lg { padding: 11px 18px; font-size: 15px; width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 6px; }

input, select, textarea {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 12px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.input-sm { padding: 5px 9px; font-size: 12px; width: auto; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #1b2849; border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 5px 11px; font-size: 12px; cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.chip-sm { padding: 4px 10px; font-size: 11px; }
.chip-warn { border-color: rgba(245,158,11,.5); color: #fcd34d; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600;
}
.badge-info { background: rgba(79,124,255,.18); color: #93b4ff; border: 1px solid rgba(79,124,255,.35); }
.badge-ok { background: rgba(34,197,94,.16); color: #86efac; border: 1px solid rgba(34,197,94,.35); }
.badge-warn { background: rgba(245,158,11,.18); color: #fcd34d; border: 1px solid rgba(245,158,11,.35); }
.badge-danger { background: rgba(239,68,68,.18); color: #fca5a5; border: 1px solid rgba(239,68,68,.4); }

/* Login View */
.login-view {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at top right, #1b2a57 0%, var(--bg) 55%);
}
.login-card {
  width: 100%; max-width: 420px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 18px; padding: 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.brand-row { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.brand-logo {
  width: 48px; height: 48px; border-radius: 14px; background: linear-gradient(135deg, #4f7cff, #7c3aed);
  display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0;
}
.brand-row h1 { margin: 0; font-size: 20px; }
.brand-row p { margin: 2px 0 0; font-size: 12px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.pwd-wrap { position: relative; display: flex; align-items: center; }
.pwd-wrap input { padding-right: 40px; }
.pwd-toggle {
  position: absolute; right: 6px; background: transparent; border: none;
  cursor: pointer; padding: 4px 6px; font-size: 15px; opacity: 0.8;
}
.pwd-toggle:hover { opacity: 1; }
.error-box {
  background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.45);
  color: #fecaca; padding: 8px 12px; border-radius: 8px; font-size: 12px;
}
.demo-accounts {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}
.demo-title { font-size: 11px; color: var(--muted); margin-bottom: 10px; }

/* App Shell */
.app-shell {
  height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
}
.topbar {
  height: var(--top-h); flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 0 14px; background: var(--bg-elev); border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mini { font-weight: 700; font-size: 15px; white-space: nowrap; }
.project-select {
  width: auto; max-width: 260px; padding: 5px 10px; font-size: 13px; font-weight: 500;
}
.user-pill {
  font-size: 12px; background: #1d2a4d; border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}

.main-layout {
  flex: 1; display: flex; min-height: 0; overflow: hidden;
}
.nav-bar {
  width: 200px; flex-shrink: 0; background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 10px; gap: 6px;
}
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; text-align: left;
}
.nav-item:hover { background: rgba(79,124,255,.08); color: var(--text); }
.nav-item.active {
  background: rgba(79,124,255,.16); border-color: rgba(79,124,255,.4); color: #fff; font-weight: 600;
}
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 700;
}

.content {
  flex: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 16px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Chat Panel */
.chat-panel.active {
  display: flex; flex-direction: column; height: calc(100dvh - var(--top-h) - 32px);
}
.chat-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.session-bar, .agent-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.agent-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 999px; font-size: 12px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--muted);
}
.agent-pill.active {
  background: rgba(79,124,255,.22); border-color: var(--primary); color: #fff; font-weight: 600;
}
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--success); }
.dot-off { background: #64748b; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 14px 4px; display: flex; flex-direction: column; gap: 14px;
}
.empty-chat {
  margin: auto; text-align: center; max-width: 440px; padding: 24px;
  color: var(--muted); border: 1px dashed var(--border); border-radius: 14px;
}
.msg {
  max-width: 92%; display: flex; flex-direction: column; gap: 4px;
}
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; width: 100%; max-width: 860px; }
.msg-meta { font-size: 11px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.msg.user .msg-meta { justify-content: flex-end; }
.msg-bubble {
  padding: 11px 14px; border-radius: 14px; word-break: break-word;
  background: var(--bg-card); border: 1px solid var(--border);
}
.msg.user .msg-bubble {
  background: #233a7a; border-color: #3656b0; color: #fff;
}
.msg-bubble pre {
  background: #090e1d; border: 1px solid #223054; border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; font-size: 12px; line-height: 1.45; margin: 8px 0;
}
.msg-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; font-size: 12.5px;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-status {
  font-size: 11.5px; color: #93b4ff; background: rgba(79,124,255,.1);
  border-left: 3px solid var(--primary); padding: 5px 9px; border-radius: 4px; margin-bottom: 6px;
}
.tool-details {
  margin: 6px 0; background: #0d1428; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px;
}
.tool-details summary { cursor: pointer; color: #a5b4fc; font-weight: 500; }
.tool-details pre { margin: 6px 0 0; max-height: 220px; overflow: auto; font-size: 11.5px; }
.streaming-cursor::after {
  content: '▍'; animation: blink 1s infinite; color: var(--primary);
}
@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

.chat-composer-wrap {
  flex-shrink: 0; padding-top: 8px; border-top: 1px solid var(--border);
}
.quick-prompts {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px;
  scrollbar-width: none;
}
.quick-prompts::-webkit-scrollbar { display: none; }
.chat-composer { display: flex; gap: 8px; align-items: flex-end; }
.chat-composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 42px; line-height: 1.4;
}

/* Cards & Grids */
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.card-head h3 { margin: 0; font-size: 15px; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px;
}
.panel-header h2 { margin: 0; font-size: 16px; }
.stack-gap { display: flex; flex-direction: column; gap: 12px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Files & Diff */
.subtab-group { display: flex; gap: 8px; }
.files-layout {
  display: grid; grid-template-columns: 280px 1fr; gap: 14px; min-height: 62vh;
}
.breadcrumb {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  padding-bottom: 10px; margin-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 12px;
}
.breadcrumb button {
  background: none; border: none; color: #93b4ff; cursor: pointer; padding: 2px 4px;
}
.file-list { display: flex; flex-direction: column; gap: 3px; max-height: 60vh; overflow-y: auto; }
.file-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.file-row:hover { background: rgba(79,124,255,.14); }
.file-row.active { background: rgba(79,124,255,.24); color: #fff; }
.preview-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--border);
}
.code-viewer {
  margin: 0; background: #090e1d; border-radius: 8px; padding: 12px;
  overflow: auto; max-height: 62vh; font-size: 12px; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.status-box {
  background: #090e1d; padding: 10px 12px; border-radius: 8px; font-size: 12px;
  overflow-x: auto; margin: 0 0 12px;
}
.diff-viewer {
  background: #090e1d; border-radius: 8px; padding: 10px; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
}
.diff-line { white-space: pre; padding: 1px 6px; }
.diff-add { background: rgba(34,197,94,.16); color: #86efac; }
.diff-del { background: rgba(239,68,68,.18); color: #fca5a5; }
.diff-hunk { color: #7dd3fc; background: rgba(56,189,248,.12); }

/* Approvals & Audit */
.approval-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.approval-card.pending { border-color: rgba(245,158,11,.6); background: #211c18; }
.approval-cmd {
  background: #090e1d; padding: 8px 10px; border-radius: 8px; margin: 8px 0;
  font-family: ui-monospace, monospace; font-size: 12.5px; overflow-x: auto;
}
.audit-list { display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow-y: auto; }
.audit-row {
  display: flex; gap: 10px; align-items: baseline; font-size: 12px;
  padding-bottom: 6px; border-bottom: 1px solid rgba(37,50,85,.5);
}

/* Health & Admin */
.health-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 10px;
}
.health-item {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.info-banner {
  margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: 12px;
  background: rgba(79,124,255,.1); border: 1px solid rgba(79,124,255,.25); color: #cbd5f5;
}
.item-row {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.deploy-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-top: 10px;
}
.deploy-box {
  background: #090e1d; border: 1px solid var(--border); border-radius: 10px; padding: 10px;
}
.deploy-head {
  display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.code-mini {
  margin: 0; font-size: 11.5px; overflow: auto; max-height: 220px;
  font-family: ui-monospace, monospace; white-space: pre;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,.68);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 520px; max-height: 90dvh; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px; padding: 20px;
}
.modal-card h3 { margin: 0 0 14px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Mobile Responsive */
@media (max-width: 820px) {
  .brand-mini { display: none; }
  .user-pill { display: none; }
  .project-select { max-width: 175px; }
  .main-layout { flex-direction: column; }
  .nav-bar {
    order: 2; width: 100%; height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 4px 6px env(safe-area-inset-bottom, 4px);
    flex-direction: row; justify-content: space-around;
    border-right: none; border-top: 1px solid var(--border);
  }
  .nav-item {
    flex: 1; flex-direction: column; justify-content: center; gap: 2px;
    padding: 4px 2px; font-size: 11px; text-align: center;
  }
  .nav-icon { font-size: 18px; line-height: 1; }
  .nav-badge { position: absolute; top: 2px; right: 16%; margin: 0; }
  .content { order: 1; padding: 10px; }
  .chat-panel.active {
    height: calc(100dvh - var(--top-h) - var(--nav-h) - env(safe-area-inset-bottom, 0px) - 20px);
  }
  .files-layout { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
