/* Mobile AI Commander v2 — Ultra-fast, Dark, Touch-optimized, Low-Bandwidth */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f12;
  --bg2: #161a20;
  --bg3: #202630;
  --border: #2d3544;
  --text: #f0f3f8;
  --text2: #9ba6b8;
  --accent: #38bdf8;
  --accent2: #0284c7;
  --accent-glow: rgba(56, 189, 248, 0.25);
  --red: #f87171;
  --green: #4ade80;
  --orange: #fb923c;
  --purple: #a855f7;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Menlo", monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%; width: 100%;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.screen { height: 100%; width: 100%; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

/* --- Login --- */
.login-box {
  margin: auto; padding: 2.5rem 1.5rem; text-align: center; max-width: 340px; width: 100%;
}
.logo-circle {
  font-size: 2.8rem; margin-bottom: 0.75rem;
  display: inline-block; filter: drop-shadow(0 0 16px var(--accent-glow));
}
.login-box h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.4rem; letter-spacing: -0.02em; }
.login-box .sub { color: var(--text2); font-size: 0.85rem; line-height: 1.4; margin-bottom: 1.8rem; }
.login-box input {
  width: 100%; padding: 0.85rem 1rem; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); border-radius: 10px;
  font-size: 1rem; margin-bottom: 0.85rem; outline: none; transition: border-color 0.2s;
}
.login-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.login-box button {
  width: 100%; padding: 0.85rem; background: var(--accent2);
  color: #fff; border: none; border-radius: 10px; font-size: 1rem;
  cursor: pointer; font-weight: 600; transition: background 0.15s;
}
.login-box button:active { background: #0369a1; }
.err { color: var(--red); font-size: 0.85rem; margin-top: 0.75rem; }

/* --- Top Bar --- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.75rem; background: var(--bg2);
  border-bottom: 1px solid var(--border);
  min-height: 52px; flex-shrink: 0; z-index: 20;
}
.header-titles { flex: 1; min-width: 0; padding-left: 0.25rem; }
#topbar-title { font-size: 1.05rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-sub { font-size: 0.75rem; color: var(--text2); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 0.35rem; }

.icon-btn {
  background: none; border: none; color: var(--text); font-size: 1.25rem;
  padding: 0.4rem; cursor: pointer; border-radius: 8px; min-width: 40px; min-height: 40px;
  display: flex; align-items: center; justify-content: center; transition: background 0.15s;
}
.icon-btn:active { background: var(--bg3); }
.voice-hud-btn { color: var(--accent); }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0; margin-right: 4px;
}
.dot.online { background: var(--green); box-shadow: 0 0 6px rgba(74,222,128,0.6); }
.dot.offline { background: var(--red); }
.dot.connecting { background: var(--orange); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* --- Menu Overlay --- */
#menu-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
}
#menu-overlay[hidden] { display: none !important; }
#menu {
  position: absolute; top: 56px; right: 12px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px; min-width: 230px;
  overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.menu-header {
  padding: 0.75rem 1rem 0.5rem; font-size: 0.75rem; font-weight: 600;
  color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em;
}
.menu-sep { border: 0; border-top: 1px solid var(--border); margin: 0.25rem 0; }
#menu button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; padding: 0.8rem 1rem;
  background: none; border: none; color: var(--text); font-size: 0.95rem;
  cursor: pointer;
}
#menu button:active { background: var(--bg3); }

