:root {
  --bg-primary: #09090b;
  --bg-secondary: #121215;
  --bg-card: #18181b;
  --bg-input: #202024;
  --border-color: #27272a;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent-cyan: #38bdf8;
  --accent-cyan-glow: rgba(56, 189, 248, 0.25);
  --accent-purple: #c084fc;
  --accent-emerald: #34d399;
  --danger: #ef4444;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --header-height: 60px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
}

/* App Container */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

@media (max-width: 860px) {
  #app-container {
    border-left: none;
    border-right: none;
  }
}

/* Top App Header */
header {
  height: var(--header-height);
  padding: env(safe-area-inset-top, 0) 16px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 50;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #18181b, #27272a);
  border: 1px solid var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-info h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 6px var(--accent-emerald);
  display: inline-block;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Model Selector Dropdown */
.model-select-wrapper {
  position: relative;
}

select#model-select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, color 0.2s;
  max-width: 170px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

select#model-select:focus, select#model-select:hover {
  border-color: var(--accent-cyan);
  color: var(--text-primary);
}

.model-select-wrapper::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 10px;
  color: var(--text-muted);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

/* Chat Messages Feed */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Empty State Greeting */
.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
  padding: 32px 16px;
}

.empty-state .logo-large {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px auto;
  filter: drop-shadow(0 0 16px var(--accent-cyan-glow));
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #fff, var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.suggestion-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  border-color: var(--accent-cyan);
  background-color: #202025;
  transform: translateY(-1px);
}

/* Messages */
.message-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: bold;
}

.avatar.user-avatar {
  background-color: #3b82f6;
  color: #fff;
}

.avatar.assistant-avatar {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  box-shadow: 0 0 8px var(--accent-cyan-glow);
}

.message-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 14px;
  word-break: break-word;
  position: relative;
}

.message-row.user .message-bubble {
  background-color: #2563eb;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-row.assistant .message-bubble {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

/* Markdown Content Styling */
.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  background-color: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  color: #38bdf8;
}

.message-bubble pre {
  background-color: #0d0d10;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  margin: 10px 0;
  overflow-x: auto;
  position: relative;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  color: #e4e4e7;
  font-size: 12.5px;
  display: block;
}

.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(39, 39, 42, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.copy-code-btn:hover {
  background-color: #3f3f46;
  color: #fff;
}

.message-bubble ul, .message-bubble ol {
  margin-left: 20px;
  margin-bottom: 8px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble blockquote {
  border-left: 3px solid var(--accent-cyan);
  padding-left: 10px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* Blinking cursor for streaming */
.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background-color: var(--accent-cyan);
  vertical-align: middle;
  margin-left: 4px;
  animation: blink 0.8s infinite;
}

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

/* Bottom Chat Input Form */
footer {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0)) 16px;
  border-top: 1px solid var(--border-color);
  background-color: rgba(9, 9, 11, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 50;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 22px;
  padding: 6px 8px 6px 14px;
  transition: border-color 0.2s;
}

.input-bar:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

textarea#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  max-height: 140px;
  min-height: 24px;
  padding: 4px 0;
}

textarea#user-input::placeholder {
  color: var(--text-muted);
}

.action-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.mic-btn {
  background-color: transparent;
  color: var(--text-muted);
}

.mic-btn:hover {
  color: var(--text-primary);
}

.mic-btn.recording {
  color: var(--danger);
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0% { transform: scale(1); filter: drop-shadow(0 0 2px var(--danger)); }
  50% { transform: scale(1.1); filter: drop-shadow(0 0 8px var(--danger)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 2px var(--danger)); }
}

.send-btn {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.05);
}

.footer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* --- Phase 1 Additions --- */
.tool-chip {
  display: inline-block;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 0.75rem;
  margin-bottom: 8px;
  font-family: monospace;
}

.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.85rem;
}

.message-bubble th, .message-bubble td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}

.message-bubble th {
  background: var(--surface);
  color: var(--primary);
}

.message-bubble a {
  color: var(--primary);
  text-decoration: none;
}
.message-bubble a:hover {
  text-decoration: underline;
}

#login-btn.logged-in {
  color: var(--primary);
  background: rgba(56, 189, 248, 0.1);
}

.attachment-preview {
  display: none;
  gap: 10px;
  padding: 10px;
  background: var(--surface-light);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  overflow-x: auto;
}

.attachment-thumb {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.remove-attachment {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}

.icon-btn:focus-visible, .chip:focus-visible, .action-btn:focus-visible, .remove-attachment:focus-visible, .copy-code-btn:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* Fleet Dashboard */
.fleet-dashboard {
  background: var(--gray-900);
  border: 1px solid var(--gray-800);
  border-radius: 12px;
  padding: 20px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.fleet-dashboard h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--primary);
}
.dashboard-section {
  margin-bottom: 20px;
}
.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.dashboard-table th, .dashboard-table td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid var(--gray-800);
}
.dashboard-table th {
  color: var(--gray-400);
  font-weight: 500;
}
.dashboard-table td {
  color: var(--gray-100);
}
