/* === Root === */
:root {
  --bg: #0f1117;
  --panel: #1a1d27;
  --sidebar: #14161f;
  --border: #2a2d3a;
  --text: #e1e4ed;
  --muted: #7a7f90;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --danger: #e53935;
  --success: #4caf50;
  --warning: #f0a500;
  --msg-user: #1e3a5f;
  --msg-assistant: #1a1d27;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

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

/* === App Shell === */
#app {
  display: flex;
  height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#sidebar-header {
  padding: 20px 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

#btn-new-session {
  width: 32px; height: 32px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
#btn-new-session:hover { background: var(--accent-hover); }

#sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 14px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.nav-btn:hover { background: var(--panel); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }

/* Session list */
#session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.session-item:hover { background: var(--panel); }
.session-item.active { background: var(--panel); border-left: 3px solid var(--accent); }
.session-item-title { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

#sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

#status-indicator { font-size: 12px; }
#status-indicator.status-online { color: var(--success); }
#status-indicator.status-offline { color: var(--danger); }

/* ============================================================
   MAIN AREA
   ============================================================ */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* === Toolbar === */
#toolbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  gap: 12px;
}

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

#toolbar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

#btn-settings {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 36px; height: 36px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-settings:hover { background: var(--border); }

/* === Content Area === */
#content-area {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  overflow-y: auto;
}
.view.active { display: flex; flex-direction: column; }

/* ============================================================
   DASHBOARD
   ============================================================ */
#dashboard, #dashboard-view { padding: 24px; gap: 24px; }

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stat-icon { font-size: 24px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; color: var(--muted); }

.quick-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.action-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.action-btn:hover { background: var(--accent-hover); }

.recent-section h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--muted);
}

.recent-item {
  padding: 10px 14px;
  background: var(--panel);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.recent-item:hover { background: var(--border); }
.recent-item-title { font-size: 13px; color: var(--text); }
.recent-item-meta { font-size: 11px; color: var(--muted); }

.system-status {
  display: flex;
  gap: 24px;
  font-size: 12px;
  color: var(--muted);
  padding: 12px 16px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.system-status span { display: flex; gap: 6px; align-items: center; }

/* ============================================================
   CHAT VIEW
   ============================================================ */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

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

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

/* === Input Area === */
#input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  align-items: flex-end;
}

#user-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 120px;
}
#user-input:focus { outline: none; border-color: var(--accent); }

#btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
#btn-send:hover { background: var(--accent-hover); }

#btn-stop {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

/* ============================================================
   SKILLS VIEW
   ============================================================ */
#skills-view { padding: 20px 24px; gap: 16px; }

.skills-header {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.skills-search { flex: 1; }
.skills-search input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.skills-search input:focus { outline: none; border-color: var(--accent); }

.skills-stats { font-size: 13px; color: var(--muted); white-space: nowrap; }

.btn-import-skill {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.btn-import-skill:hover { opacity: 0.85; }
.btn-import-skill:disabled { opacity: 0.5; cursor: not-allowed; }

.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.skill-category { }
.skill-category h3 {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px 0;
  font-weight: 600;
  text-transform: capitalize;
}

.skill-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.skill-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.skill-card:hover { border-color: var(--accent); }

.btn-delete-skill {
  background: none;
  border: 1px solid #f38ba8;
  color: #f38ba8;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-delete-skill:hover { background: #f38ba8; color: #1e1e2e; }

.skill-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.skill-icon { font-size: 18px; }
.skill-name { font-weight: 600; font-size: 14px; color: var(--text); }
.skill-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.skill-category { font-size: 11px; color: var(--accent); margin-top: 2px; }

.skill-category-heading {
  grid-column: 1 / -1;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 0 4px;
  margin-top: 8px;
}

/* ============================================================
   TASKS VIEW
   ============================================================ */
#tasks-view { padding: 20px 24px; gap: 16px; }

.tasks-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: -26px;
}

.tasks-header h2 { font-size: 16px; color: var(--text); margin: 0; }

.tasks-actions button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.tasks-actions button:hover { opacity: 0.85; }

.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 0;
  font-size: 15px;
}

.task-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 16px;
  border-left: 4px solid var(--border);
}

