:root {
  color-scheme: dark;
  --bg-0: #0b0f14;
  --bg-1: #111822;
  --bg-2: #172030;
  --bg-3: #1f2a3d;
  --line: rgba(148, 163, 184, 0.14);
  --text: #e8eef7;
  --text-muted: #94a3b8;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.12);
  --user: #243047;
  --nova: #152238;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(94, 234, 212, 0.08), transparent 60%),
              radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.06), transparent 55%),
              var(--bg-0);
  color: var(--text);
  font-family: var(--font);
}

button, textarea { font: inherit; }

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(10px);
  z-index: 10;
  flex-shrink: 0;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(94, 234, 212, 0.55);
}

.brand h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.05rem;
  letter-spacing: 0.28em;
  font-weight: 600;
}

.brand-sub {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.account-menu {
  position: relative;
}

.account-btn {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-size: 0.82rem;
}

.account-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-1);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 20;
}

.account-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}

.account-item:hover {
  background: var(--accent-dim);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-pill[data-state="ok"] .status-dot { background: var(--ok); box-shadow: 0 0 10px rgba(52, 211, 153, 0.55); }
.status-pill[data-state="degraded"] .status-dot { background: var(--warn); }
.status-pill[data-state="down"] .status-dot { background: var(--danger); }

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 1rem 0.75rem;
  background: rgba(17, 24, 34, 0.72);
  overflow-y: auto;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.72rem 0.85rem;
  margin-bottom: 0.35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.nav-item.active {
  color: var(--text);
  background: var(--accent-dim);
  border-color: rgba(94, 234, 212, 0.22);
}

.nav-item.soon {
  opacity: 0.7;
}

.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}

.section-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: none;
}

.section-panel:not(.hidden) {
  display: flex;
  flex-direction: column;
}

.chat-section {
  display: none;
  flex-direction: column;
  min-height: 0;
}

.chat-section:not(.hidden) {
  display: flex;
}

.panel-banner {
  flex-shrink: 0;
  margin: 0.75rem 1rem 0;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: #fecaca;
  font-size: 0.92rem;
}

.state-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.75rem 1rem 0;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  background: rgba(94, 234, 212, 0.08);
  border: 1px solid rgba(94, 234, 212, 0.18);
  color: #ccfbf1;
  font-size: 0.9rem;
}

.state-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(94, 234, 212, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

.transcript {
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem 1.25rem 1.25rem;
  scroll-behavior: smooth;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.welcome-card {
  max-width: 680px;
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(31, 42, 61, 0.65), rgba(23, 32, 48, 0.55));
  box-shadow: var(--shadow);
}

.welcome-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.05rem;
}

.welcome-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.55;
}

.msg {
  display: grid;
  gap: 0.35rem;
  max-width: 860px;
  margin-bottom: 1rem;
  animation: fadeUp 0.25s ease;
}

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

.msg-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.msg-badge {
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.68rem;
}

.msg-body {
  padding: 0.95rem 1.05rem;
  border-radius: var(--radius);
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .msg-body { background: var(--user); border: 1px solid rgba(148, 163, 184, 0.12); }
.msg.assistant .msg-body { background: var(--nova); border: 1px solid rgba(94, 234, 212, 0.12); }

.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 0.85rem 1.25rem calc(1rem + env(safe-area-inset-bottom, 0px));
  background: rgba(11, 15, 20, 0.92);
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

#message-input {
  width: 100%;
  resize: none;
  min-height: 46px;
  max-height: 180px;
  padding: 0.8rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
}

#message-input:focus {
  outline: none;
  border-color: rgba(94, 234, 212, 0.45);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.12);
}

.msg-timing {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.voice-call-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.55rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(94, 234, 212, 0.2);
  background: rgba(94, 234, 212, 0.06);
  font-size: 0.82rem;
}

.voice-call-state {
  color: var(--accent);
  font-weight: 600;
}

.voice-call-timing {
  color: var(--text-muted);
}

#call-btn.active {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

.composer-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 0.65rem 0.95rem;
  cursor: pointer;
}

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

.primary-btn {
  background: linear-gradient(180deg, rgba(94, 234, 212, 0.18), rgba(94, 234, 212, 0.08));
  border-color: rgba(94, 234, 212, 0.35);
}

.icon-btn {
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn.active {
  background: rgba(94, 234, 212, 0.18);
  border-color: rgba(94, 234, 212, 0.45);
  color: var(--accent);
}

.composer-meta {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.55rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.link-btn {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.level-meter {
  margin-top: 0.55rem;
  height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  overflow: hidden;
}

#level-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(94, 234, 212, 0.5), var(--accent));
  transition: width 80ms linear;
}

.hidden { display: none !important; }

.placeholder-section {
  padding: 1.25rem;
}

.placeholder-section:not(.hidden) {
  display: flex;
}

.placeholder-card {
  max-width: 640px;
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(31, 42, 61, 0.65), rgba(23, 32, 48, 0.55));
}

.placeholder-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.05rem;
}

.placeholder-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ===== Tasks ===== */
.tasks-section {
  display: none;
  flex-direction: column;
  min-height: 0;
  padding: 1rem 1.25rem 1.25rem;
  gap: 0.85rem;
}

.tasks-section:not(.hidden) {
  display: flex;
}
.tasks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.tasks-header h2 { margin: 0; font-size: 1.15rem; letter-spacing: 0.04em; }
.task-counts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}
.task-count-card {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  text-align: left;
  cursor: pointer;
}
.task-count-card strong { display: block; font-size: 1.25rem; color: var(--accent); }
.task-count-card span { color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
.task-count-card.active { border-color: rgba(94, 234, 212, 0.4); background: var(--accent-dim); }
.tasks-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}
.tasks-toolbar input,
.tasks-toolbar select,
#task-form input,
#task-form textarea,
#task-form select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}
.tasks-toolbar input { flex: 1 1 180px; min-width: 140px; }
.task-status-line {
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(94, 234, 212, 0.25);
  background: rgba(94, 234, 212, 0.08);
  color: #ccfbf1;
  font-size: 0.9rem;
}
.task-list {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  display: grid;
  gap: 0.65rem;
  align-content: start;
}
.task-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(31, 42, 61, 0.7), rgba(23, 32, 48, 0.55));
  cursor: pointer;
}
.task-card.overdue { border-color: rgba(248, 113, 113, 0.45); }
.task-card.done { opacity: 0.72; }
.task-check {
  width: 22px;
  height: 22px;
  margin-top: 0.15rem;
  accent-color: var(--accent);
}
.task-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}
.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.task-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.task-pill.high, .task-pill.urgent { border-color: rgba(251, 191, 36, 0.45); color: #fde68a; }
.task-pill.overdue { border-color: rgba(248, 113, 113, 0.45); color: #fecaca; }
.task-empty {
  color: var(--text-muted);
  padding: 2rem 1rem;
  text-align: center;
}
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 40;
}
.modal-card {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem 1.15rem;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}
.modal-head h3 { margin: 0; }
#task-form { display: grid; gap: 0.7rem; }
#task-form label { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.65rem;
}
.modal-actions { display: flex; gap: 0.55rem; justify-content: flex-end; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; min-height: 0; }
  .sidebar {
    display: flex;
    overflow-x: auto;
    gap: 0.35rem;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }
  .nav-item { width: auto; white-space: nowrap; margin: 0; }
  .task-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tasks-section { padding: 0.85rem; }
  .composer { padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px)); }
}

