:root {
  --bg-root: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1f2630;
  --bg-input: #0b0e14;
  --border: #2d3542;
  --border-strong: #3e4859;
  --text-primary: #e6edf3;
  --text-secondary: #9ba6b5;
  --text-muted: #6e7887;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --ok-bg: rgba(34, 197, 94, 0.12);
  --ok-border: rgba(34, 197, 94, 0.35);
  --ok-text: #86efac;
  --amber-bg: rgba(245, 158, 11, 0.16);
  --amber-border: rgba(245, 158, 11, 0.5);
  --amber-text: #fcd34d;
  --red-bg: rgba(239, 68, 68, 0.16);
  --red-border: rgba(239, 68, 68, 0.55);
  --red-text: #fca5a5;
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-root);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.muted {
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11.5px;
}

.btn-full {
  width: 100%;
}

/* Login Screen */
.login-overlay {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.brand-row h1 {
  margin: 0;
  font-size: 20px;
}

.brand-badge {
  background: var(--accent-soft);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-subtitle {
  margin: 0 0 18px;
  color: var(--text-secondary);
  font-size: 13px;
}

.login-card input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  margin-bottom: 14px;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red-text);
  font-size: 12.5px;
}

/* App Shell Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
}

/* Top Header */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-root);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-weight: 700;
  font-size: 15px;
}

.badge-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  color: var(--amber-text);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.badge-pill {
  background: #f59e0b;
  color: #111827;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 800;
}

/* Top Bot Tabs */
.tab-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px 0;
  background: var(--bg-root);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border);
  margin-bottom: -1px;
  padding-bottom: 9px;
}

.tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f59e0b;
}

.tab-spacer {
  flex: 1;
}

/* Chat View */
.chat-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.bot-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.bot-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.bot-meta h2 {
  margin: 0;
  font-size: 14.5px;
  white-space: nowrap;
}

.bot-desc {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Instructions Panel */
.instructions-panel {
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.instructions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

.instructions-actions {
  display: flex;
  gap: 6px;
}

.instructions-panel textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  resize: vertical;
}

.instructions-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.instructions-feedback {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--ok-text);
}

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

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 380px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row.user .msg-bubble {
  background: var(--accent-soft);
  border-color: rgba(59, 130, 246, 0.35);
}

.msg-row.assistant .msg-bubble {
  background: var(--bg-elevated);
}

.msg-meta-label {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Safe Rendered Markdown Elements */
.md-body p {
  margin: 0 0 8px;
}

.md-body p:last-child {
  margin-bottom: 0;
}

.md-body ul, .md-body ol {
  margin: 4px 0 8px 20px;
  padding: 0;
}

.md-body li {
  margin-bottom: 3px;
}

.md-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.md-body pre {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.md-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.45;
}

/* Inline Approval Card */
.approval-card {
  align-self: flex-start;
  width: 100%;
  max-width: 560px;
  background: var(--bg-elevated);
  border: 1px solid var(--amber-border);
  border-radius: 12px;
  padding: 14px 16px;
}

.approval-card.cap-exceeded {
  border-color: var(--red-border);
}

.approval-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--amber-text);
  margin-bottom: 8px;
}

.approval-card.cap-exceeded .approval-title {
  color: var(--red-text);
}

.approval-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.approval-reason {
  font-size: 12.5px;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.approval-cap-warning {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red-text);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
}

.approval-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-status-note {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
}

/* Bottom Chat Input */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-root);
  border-top: 1px solid var(--border);
}

.chat-input-bar textarea {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  max-height: 160px;
  resize: none;
}

.chat-input-bar textarea:focus {
  outline: none;
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .app-shell {
    border-left: none;
    border-right: none;
  }
  .top-header {
    padding: 8px 10px;
  }
  .bot-desc {
    display: none;
  }
  .msg-row {
    max-width: 94%;
  }
}
.approval-status-note.warn {
  color: var(--amber-text);
}