.task-card.task-pending  { border-left-color: #2196f3; }
.task-card.task-running  { border-left-color: var(--warning); }
.task-card.task-done     { border-left-color: var(--success); }
.task-card.task-failed   { border-left-color: var(--danger); }
.task-card.task-cancelled{ border-left-color: #9e9e9e; }
.task-card.task-paused   { border-left-color: #ff9800; }
.task-card.task-queued   { border-left-color: #9c27b0; }

.task-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.task-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.task-btn:hover { background: var(--hover); }
.task-btn-pause  { color: #ff9800; }
.task-btn-resume { color: var(--success); }
.task-btn-del    { color: var(--danger); }

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

.task-icon { font-size: 16px; }
.task-name { font-weight: 600; font-size: 14px; }
.task-status {
  font-size: 13px;
  color: var(--muted);
  margin-left: auto;
}

/* ── Task Queue Global Controls ── */
.task-ctrl-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.task-ctrl-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, transform .1s;
}
.task-ctrl-btn:active { transform: scale(0.96); }
.task-ctrl-start  { background: var(--success); color: #1e1e2e; }
.task-ctrl-start:hover { background: #89d88f; }
.task-ctrl-pause  { background: #ff9800; color: #fff; }
.task-ctrl-pause:hover { background: #f5a623; }
.task-ctrl-resume { background: var(--success); color: #1e1e2e; }
.task-ctrl-resume:hover { background: #89d88f; }
.task-ctrl-timer-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 4px;
}
.task-ctrl-timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-left: auto;
}
.task-ctrl-timer-input {
  width: 34px;
  padding: 5px 3px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #1e1e2e;
  color: #cdd6f4;
  font-size: 12px;
  text-align: center;
}
.task-ctrl-timer-input:focus { border-color: var(--accent); outline: none; }
.task-ctrl-timer-label {
  font-size: 12px;
  color: #6c7086;
  margin: 0 2px;
}
.task-ctrl-timer-toggle {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #313244;
  color: #a6adc8;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
}
.task-ctrl-timer-toggle.on {
  background: #f9e2af;
  color: #1e1e2e;
  border-color: #f9e2af;
}

/* ── Task order & badge ── */
.task-order {
  font-size: 12px;
  color: var(--muted);
  background: var(--hover);
  border-radius: 4px;
  padding: 2px 6px;
  min-width: 28px;
  text-align: center;
}
.task-badge {
  font-size: 11px;
  background: #181825;
  border: 1px solid #313244;
  border-radius: 4px;
  padding: 2px 8px;
  color: #6c7086;
}
.task-progress {
  font-size: 12px;
  color: var(--muted);
}
.task-progress.done   { color: var(--success); }
.task-progress.failed { color: var(--danger); }
.task-progress.paused { color: #ff9800; }

.task-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.task-params {
  font-size: 11px;
  color: #585b70;
  margin-left: 8px;
  background: #181825;
  border-radius: 4px;
  padding: 1px 6px;
}

.task-result {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 4px;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  font-family: monospace;
  word-break: break-all;
}

/* ============================================================
   HARDWARE VIEW
   ============================================================ */
#hardware-view { padding: 20px 24px; gap: 16px; }

/* ── Panel View (skill iframe) ── */
#panel-view { padding: 0; gap: 0; }
#panel-view.active { display: flex; flex-direction: column; }
#panel-toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: #181825;
  border-bottom: 1px solid #313244; flex-shrink: 0;
}
#btn-panel-back {
  background: none; border: none; color: #89b4fa;
  font-size: 15px; cursor: pointer; padding: 4px 8px;
  border-radius: 6px;
}
#btn-panel-back:hover { background: #313244; }
#panel-title { font-size: 15px; font-weight: 600; color: #cdd6f4; }
#panel-iframe {
  flex: 1; border: none; width: 100%; height: 100%;
  background: #0f0f0f;
}

@media (max-width: 680px) {
  #panel-view { padding-bottom: 56px; }
}

/* ============================================================
   HARDWARE
   ============================================================ */
.hardware-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hardware-header h2 { font-size: 20px; }

.hw-refresh-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.hw-refresh-btn:hover { opacity: 0.85; }

/* ═══ BLE 全局桥状态栏 ═══ */
.ble-status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.ble-status-icon { font-size: 20px; flex-shrink: 0; }
.ble-status-text { font-size: 13px; font-weight: 500; color: var(--fg); }
.ble-status-device { font-size: 12px; color: var(--muted); margin-left: 4px; }
.ble-status-actions { margin-left: auto; display: flex; gap: 8px; }
.ble-btn-connect {
  background: #2563eb; color: #fff; border: none;
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.ble-btn-connect:hover { background: #1d4ed8; }
.ble-btn-connect:disabled { background: #475569; cursor: not-allowed; }
.ble-btn-disconnect {
  background: #475569; color: #e2e8f0; border: none;
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.ble-btn-disconnect:hover { background: #ef4444; }
.ble-btn-disconnect.hidden { display: none; }

/* BLE command bar */
#ble-cmd-bar {
  display: flex; gap: 8px; padding: 10px 0;
  align-items: center; flex-wrap: wrap;
}
#ble-cmd-input {
  flex: 1; min-width: 150px;
  background: #181825; border: 1px solid #313244;
  color: #cdd6f4; border-radius: 8px;
  padding: 8px 12px; font-size: 14px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
}
#ble-cmd-input:focus { border-color: #cba6f7; outline: none; }
#btn-ble-send {
  background: #cba6f7; color: #1e1e2e; border: none;
  border-radius: 8px; padding: 8px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
#btn-ble-send:hover { background: #b4a0e0; }
#btn-ble-send:disabled { opacity: 0.5; cursor: not-allowed; }
#btn-ble-ping {
  background: #a6e3a1; color: #1e1e2e; border: none;
  border-radius: 8px; padding: 8px 12px;
  font-size: 13px; cursor: pointer;
}
#btn-ble-ping:hover { background: #89d87a; }
#ble-response {
  font-size: 12px; color: #6c7086;
  min-height: 18px; padding: 2px 0 8px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  word-break: break-all;
}
#ble-response.success { color: #a6e3a1; }
#ble-response.error { color: #f38ba8; }

.hardware-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hw-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hw-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.hw-section h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  color: var(--fg);
}

.hw-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hw-card-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.hw-card-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hw-card-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
}

.hw-card-status {
  font-weight: 500;
  font-size: 13px;
}
.hw-card-status.ok  { color: #a6e3a1; }
.hw-card-status.err { color: #f38ba8; }

.hw-card-meta {
  font-size: 12px;
  color: #6c7086;
}

.hw-loading { color: var(--muted); text-align: center; padding: 40px 0; }

/* ============================================================
   SETTINGS PANEL (slide-in)
   ============================================================ */
#settings-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
}
#settings-overlay.hidden { display: none; }

#settings-panel {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 360px;
  max-width: 90vw;
  background: var(--sidebar);
  border-left: 1px solid var(--border);
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.4);
}
#settings-panel.hidden { display: none; }

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.settings-header h2 { font-size: 18px; }

#btn-close-settings {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 32px; height: 32px;
  border-radius: 6px;
  cursor: pointer;
}
#btn-close-settings:hover { background: var(--border); }

.settings-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.settings-body select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.settings-hint {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* Task Dialog */
#task-dialog-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}
#task-dialog-overlay.hidden { display: none; }

#task-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  z-index: 91;
  min-width: 320px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#task-dialog.hidden { display: none; }
#task-dialog h3 { margin: 0; font-size: 16px; }
#task-dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
#task-dialog select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.dialog-actions button {
  padding: 8px 18px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }

/* Hardware check dialog */
/* Skill Dialog */
#skill-dialog { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 92; display: flex; align-items: center; justify-content: center; }
#skill-dialog .dialog-box, #skill-dialog .dialog-box-wide {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  z-index: 93;
  min-width: 340px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#skill-dialog .dialog-box-wide { min-width: 380px; max-width: 520px; }
#skill-dialog .dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#skill-dialog .dialog-header h3 { margin: 0; font-size: 16px; }
#skill-dialog .dialog-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
#skill-dialog .dialog-close:hover { color: var(--text); }
#skill-dialog .dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Hardware status */
.hw-ok { color: #22c55e; font-weight: 600; font-size: 15px; }
.hw-warn { color: #f59e0b; font-weight: 600; font-size: 14px; }
.hw-note { color: var(--muted); font-size: 13px; }
#pull-progress { color: var(--muted); font-size: 13px; }

/* Params form */
.skill-params { display: flex; flex-direction: column; gap: 10px; }
.param-row { display: flex; flex-direction: column; gap: 4px; }
.param-row label { font-weight: 600; font-size: 13px; color: var(--muted); }
.param-row input, .param-row textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.param-row input:focus, .param-row textarea:focus { outline: none; border-color: var(--accent); }

/* Skill detail info */
#skill-detail-info { padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
.skill-tag {
  display: inline-block;
  background: #1e293b;
  color: #94a3b8;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid #334155;
}
.skill-price-free { color: #22c55e; }
.skill-price-paid { color: #f59e0b; }
.skill-btn-buy {
  background: #f59e0b;
  color: #000;
  font-weight: 600;
}
.skill-btn-buy:hover { background: #d97706; }
.skill-note { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* Task result */
.task-status-line { margin-bottom: 6px; font-size: 14px; }
.task-output {
  background: var(--code-bg, #1e1e2e);
  color: var(--code-text, #cdd6f4);
  padding: 10px;
  border-radius: 6px;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 4px 0 0 0;
}
.skill-result-error { color: var(--error); font-size: 14px; padding: 8px 0; }
.btn-secondary {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.btn-secondary:hover { background: var(--hover); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
/* Mobile hamburger button — hidden on desktop */
.mobile-only { display: none; }

#btn-menu {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 40px; height: 36px;
  border-radius: 6px;
  cursor: pointer;
}

/* Tablet: shrink sidebar */
@media (max-width: 820px) {
  #sidebar { width: 210px; min-width: 210px; }
  .stats-row { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .skill-cards { grid-template-columns: 1fr 1fr; }
  .message { max-width: 88%; }
}

/* Phone: sidebar hidden + bottom nav + full-width content */
@media (max-width: 680px) {
  .mobile-only { display: flex; }

  /* Sidebar → slide-in overlay */
  #sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 270px;
    min-width: 270px;
    z-index: 200;
    transition: left 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }
  #sidebar.open { left: 0; }

  /* Dim overlay behind sidebar */
  #sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }
  #sidebar-overlay.show { display: block; }

  /* Bottom nav bar */
  #bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--sidebar);
    border-top: 1px solid var(--border);
    z-index: 150;
    display: none;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #bottom-nav.mobile-only { display: flex; }
  .bn-tab {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 0;
    min-width: 48px;
  }
  .bn-tab span {
    font-size: 10px;
    line-height: 1;
  }
  .bn-tab .icon { font-size: 20px; }
  .bn-tab.active { color: var(--accent); background: rgba(99,102,241,0.15); }
  .bn-tab:active { background: rgba(99,102,241,0.25); }

  /* Main area full width */
  #main-area { width: 100%; padding-bottom: 56px; }
  #toolbar { padding: 0 10px; }

  /* Content padding */
  #messages { padding: 10px 12px; }
  .message { max-width: 92%; font-size: 14px; }
  #input-area { padding: 8px 10px; gap: 6px; }
  #user-input { font-size: 14px; }
  #btn-send { padding: 10px 14px; font-size: 13px; }

  /* Dashboard */
  #dashboard, #dashboard-view { padding: 14px 12px; gap: 14px; }
  .stats-row { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px 8px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 11px; }
  .quick-actions { flex-direction: column; }

  /* Skills */
  #skills-view { padding: 12px; }
  .skills-header { flex-direction: column; align-items: stretch; gap: 8px; }
  .skill-cards { grid-template-columns: 1fr; gap: 8px; }
  .skill-card { padding: 12px; }

  /* Tasks */
  #tasks-view { padding: 12px; }
  .tasks-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .task-card { padding: 10px 12px; }

  /* Hardware */
  #hardware-view { padding: 12px; }
  .hardware-cards { grid-template-columns: 1fr; }
  .hardware-header { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Settings panel full-width */
  #settings-panel { width: 100%; max-width: 100%; }

  /* Selects smaller */
  #toolbar select { font-size: 12px; padding: 5px 6px; max-width: 100px; }

  /* BLE status bar — stack vertically on mobile */
  .ble-status-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .ble-status-actions { margin-left: 0; width: 100%; flex-direction: column; gap: 6px; }
  .ble-btn-connect, .ble-btn-disconnect { width: 100%; padding: 10px 0; font-size: 14px; text-align: center; }
}

/* ═══════════════════════════════════════════════
   Auth Overlay
   ═══════════════════════════════════════════════ */
#auth-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#auth-overlay.hidden { display: none; }
#auth-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  width: 100%; max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}
#auth-header { text-align: center; margin-bottom: 24px; }
#auth-header h1 { font-size: 28px; margin: 0 0 6px 0; color: var(--accent); }
#auth-subtitle { font-size: 13px; color: var(--muted); margin: 0; }
#auth-form input, #auth-form select {
  width: 100%; padding: 12px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font-size: 14px; box-sizing: border-box;
}
#auth-form input:focus, #auth-form select:focus {
  border-color: var(--accent); outline: none;
}
#auth-agreement { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
#auth-agreement input[type=checkbox] { width: auto; margin-right: 6px; }
.auth-error {
  color: #ff4d4d; font-size: 13px; text-align: center;
  margin-bottom: 12px; padding: 8px;
  background: rgba(255,77,77,0.1); border-radius: 6px;
}
.auth-btn-primary {
  width: 100%; padding: 12px; margin-bottom: 8px;
  border: none; border-radius: 8px;
  background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.auth-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-btn-secondary {
  width: 100%; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
#auth-toggle { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
#auth-toggle a { color: var(--accent); text-decoration: none; margin-left: 4px; }

/* Terms link inside agreement */
#auth-terms-link { color: var(--accent); text-decoration: none; }
#auth-terms-link:hover { text-decoration: underline; }

/* Terms Modal */
#auth-terms-modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10001; display: flex; align-items: center; justify-content: center;
}
.terms-modal-bg {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
}
.terms-modal-box {
  position: relative; z-index: 1;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 12px; max-width: 480px; width: 90%; max-height: 80vh;
  display: flex; flex-direction: column;
}
.terms-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.terms-modal-header h3 {
  margin: 0; font-size: 16px; color: var(--text);
}
#auth-terms-close {
  background: none; border: none; color: var(--muted); font-size: 24px;
  cursor: pointer; line-height: 1; padding: 0;
}
.terms-modal-body {
  padding: 20px; overflow-y: auto; font-size: 13px; color: var(--text);
  line-height: 1.8;
}
.terms-modal-body p { margin: 0 0 12px 0; }

/* ═══════════════════════════════════════════════
   Profile View
   ═══════════════════════════════════════════════ */
#profile-view { padding: 24px; }
.profile-container {
  max-width: 420px; margin: 0 auto;
}
.profile-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px 24px;
  text-align: center;
}
.profile-avatar { font-size: 56px; margin-bottom: 12px; }
.profile-card h2 { font-size: 22px; margin: 0 0 20px 0; color: var(--text); }
.profile-info { margin-bottom: 24px; }
.profile-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.profile-row:last-child { border-bottom: none; }
.profile-label { font-size: 13px; color: var(--muted); }
.profile-value { font-size: 14px; color: var(--text); font-weight: 500; }
.btn-logout {
  padding: 10px 32px; border: 1px solid #ff4d4d; border-radius: 8px;
  background: transparent; color: #ff4d4d;
  font-size: 14px; cursor: pointer;
}
.btn-logout:hover { background: rgba(255,77,77,0.1); }
