:root {
  --bg-primary: #070a13;
  --bg-secondary: #0e1322;
  --panel-bg: rgba(15, 22, 42, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.4);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #64748b;
  
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-primary-glow: rgba(99, 102, 241, 0.25);
  
  --color-success: #10b981;
  --color-success-glow: rgba(16, 185, 129, 0.2);
  --color-warning: #f59e0b;
  --color-warning-glow: rgba(245, 158, 11, 0.2);
  --color-danger: #f43f5e;
  --color-danger-glow: rgba(244, 63, 94, 0.2);
  --color-info: #0ea5e9;
  
  --font-sans: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --sidebar-width: 320px;
  --transition-speed: 0.25s;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(14, 165, 233, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  height: 100vh;
  height: 100dvh; /* actual visible viewport on mobile, excludes the browser's address bar */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  z-index: 10;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
  filter: drop-shadow(0 0 8px var(--color-primary-glow));
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 30%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.ollama-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  align-self: flex-start;
  transition: all var(--transition-speed);
}

.user-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.8rem;
}

.user-badge-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role-tag {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-info);
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.25);
  padding: 1px 6px;
  border-radius: 4px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.green {
  background-color: var(--color-success);
  box-shadow: 0 0 10px var(--color-success);
  animation: pulse 2s infinite;
}

.status-dot.yellow {
  background-color: var(--color-warning);
  box-shadow: 0 0 10px var(--color-warning);
  animation: pulse 2s infinite;
}

.status-dot.red {
  background-color: var(--color-danger);
  box-shadow: 0 0 10px var(--color-danger);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-header h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Agents List & Cards */
.agents-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.agent-card {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  transition: all var(--transition-speed);
  position: relative;
  overflow: hidden;
}

.agent-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.agent-card.active {
  background: rgba(99, 102, 241, 0.04);
  border-color: rgba(99, 102, 241, 0.2);
}

.agent-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.agent-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.agent-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
}

.agent-badge.stdio {
  color: var(--color-info);
  border-color: rgba(14, 165, 233, 0.2);
}

.agent-badge.sse {
  color: var(--color-primary);
  border-color: rgba(99, 102, 241, 0.2);
}

.agent-config-summary {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 12px;
}

.agent-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.agent-buttons {
  display: flex;
  gap: 6px;
}

.agent-card.error-state {
  border-color: rgba(244, 63, 94, 0.3);
}

.agent-error-msg {
  font-size: 0.75rem;
  color: var(--color-danger);
  background: rgba(244, 63, 94, 0.05);
  border: 1px solid rgba(244, 63, 94, 0.1);
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-family: var(--font-mono);
  max-height: 80px;
  overflow-y: auto;
}

/* Automation Rules List & Cards */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rule-card {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  transition: all var(--transition-speed);
}

.rule-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.rule-card.disabled {
  opacity: 0.5;
}

.rule-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}