/* --- Views --- */
.view { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.view[hidden] { display: none !important; }

.view-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.section-label { font-size: 0.8rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; }

.list { padding: 0.65rem; }

/* --- Cards --- */
.card {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.95rem 1rem; margin-bottom: 0.5rem;
  background: var(--bg2); border-radius: 10px;
  border: 1px solid var(--border); cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.card:active { background: var(--bg3); transform: scale(0.99); }
.card .icon { font-size: 1.4rem; flex-shrink: 0; }
.card .info { flex: 1; min-width: 0; }
.card .name { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { color: var(--text2); font-size: 0.8rem; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .badge {
  font-size: 0.7rem; padding: 2px 7px; border-radius: 6px;
  background: var(--accent2); color: #fff; font-weight: 500; flex-shrink: 0;
}
.card .badge.running { background: var(--green); color: #000; font-weight: 600; }
.card .badge.disabled { background: var(--bg3); color: var(--text2); }

.project-banner {
  padding: 0.65rem 1rem; background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.project-banner .name { font-weight: 600; font-size: 0.95rem; display: block; }
.project-banner .meta { font-size: 0.8rem; color: var(--text2); }

/* --- FAB Button --- */
.fab {
  position: absolute; bottom: calc(1.2rem + var(--safe-bottom)); right: 1.2rem;
  width: 56px; height: 56px; border-radius: 28px; border: none;
  background: var(--accent2); color: #fff; font-size: 1.8rem;
  cursor: pointer; box-shadow: 0 4px 16px rgba(2, 132, 199, 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 10;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.94); }

/* --- Chat View --- */
#chat-view {
  display: flex; flex-direction: column; position: relative;
}
#chat-messages {
  flex: 1; overflow-y: auto; padding: 0.75rem 0.5rem;
  scroll-behavior: smooth; outline: none;
}

.msg {
  margin-bottom: 0.85rem; padding: 0.65rem 0.85rem;
  border-radius: 12px; max-width: 92%; word-wrap: break-word;
  font-size: 0.92rem; line-height: 1.5; position: relative;
}
.msg.user {
  background: var(--accent2); color: #fff; margin-left: auto;
  border-bottom-right-radius: 2px;
}
.msg.assistant {
  background: var(--bg2); border: 1px solid var(--border);
  border-bottom-left-radius: 2px; color: var(--text);
}
.msg.notice {
  background: none; color: var(--text2); font-size: 0.8rem;
  text-align: center; font-style: italic; max-width: 100%; margin: 0.4rem 0;
}
.msg.error {
  background: rgba(248, 113, 113, 0.12); border: 1px solid var(--red);
  color: var(--red); font-size: 0.85rem;
}

.msg pre, .msg code {
  font-family: var(--mono); font-size: 0.82rem;
  background: rgba(0,0,0,0.35); padding: 2px 5px; border-radius: 4px;
}
.msg pre {
  padding: 0.65rem; margin: 0.5rem 0; overflow-x: auto;
  max-height: 250px; white-space: pre-wrap; line-height: 1.4;
}

.msg img.msg-image {
  max-width: 100%; max-height: 220px; border-radius: 8px;
  display: block; margin: 0.5rem 0; object-fit: contain;
  background: #000;
}

/* Code Fence (Void / T3 Code pattern) */
.code-fence {
  margin: 0.6rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.95);
}
.code-fence-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.code-fence-lang {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text2);
  text-transform: uppercase;
}
.code-fence-copy {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: var(--text2);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 6px;
}
.code-fence-copy:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}
.code-fence pre {
  margin: 0 !important;
  padding: 0.6rem 0.8rem !important;
  background: transparent !important;
  max-height: 320px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.4;
}

/* Tool execution card enhancements (Cline pattern) */
.tool-args {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text2);
  margin: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-status {
  font-size: 0.72rem;
  font-weight: 600;
  margin-right: 6px;
}
.tool-status.running { color: var(--orange, #fb923c); }
.tool-status.success { color: var(--green, #4ade80); }
.tool-status.error { color: var(--red, #f87171); }
.tool-block.tool-error { border-color: rgba(248, 113, 113, 0.4); }
.tool-block.tool-success { border-color: rgba(74, 222, 128, 0.25); }

/* Tool execution card */
.tool-block {
  margin: 0.4rem 0; padding: 0.45rem 0.65rem;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.82rem;
}
.tool-header {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.tool-name { color: var(--accent); font-weight: 600; }
.tool-toggle-icon { font-size: 0.75rem; color: var(--text2); }
.tool-output {
  max-height: 160px; overflow-y: auto; overflow-x: hidden;
  font-family: var(--mono); font-size: 0.76rem;
  white-space: pre-wrap; margin-top: 0.35rem; padding-top: 0.25rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  color: var(--text2); line-height: 1.35;
}

.thinking-block {
  margin: 0.35rem 0; padding: 0.4rem 0.6rem;
  border-left: 2px solid var(--purple); background: rgba(168, 85, 247, 0.08);
  color: var(--text2); font-style: italic; font-size: 0.8rem;
  max-height: 120px; overflow-y: auto; border-radius: 0 6px 6px 0;
}

/* --- Floating Navigation Arrows --- */
#chat-nav-overlay {
  position: absolute; right: 12px; bottom: 120px;
  display: flex; flex-direction: column; gap: 6px; z-index: 15;
}
.nav-arrow {
  width: 38px; height: 38px; border-radius: 19px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); font-size: 0.95rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5); opacity: 0.88;
  transition: opacity 0.15s, transform 0.1s;
}
.nav-arrow:active { opacity: 1; transform: scale(0.92); background: var(--bg3); }

/* --- Attachment Strip --- */
.attachment-strip {
  display: flex; gap: 8px; padding: 0.5rem 0.75rem;
  background: var(--bg2); border-top: 1px solid var(--border);
  overflow-x: auto; flex-shrink: 0;
}
.attachment-thumb {
  position: relative; width: 54px; height: 54px; border-radius: 8px;
  border: 1px solid var(--border); overflow: hidden; flex-shrink: 0;
}
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment-remove {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  border-radius: 9px; background: rgba(0,0,0,0.75); color: #fff;
  border: none; font-size: 11px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* --- Composer --- */
#chat-composer {
  border-top: 1px solid var(--border); background: var(--bg2);
  padding-bottom: var(--safe-bottom); flex-shrink: 0;
}

/* Claude-style Control Row */
.control-row {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.6rem; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.hist-controls {
  display: flex; align-items: center; gap: 2px; margin-left: auto;
}
.hist-btn {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text2); border-radius: 4px; padding: 2px 6px;
  font-size: 0.68rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.hist-btn:active { background: var(--bg3); color: var(--text); }
.control-col {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 6px; min-width: 0;
}
.control-col label {
  font-size: 0.65rem; font-weight: 700; color: var(--text2);
}
.control-col select {
  background: var(--bg) !important;
  border: none;
  color: #f0f2ff !important;
  font-size: 0.78rem;
  font-weight: 500;
  outline: none;
  width: 100%;
  cursor: pointer;
}
.control-col select option,
select option {
  background-color: #12131c !important;
  color: #f0f2ff !important;
  padding: 6px 10px;
}
.env-col { flex: 1; }
.model-col { flex: 1.4; }

.btn-meet-pill {
  background: #059669;
  color: #fff;
  border: 1px solid #10b981;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-meet-pill:hover {
  background: #047857;
}

.mode-pill {
  display: flex; align-items: center; gap: 4px; padding: 4px 8px;
  border-radius: 12px; font-size: 0.72rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  cursor: pointer; flex-shrink: 0; transition: background 0.15s;
}
.mode-pill.queue { border-color: var(--accent2); color: var(--accent); }
.mode-pill.steer { border-color: var(--orange); color: var(--orange); }
.mode-pill.hands-free { border-color: #38bdf8; color: #38bdf8; }
.mode-pill.hands-free.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: #38bdf8;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}
.voice-status-banner {
  background: rgba(56, 189, 248, 0.12);
  border-bottom: 1px solid rgba(56, 189, 248, 0.25);
  color: #38bdf8;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 10;
}
.pulse-dot {
  color: #38bdf8;
  animation: pulse-mic 1.2s infinite;
}
.mode-indicator { font-size: 8px; }

/* Input Row */
.input-row {
  display: flex; gap: 0.35rem; padding: 0.4rem 0.6rem;
  align-items: flex-end;
}
.action-btn {
  width: 40px; height: 40px; border-radius: 20px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); font-size: 1.1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.action-btn:active { background: var(--bg3); }
.mic-btn.active {
  background: var(--red); color: #fff; border-color: var(--red);
  animation: pulse-mic 1.2s infinite;
}
@keyframes pulse-mic {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6); }
  70% { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}

#chat-input {
  flex: 1; padding: 0.65rem 0.85rem; background: var(--bg);
  color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; font-size: 0.95rem; resize: none;
  outline: none; max-height: 120px; min-height: 40px;
  font-family: var(--font); line-height: 1.4;
}
#chat-input:focus { border-color: var(--accent); }

.send-btn, .stop-btn {
  width: 42px; height: 42px; border: none; border-radius: 21px;
  font-size: 1.05rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.send-btn { background: var(--accent2); color: #fff; }
.stop-btn { background: var(--red); color: #fff; }
.send-btn:active, .stop-btn:active { opacity: 0.8; }
.send-btn[hidden], .stop-btn[hidden] { display: none !important; }

.status {
  padding: 0 0.75rem 0.35rem; font-size: 0.75rem; color: var(--text2);
  min-height: 1.2em; display: flex; justify-content: space-between;
}

/* --- Fullscreen Voice Assistant HUD --- */
.voice-hud {
  position: fixed; inset: 0; z-index: 250;
  background: radial-gradient(circle at center, #131d2a 0%, #080a0d 100%);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 1.5rem 1rem calc(1.5rem + var(--safe-bottom));
}
.voice-hud[hidden] { display: none !important; }

.voice-hud-header {
  display: flex; align-items: center; justify-content: space-between;
}
.voice-badge {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; background: rgba(56, 189, 248, 0.15);
  color: var(--accent); padding: 4px 10px; border-radius: 12px;
}

.voice-orb-container {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; margin: auto 0;
}
.voice-orb {
  position: relative; width: 140px; height: 140px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  cursor: pointer; margin-bottom: 1.5rem;
}
.orb-core {
  font-size: 3rem; z-index: 2;
}
.orb-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0;
}
.voice-orb.listening .orb-ring {
  animation: orb-pulse 2s infinite ease-out;
}
.voice-orb.listening .ring-2 { animation-delay: 0.6s; }
.voice-orb.listening .ring-3 { animation-delay: 1.2s; }

.voice-orb.thinking .orb-core { animation: spin 2s infinite linear; }
.voice-orb.speaking .orb-ring {
  border-color: var(--green);
  animation: orb-pulse 1.2s infinite ease-out;
}

@keyframes orb-pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.voice-hud-status {
  font-size: 1rem; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em; text-align: center;
}

.voice-transcript-box {
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: 14px; padding: 1rem; margin: 1rem 0; min-height: 120px;
  max-height: 180px; overflow-y: auto; text-align: center;
}
.voice-live-text {
  font-size: 1.05rem; line-height: 1.4; color: #fff; font-weight: 500;
}
.voice-last-reply {
  font-size: 0.88rem; color: var(--text2); margin-top: 0.5rem; font-style: italic;
}

.voice-hud-footer {
  display: flex; gap: 0.75rem; justify-content: center;
}
.voice-control-btn {
  padding: 0.75rem 1.25rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font-size: 0.9rem;
  font-weight: 600; cursor: pointer; min-height: 48px;
}
.voice-control-btn.active {
  background: var(--accent2); color: #fff; border-color: var(--accent2);
}

/* --- Dialogs --- */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.dialog {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.25rem; width: 100%; max-width: 360px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.8);
}
.dialog h3 { font-size: 1.1rem; margin-bottom: 0.85rem; font-weight: 600; }
.dialog input, .dialog select, .dialog textarea {
  width: 100%; padding: 0.7rem; margin-bottom: 0.75rem;
  background: var(--bg); color: #f0f2ff; border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.9rem; outline: none;
}
.dialog select option {
  background-color: #12131c !important;
  color: #f0f2ff !important;
}
.dialog .actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }
.dialog .actions button, .btn-sm {
  padding: 0.55rem 1rem; border: none; border-radius: 8px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.btn-primary, .dialog .btn-primary { background: var(--accent2); color: #fff; }
.btn-cancel, .dialog .btn-cancel { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }

/* Scrollbars */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
