:root {
  --bg: #060b14;
  --bg-panel: rgba(13, 25, 44, 0.78);
  --bg-card: rgba(17, 34, 60, 0.85);
  --border: rgba(56, 189, 248, 0.22);
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.16);
  --amber: #f59e0b;
  --green: #34d399;
  --red: #f87171;
  --text: #e2e8f0;
  --muted: #94a3b8;
}

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

html, body {
  height: 100%;
  background: radial-gradient(circle at top center, #0d213a 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Login */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  backdrop-filter: blur(14px);
  box-shadow: 0 0 50px rgba(34, 211, 238, 0.12);
}

.login-card h1 {
  margin-top: 14px;
  letter-spacing: 0.24em;
  color: var(--cyan);
  font-size: 1.5rem;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 22px;
}

#pin-input {
  background: rgba(6, 11, 20, 0.85);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  text-align: center;
  letter-spacing: 0.12em;
}

#pin-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-soft);
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4, #0284c7);
  color: #04101d;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  cursor: pointer;
}

.error-text {
  color: var(--red);
  margin-top: 12px;
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  height: 58px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 11, 20, 0.88);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

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

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

.brand-title {
  display: block;
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 0.98rem;
  color: var(--cyan);
}

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

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

.toggle-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 0.95rem;
}

.icon-btn:hover {
  border-color: var(--cyan);
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: 310px;
  border-right: 1px solid var(--border);
  background: rgba(8, 16, 30, 0.75);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

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

.panel h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--cyan);
  margin-bottom: 8px;
}

.panel-header h3 {
  margin-bottom: 0;
}

.count-pill {
  background: var(--cyan-soft);
  color: var(--cyan);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.select-input {
  width: 100%;
  background: rgba(6, 11, 20, 0.9);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.84rem;
}

.meta-badge {
  margin-top: 8px;
  font-size: 0.74rem;
  color: var(--muted);
}

.item-list, .plugin-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  background: rgba(6, 11, 20, 0.65);
  border: 1px solid rgba(56, 189, 248, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.item-row.completed .item-text {
  text-decoration: line-through;
  opacity: 0.55;
}

.item-meta {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

.mini-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
}

.mini-btn:hover {
  color: var(--red);
}

.plugin-row {
  background: rgba(6, 11, 20, 0.65);
  border: 1px solid rgba(56, 189, 248, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
}

.plugin-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}

.plugin-desc {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 3px;
}

.badge {
  font-size: 0.66rem;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
}

.badge.active { background: rgba(52, 211, 153, 0.18); color: var(--green); }
.badge.standby { background: rgba(56, 189, 248, 0.18); color: var(--cyan); }
.badge.ready_for_setup { background: rgba(245, 158, 11, 0.18); color: var(--amber); }

/* Main Stage */
.main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.hud-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 16px 8px;
  flex-shrink: 0;
}

/* Arc Reactor Voice Orb */
.orb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.orb.small {
  width: 72px;
  height: 72px;
  cursor: default;
}

.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--cyan);
}

.orb-ring.outer {
  inset: 0;
  border-style: dashed;
  opacity: 0.65;
  animation: spin 16s linear infinite;
}

.orb-ring.inner {
  inset: 10px;
  border-width: 3px;
  opacity: 0.85;
  animation: spin-rev 9s linear infinite;
}

.orb-core {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle, #e0f2fe 0%, var(--cyan) 55%, rgba(8, 145, 178, 0.1) 100%);
  box-shadow: 0 0 26px var(--cyan);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.orb.listening .orb-core {
  background: radial-gradient(circle, #fef3c7 0%, var(--amber) 60%, rgba(245, 158, 11, 0.1) 100%);
  box-shadow: 0 0 36px var(--amber);
  animation: pulse 0.9s ease-in-out infinite;
}

.orb.listening .orb-ring { border-color: var(--amber); }

.orb.thinking .orb-ring.outer { animation-duration: 2s; }
.orb.thinking .orb-ring.inner { animation-duration: 1.4s; }

.orb.speaking .orb-core {
  animation: pulse 0.6s ease-in-out infinite;
}

.orb-label {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes spin-rev { from { transform: rotate(360deg); } to { transform: rotate(0deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* Chat */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 780px;
  padding: 12px 15px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 0.94rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.22), rgba(2, 132, 199, 0.28));
  border: 1px solid rgba(34, 211, 238, 0.35);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-panel);
  border: 1px solid var(--border);
}

.tool-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.tool-badge {
  font-size: 0.7rem;
  color: var(--cyan);
  background: var(--cyan-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.quick-prompts {
  display: flex;
  gap: 8px;
  padding: 6px 16px;
  overflow-x: auto;
  flex-shrink: 0;
}

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  white-space: nowrap;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(6, 11, 20, 0.92);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
}

.mic-btn.active {
  border-color: var(--amber);
  background: rgba(245, 158, 11, 0.2);
}

#chat-input {
  flex: 1;
  background: rgba(13, 25, 44, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

#chat-input:focus {
  border-color: var(--cyan);
}

.send-btn {
  background: linear-gradient(135deg, #22d3ee, #0284c7);
  border: none;
  color: #04101d;
  font-weight: 700;
  border-radius: 12px;
  padding: 0 18px;
  cursor: pointer;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mobile-only {
  display: none;
}

@media (max-width: 860px) {
  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    width: 84vw;
    max-width: 320px;
    background: rgba(6, 11, 20, 0.97);
  }

  .sidebar.open {
    transform: translateX(0);
  }
}
