:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #222736;
  --border: #2c3347;
  --text: #eef1f8;
  --muted: #949db8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --success: #10b981;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

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

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.brand h1 {
  font-size: 1rem;
  font-weight: 700;
}

.brand h1 span {
  color: var(--accent);
}

.brand p {
  font-size: 0.72rem;
  color: var(--muted);
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#providerSelect {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.78rem;
}

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
}

.quick-bar {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.chip {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chip:hover, .chip:active {
  background: var(--accent);
  border-color: var(--accent);
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 96%;
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.45;
  font-size: 0.9rem;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  width: 100%;
}

.msg-header {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.msg-body h3, .msg-body h4 {
  margin: 8px 0 6px;
  font-size: 0.95rem;
}

.msg-body ul {
  padding-left: 18px;
  margin: 6px 0;
}

.msg-body li {
  margin: 3px 0;
}

.msg-body code {
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82rem;
}

.msg-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

.msg-body a {
  color: #818cf8;
  text-decoration: none;
  font-weight: 600;
}

.msg-body a:hover {
  text-decoration: underline;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 640px;
}

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

th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(99, 102, 241, 0.06);
}

.live-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--warning);
}

.hidden {
  display: none !important;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--warning);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#messageInput {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
  resize: none;
  font-family: inherit;
}

#messageInput:focus {
  outline: none;
  border-color: var(--accent);
}

#sendBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

#sendBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#wifiUrlBox {
  background: var(--surface-2);
  padding: 8px;
  border-radius: 6px;
  font-size: 0.88rem;
  color: #818cf8;
  user-select: all;
}

.qr-wrap img {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.close-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}