.rule-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.rule-summary {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.rule-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rule-json-textarea {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* Tour Scenarios List & Cards */
.scenarios-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scenario-card {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  transition: all var(--transition-speed);
}

.scenario-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.scenario-card.disabled {
  opacity: 0.5;
}

.scenario-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}

.scenario-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.scenario-summary {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.scenario-active-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--color-success);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.scenario-active-badge .indicator-dot {
  width: 6px;
  height: 6px;
  background-color: var(--color-success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.scenario-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* System Prompts List & Cards */
.system-prompts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt-card {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  transition: all var(--transition-speed);
}

.prompt-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.prompt-card.disabled {
  opacity: 0.5;
}

.prompt-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}

.prompt-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.prompt-summary {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
  word-break: break-word;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  padding: 8px 10px;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.prompt-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.prompt-content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.prompt-content-header label {
  margin-bottom: 0;
}

.prompt-ai-helper-box {
  background: rgba(99, 102, 241, 0.08);
  border: 1px dashed rgba(99, 102, 241, 0.35);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prompt-ai-helper-box h4 {
  font-size: 0.8rem;
  font-weight: 600;
  color: #a5b4fc;
  margin: 0;
}

.prompt-ai-helper-box textarea {
  font-size: 0.85rem;
}

.system-prompt-modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Tools List inside Agent Card */
.agent-tools-container {
  margin-top: 12px;
  border-top: 1px dashed var(--border-color);
  padding-top: 12px;
}

.tools-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tools-toggle-btn:hover {
  color: var(--text-main);
}

.tools-toggle-btn svg {
  transition: transform var(--transition-speed);
}

.tools-toggle-btn.expanded svg {
  transform: rotate(90deg);
}

.agent-tools-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.tool-item {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: help;
  position: relative;
}

.tool-item-name {
  font-family: var(--font-mono);
  font-weight: 500;
  color: #a5b4fc;
}

.tool-item-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: none;
}

.tool-item:hover .tool-item-desc {
  display: block;
}

/* Main Workspace */
.workspace {
  flex: 1;
  min-width: 0; /* let it shrink below its content's natural width instead of forcing page-wide horizontal scroll */
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  position: relative;
}

.workspace-header {
  height: 70px;
  padding: 0 30px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 15, 30, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.workspace-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* Hamburger menu (mobile only) */
.hamburger-btn {
  display: none;
}

.sidebar-close-btn {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

/* Chat Console */
.chat-console {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 30px;
  display: flex;
  flex-direction: column;
}

.chat-welcome {
  max-width: 600px;
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.welcome-card {
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 40px 30px;
  box-shadow: var(--shadow-lg);
}

.welcome-card h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-card p {
  color: var(--text-muted);
  line-height: 1.6;
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.welcome-suggestions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.suggestion-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 10px 16px;
  border-radius: 10px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-speed);
}

.suggestion-chip:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.3);
  color: var(--text-main);
  transform: translateX(4px);
}

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Chat Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: slideIn 0.3s ease-out;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px var(--color-primary-glow);
}

.message.assistant .message-bubble {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.message-attached-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  margin-top: 10px;
}

.message-sender {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.message.user .message-sender {
  text-align: right;
}

/* Tool execution trace components */
.trace-block {
  align-self: flex-start;
  width: 80%;
  background: rgba(15, 23, 42, 0.4);
  border-left: 3px solid var(--color-info);
  border-radius: 4px;
  padding: 12px 16px;
  margin: 6px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: slideIn 0.25s ease-out;
}

.trace-block.thinking {
  border-left-color: var(--color-primary);
}

.trace-block.success {
  border-left-color: var(--color-success);
}

.trace-block.error {
  border-left-color: var(--color-danger);
  background: rgba(244, 63, 94, 0.03);
}

.trace-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.trace-header .agent-name-label {
  background: rgba(14, 165, 233, 0.15);
  color: var(--color-info);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

.trace-header .tool-name-label {
  font-family: var(--font-mono);
  color: #a5b4fc;
}

.trace-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-wrap: break-word;
}

.trace-code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.trace-code.result {
  color: #e2e8f0;
}

.trace-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* Chat Input Bar */
.workspace-footer {
  padding: 20px 30px 30px 30px;
  background: linear-gradient(to top, var(--bg-secondary) 80%, transparent);
}

.chat-input-form {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 10px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color var(--transition-speed);
}

.chat-input-form:focus-within {
  border-color: var(--border-focus);
}

.active-agents-indicator {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 8px;
}

.context-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 8px;
  padding: 6px 10px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--text-main);
}

.context-indicator strong {
  color: #a5b4fc;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 8px;
}

.attachment-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.active-agent-pill {
  font-size: 0.75rem;
  background: rgba(99, 102, 241, 0.1);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 2px 8px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.active-agent-pill .indicator-dot {
  width: 6px;
  height: 6px;
  background-color: var(--color-success);
  border-radius: 50%;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-input-form textarea {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  padding: 8px;
  line-height: 1.5;
}

.chat-input-form textarea::placeholder {
  color: var(--text-dark);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(7, 10, 19, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-speed) ease;
  z-index: 100;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  width: 90%;
  max-width: 550px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  transform: translateY(20px);
  transition: transform var(--transition-speed) ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal form,
.rule-modal-body,
.qr-modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-section {
  border-top: 1px solid var(--border-color);
  margin-top: 10px;
  padding-top: 16px;
}

.form-section h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  font-weight: 600;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
}

.form-group input, 
.form-group select, 
.form-group textarea {
  background: rgba(7, 10, 19, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-speed);
}

.form-group textarea {
  font-family: var(--font-mono);
}

.form-group input:focus, 
.form-group select:focus, 
.form-group textarea:focus {
  border-color: var(--color-primary);
}

.help-text {
  font-size: 0.75rem;
  color: var(--text-dark);
}

.form-group-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.form-group-checkbox label {
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.form-group-checkbox input[type="checkbox"],
.form-group-checkbox input[type="radio"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* A modal-footer sitting directly under .modal (not inside a <form> or
   .rule-modal-body, which already carry their own padding) needs its own. */
.modal > .modal-footer {
  padding: 0 24px 24px;
}

/* Form switch helper helper */
.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition-speed);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 4px 10px var(--color-primary-glow);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

#btn-tts-toggle.tts-active {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.35);
  color: #a5b4fc;
}

#btn-tts-toggle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.2);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-circle {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
}

#btn-mic {
  touch-action: none;
}

#btn-mic.recording {
  background: rgba(244, 63, 94, 0.15);
  border-color: var(--color-danger);
  color: var(--color-danger);
  animation: micPulse 1.4s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(244, 63, 94, 0); }
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 6px;
  transition: all var(--transition-speed);
}

