/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #111318;
  --surface:  #1a1d24;
  --surface2: #22262e;
  --border:   #2a2e38;
  --text:     #e0e0e6;
  --muted:    #6b7280;
  --accent:   #10b981;
  --accent-soft: rgba(16,185,129,.08);
  --danger:   #ef4444;
  --warn:     #f59e0b;
  --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', 'Cascadia Code', ui-monospace, monospace;
  --radius:   5px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 600;
}
button.primary:hover, .btn.primary:hover {
  background: #059669;
  border-color: #059669;
  color: #000;
}
button.danger, .btn.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #000; }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius);
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }

code, pre { font-family: var(--font-mono); }

/* ── Layout ───────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-logo {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .02em;
}
.topbar-nav { display: flex; align-items: center; gap: 14px; }
.topbar-nav a { color: var(--muted); font-size: 12px; }
.topbar-nav a:hover { color: var(--text); text-decoration: none; }

.page { flex: 1; padding: 20px 20px; max-width: 1100px; margin: 0 auto; width: 100%; }
.page-sm { max-width: 420px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 10px;
  flex-wrap: wrap;
}
.page-title { font-size: 14px; font-weight: 600; color: var(--text); }

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

/* ── Dashboard / Chat-first layout ────────────────────────────── */
.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.sidebar-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.sidebar-search {
  padding: 5px 8px;
  font-size: 12px;
  background: var(--bg);
}
.device-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
}
.device-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.device-item:hover { background: var(--surface2); }
.device-item-active { background: var(--accent-soft); }
.device-item-active:hover { background: var(--accent-soft); }
.device-item-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-item-offline { opacity: .5; }
.device-item-detail {
  opacity: .4;
  font-size: 11px;
  color: var(--muted);
  padding: 2px 5px;
  border-radius: 3px;
  transition: opacity .15s;
}
.device-item:hover .device-item-detail { opacity: 1; }
.device-item-detail:hover { color: var(--accent); text-decoration: none; }
.sidebar-add {
  flex-shrink: 0;
  margin: 6px 8px 8px;
  padding: 6px;
  font-size: 11px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.sidebar-add:hover { border-color: var(--accent); color: var(--accent); }

/* Mobile device bar */
.mobile-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mobile-menu {
  padding: 3px 6px;
  font-size: 16px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.mobile-menu:hover { color: var(--accent); border: none; }
.mobile-device-name {
  font-size: 13px;
  font-weight: 500;
}

/* Device context bar (desktop only — mobile-bar replaces it) */
.device-context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

/* Chat panel */
.chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── Status dot ───────────────────────────────────────────────── */
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-green { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot-gray  { background: var(--muted); }
.dot-red   { background: #e53e3e; box-shadow: 0 0 6px #e53e3e; }
.dot-amber { background: var(--warn); box-shadow: 0 0 6px var(--warn); }

/* ── Agent chat layout ─────────────────────────────────────────── */
.agent-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  position: relative;
}
.agent-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.agent-welcome {
  text-align: center;
  padding: 30px 16px;
  color: var(--muted);
  font-size: 12px;
}
.agent-welcome-title {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
  font-weight: 500;
}
.agent-msg { display: flex; flex-direction: column; animation: msg-appear .2s ease-out; }
.agent-msg-user { align-items: flex-end; }
.agent-msg-assistant { align-items: flex-start; }
.agent-msg-error { align-items: flex-start; }

.agent-bubble {
  max-width: 60%;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-line;
  word-break: break-word;
}
.agent-bubble-user {
  background: var(--accent);
  color: #000;
  border-bottom-right-radius: 3px;
}
.agent-bubble-assistant {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.agent-bubble-assistant p { margin: 0; }
.agent-bubble code { font-family: var(--font-mono); font-size: 11px; background: rgba(0,0,0,.2); padding: 1px 3px; border-radius: 2px; }
.agent-bubble-error {
  background: rgba(239,68,68,.1);
  color: #f87171;
  border-left: 2px solid #f87171;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 3px;
}

.agent-tool {
  max-width: 60%;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.agent-tool-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  cursor: pointer;
  background: var(--surface);
}
.agent-tool-header:hover { opacity: .8; }
.agent-tool-icon { font-size: 9px; }
.agent-tool-chevron { margin-left: auto; font-size: 8px; color: var(--muted); }
.agent-tool-body { padding: 5px 8px; font-size: 11px; }
.agent-tool-section { margin-bottom: 3px; }
.agent-tool-section pre {
  margin: 2px 0;
  padding: 5px 7px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 11px;
  max-height: 140px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: var(--font-mono);
}
.msg-actions {
  display: flex; gap: 3px; opacity: 0; transition: opacity .15s, max-height .15s; justify-content: flex-end;
  max-height: 0; overflow: hidden;
}
.agent-bubble:hover .msg-actions { opacity: 1; max-height: 24px; margin-top: 2px; }
.msg-actions button {
  padding: 1px 5px; font-size: 9px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--muted); cursor: pointer; line-height: 1.4;
}
.msg-actions button:hover { color: var(--text); border-color: var(--accent); }
.code-block-wrap { position: relative; }
.code-copy-btn {
  position: absolute; top: 4px; right: 4px;
  padding: 1px 5px; font-size: 9px;
  border: 1px solid var(--border); border-radius: 3px;
  background: var(--surface); color: var(--muted);
  cursor: pointer; opacity: 0; transition: opacity .15s;
  z-index: 1;
}
.code-block-wrap:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--text); border-color: var(--accent); }
.agent-code-block {
  background: var(--bg);
  padding: 6px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  margin: 3px 0;
  overflow-x: auto;
  white-space: pre-wrap;
}
.agent-thinking { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.agent-thinking-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
.agent-input-area {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  background: var(--surface);
}
.agent-input-row { display: flex; gap: 6px; align-items: flex-end; }
.agent-input {
  flex: 1; resize: none;
  padding: 7px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font-family: inherit; line-height: 1.4;
  min-height: 34px; max-height: 100px;
}
.agent-input:focus { outline: none; border-color: var(--accent); }
.agent-send { padding: 7px 14px; font-size: 12px; white-space: nowrap; height: 34px; border-radius: 8px; }
/* Draft mode toggle */
.draft-toggle {
  padding: 4px 6px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--muted); cursor: pointer; display: flex; align-items: center;
  transition: all .15s; flex-shrink: 0;
}
.draft-toggle:hover { color: var(--text); border-color: var(--accent); }
.draft-toggle-active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.draft-header {
  display: flex; justify-content: space-between; padding: 4px 8px 2px;
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.agent-input-draft {
  min-height: 200px !important;
  max-height: 70vh !important;
  height: 40vh !important;
  resize: vertical;
}

.agent-voice {
  padding: 6px 8px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--muted); cursor: pointer; display: flex; align-items: center;
  transition: all .15s;
}
.agent-voice:hover { color: var(--text); border-color: var(--accent); }
.agent-voice-active {
  color: var(--danger); border-color: var(--danger);
  animation: voice-pulse 1.5s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.3); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,.1); }
}
.agent-status {
  font-size: 10px;
  color: var(--muted);
  padding: 3px 6px;
  display: flex;
  justify-content: space-between;
}
.agent-status button {
  padding: 0; border: 0; font-size: 10px; color: var(--muted); background: none; cursor: pointer;
}
.agent-status button:hover { color: var(--accent); border: none; }

/* ── Suggestion chips ────────────────────────────────────── */
.suggestion-chips {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.suggestion-chip {
  padding: 5px 12px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: all .2s;
}
.suggestion-chip:hover {
  border-color: var(--accent); color: var(--accent); background: var(--accent-soft);
}
.suggestion-chip-edit {
  padding: 5px 10px; font-size: 12px; font-weight: 600; opacity: 0.4;
}
.suggestion-chip-edit:hover { opacity: 1; }
.chip-editor {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px 18px; max-width: 560px; width: 92vw; max-height: 80vh; overflow-y: auto;
}
.chip-editor-list { display: flex; flex-direction: column; gap: 10px; }
.chip-editor-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border);
}
.chip-editor-row textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
}

/* ── Inline screenshot preview ───────────────────────────── */
.agent-screenshot-preview { padding: 4px 7px; }
.agent-screenshot-thumb {
  max-width: 100%; max-height: 200px;
  border-radius: 6px; border: 1px solid var(--border);
  cursor: pointer; display: block;
  transition: opacity .15s;
}
.agent-screenshot-thumb:hover { opacity: .85; }

/* ── Screenshot/Modal overlay ────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; cursor: pointer;
}
.overlay-img {
  max-width: min(90vw, 1200px); max-height: 85vh;
  border-radius: 6px; cursor: default;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
  object-fit: contain;
}
.overlay-close {
  position: fixed; top: 12px; right: 12px;
  padding: 4px 10px; font-size: 11px;
  border: 1px solid rgba(255,255,255,.2); border-radius: var(--radius);
  background: rgba(0,0,0,.6); color: #aaa; cursor: pointer;
}
.overlay-close:hover { color: #fff; border-color: rgba(255,255,255,.4); }

@keyframes msg-appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Device detail page ───────────────────────────────────── */
.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}
.device-header-left { display: flex; align-items: center; gap: 8px; }
.device-header-right { display: flex; align-items: center; gap: 6px; }
.device-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