.btn-icon:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  background: rgba(15, 22, 42, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 18px;
  color: var(--text-main);
  min-width: 250px;
  max-width: 350px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease-out;
}

.toast.success {
  border-left: 3px solid var(--color-success);
}

.toast.error {
  border-left: 3px solid var(--color-danger);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  margin-left: 12px;
}

/* Mobile layout: the sidebar becomes a slide-in drawer opened via the
   hamburger button, and spacing/sizing tightens up so nothing overflows a
   phone viewport. */
@media (max-width: 768px) {
  .hamburger-btn {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: min(300px, 85vw);
    transform: translateX(-100%);
    transition: transform var(--transition-speed) ease;
    z-index: 150;
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.4);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-header {
    position: relative;
  }

  .sidebar-close-btn {
    display: inline-flex;
    position: absolute;
    top: 16px;
    right: 16px;
  }

  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 140;
  }

  .workspace-header {
    height: auto;
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 10px;
  }

  .workspace-header h2 {
    font-size: 1rem;
  }

  .header-actions .btn-label {
    display: none;
  }

  .chat-console {
    padding: 16px;
  }

  .chat-welcome {
    max-width: 100%;
  }

  .welcome-card {
    padding: 24px 18px;
  }

  .welcome-card h3 {
    font-size: 1.2rem;
  }

  .message,
  .trace-block {
    max-width: 92%;
    width: 92%;
  }

  .workspace-footer {
    padding: 10px 12px 16px;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 16px;
  }

  .toast {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  /* Keep form fields at 16px so iOS Safari doesn't auto-zoom in on focus */
  .chat-input-form textarea,
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
  }

  .modal-header,
  .modal form,
  .rule-modal-body,
  .system-prompt-modal-body,
  .qr-modal-body {
    padding: 16px;
  }

  .modal > .modal-footer {
    padding: 0 16px 16px;
  }

  .login-card {
    padding: 32px 24px;
  }
}

/* Login Screen */
.login-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(14, 165, 233, 0.1) 0px, transparent 50%);
  z-index: 200;
}

.login-card {
  width: min(360px, 90vw);
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-logo {
  justify-content: center;
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.login-error {
  font-size: 0.8rem;
  color: var(--color-danger);
  background: rgba(244, 63, 94, 0.08);
  border: 1px solid rgba(244, 63, 94, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
}

#btn-login {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

/* Users List & Cards */
.users-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-card {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-card-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-header-actions {
  display: flex;
  gap: 8px;
}

/* QR Scan Modal */
.qr-video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.qr-video-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-scan-frame {
  position: absolute;
  inset: 12%;
  border: 2px solid var(--color-primary);
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.camera-flip-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: rgba(7, 10, 19, 0.6);
  backdrop-filter: blur(4px);
  color: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
}

.camera-flip-btn:hover {
  background: rgba(7, 10, 19, 0.8);
}

.qr-status {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.qr-status.success {
  color: var(--color-success);
}

.qr-status.error {
  color: var(--color-danger);
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Animations */
@keyframes pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(50px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