/* Remote control section */
.remote-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.remote-screen {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  position: relative;
  overflow: hidden;
  touch-action: auto;
}
.remote-screen img {
  max-width: 100%;
  max-height: min(55vh, 600px);
  display: block;
  object-fit: contain;
}
.remote-placeholder {
  color: var(--muted);
  font-size: 12px;
  padding: 30px;
  text-align: center;
}
.remote-controls {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.remote-controls button { font-size: 11px; padding: 4px 10px; }

/* Fullscreen remote — shared styles for native + fake */
.remote-screen img {
  transition: transform 0.1s ease-out;
  will-change: transform;
}
.remote-section { position: relative; }
.fs-exit-btn {
  display: none;
  position: absolute;
  top: 8px; right: 8px;
  z-index: 100001;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
/* Show exit button in any fullscreen mode */
.remote-section:fullscreen .fs-exit-btn,
.remote-section:-webkit-full-screen .fs-exit-btn,
.remote-section.fake-fullscreen .fs-exit-btn { display: flex; }

.remote-section:fullscreen,
.remote-section:-webkit-full-screen,
.remote-section.fake-fullscreen {
  background: #000;
  display: flex;
  flex-direction: column;
}
.remote-section:fullscreen .remote-screen,
.remote-section:-webkit-full-screen .remote-screen,
.remote-section.fake-fullscreen .remote-screen {
  flex: 1;
  min-height: 0;
  position: relative;
}
.remote-section:fullscreen .remote-screen img,
.remote-section:-webkit-full-screen .remote-screen img,
.remote-section.fake-fullscreen .remote-screen img {
  max-height: 100% !important;
  max-width: 100% !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
}
.remote-section:fullscreen .remote-controls,
.remote-section:-webkit-full-screen .remote-controls,
.remote-section.fake-fullscreen .remote-controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 100000;
  background: rgba(0,0,0,0.8);
  border-top: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.3s, transform 0.3s;
}
.remote-section:fullscreen .remote-controls.fs-controls-hidden,
.remote-section:-webkit-full-screen .remote-controls.fs-controls-hidden,
.remote-section.fake-fullscreen .remote-controls.fs-controls-hidden {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}
/* Hide gesture hint bar in fullscreen */
.remote-section:fullscreen .gesture-hint,
.remote-section:-webkit-full-screen .gesture-hint,
.remote-section.fake-fullscreen .gesture-hint { display: none !important; }

/* Fake fullscreen (iOS Safari fallback) */
body.fake-fullscreen-active { overflow: hidden !important; position: fixed !important; width: 100%; height: 100%; }
body.fake-fullscreen-active .topbar,
body.fake-fullscreen-active .device-header,
body.fake-fullscreen-active .footer,
body.fake-fullscreen-active .device-content > *:not(.remote-section) {
  display: none !important;
}
.remote-section.fake-fullscreen {
  position: fixed !important;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 99999;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
}

/* Camera feed */
.camera-section { margin-bottom: 20px; }
.camera-feed {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.camera-feed img {
  width: 100%;
  display: block;
}

/* Info grid */
.info-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.info-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.info-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.info-item .info-label { font-size: 10px; color: var(--muted); }
.info-item .info-value { font-size: 12px; color: var(--text); font-weight: 500; }

/* Upload zone */
.upload-zone {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: all .15s;
  cursor: default;
}
.upload-zone-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* File picker dialog */
.fp-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 92%;
  max-width: 640px;
  height: 70vh;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.fp-titlebar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  font-size: 13px;
}
.fp-body {
  flex: 1;
  display: flex;
  min-height: 0;
}
.fp-sidebar {
  width: 150px;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
  flex-shrink: 0;
}
.fp-sidebar-item {
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  border-radius: 4px;
  margin: 1px 4px;
}
.fp-sidebar-item:hover { background: var(--surface2); }
.fp-sidebar-active { background: var(--accent-soft) !important; color: var(--accent); }
.fp-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.fp-breadcrumb {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted);
  white-space: nowrap;
  overflow-x: auto;
}
.fp-crumb:hover { background: var(--surface2); color: var(--text); }
.fp-filelist {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.fp-row {
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(42,46,56,.3);
}
.fp-row:hover { background: var(--surface2); }
.fp-row-selected { background: var(--accent-soft) !important; }
.fp-icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.fp-filename { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-filesize { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.fp-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.fp-sort-btn {
  padding: 2px 6px;
  font-size: 10px;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 3px;
}
.fp-sort-btn:hover { color: var(--text); border-color: var(--border); }
.fp-sort-active { color: var(--accent) !important; border-color: var(--accent) !important; background: var(--accent-soft); }

@media (max-width: 600px) {
  .fp-sidebar { width: 0; display: none; }
  .fp-dialog { height: 80vh; max-height: none; }
}

/* Collapsible sections */
.collapsible-trigger {
  cursor: pointer;
  color: var(--accent);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.collapsible-trigger:hover { text-decoration: underline; }
.collapsible-body {
  margin-top: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

.form-check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.form-check input[type=checkbox] { width: auto; accent-color: var(--accent); }

.section { margin-bottom: 24px; }
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Alerts ───────────────────────────────────────────────────── */
.alert {
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 12px;
  border: 1px solid;
}
.alert-success { background: rgba(16,185,129,.08); border-color: rgba(16,185,129,.3); color: var(--accent); }
.alert-error   { background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.3); color: var(--danger); }

/* ── Login ────────────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(16,185,129,.04) 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  animation: login-appear .4s ease-out;
}
@keyframes login-appear {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
  margin-bottom: 3px;
  color: var(--text);
}
.login-tagline {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 24px;
}

/* ── Modal ────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 440px;
}
.modal-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
tr:hover td { background: var(--surface); }

/* ── Admin stats grid ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.stat-label { font-size: 10px; color: var(--muted); margin-bottom: 3px; }
.stat-value { font-size: 18px; font-weight: 700; color: var(--accent); }

/* ── Log stream ───────────────────────────────────────────────── */
.log-stream {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  height: 180px;
  overflow-y: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  color: #aaa;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Token display ────────────────────────────────────────────── */
.token-box {
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12px;
  word-break: break-all;
  color: var(--accent);
  margin: 8px 0;
}

.copy-cmd {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  margin: 6px 0;
  font-size: 12px;
  font-family: var(--font-mono);
  color: #aaa;
  overflow-x: auto;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s;
}
.copy-cmd:hover { border-color: var(--accent); }

/* ── Footer ───────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 14px;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--text); }

/* ── Utility ──────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag-green  { border-color: var(--accent); color: var(--accent); }
.tag-red    { border-color: var(--danger); color: var(--danger); }
.tag-gray   { border-color: var(--border); color: var(--muted); }
.tag-yellow { border-color: #f59e0b; color: #f59e0b; }

/* ── Legal pages ──────────────────────────────────────────────── */
.legal-page {
  max-width: 680px;
  margin: 40px auto;
  padding: 0 20px 60px;
  color: var(--text);
  line-height: 1.8;
}
.legal-page h1 { font-size: 20px; margin-bottom: 4px; }
.legal-page .updated { color: var(--muted); font-size: 12px; margin-bottom: 32px; }
.legal-page h2 { font-size: 14px; margin: 24px 0 8px; color: var(--text); }
.legal-page p { color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.legal-page ul { color: var(--muted); font-size: 13px; padding-left: 20px; margin-bottom: 10px; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hide-mobile { display: none; }
  .device-context-bar { display: none !important; }
  .sidebar {
    position: fixed;
    left: -240px;
    top: 40px;
    bottom: 0;
    z-index: 150;
    transition: left .2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }
  .sidebar-open { left: 0; }
  .mobile-bar { display: flex; }
  .app-layout { flex-direction: column; }
  .agent-bubble { max-width: 85%; }
  .agent-tool { max-width: 85%; }
  .agent-input { font-size: 16px; }
  .msg-actions { opacity: 1; max-height: 24px; margin-top: 2px; }
  .device-content { padding: 12px; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .remote-controls { gap: 5px; }
  .remote-controls button { padding: 5px 8px; font-size: 11px; }
}

@media (max-width: 400px) {
  .topbar { padding: 0 10px; }
  .info-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page { padding: 10px 8px; }
  .device-content { padding: 10px; }
  .page-header { gap: 6px; }
}

/* Prevent iOS auto-zoom on input focus */
@media (max-width: 768px) {
  input, select, textarea { font-size: 16px; }
}
