:root {
  --bg: #0b0f14;
  --bg-elev: #131922;
  --bg-card: #161d28;
  --border: #232c3b;
  --text: #e6edf5;
  --muted: #8a97aa;
  --accent: #5dc0ff;
  --accent-2: #7af7c8;
  --danger: #ff6b6b;
  --warn: #ffc857;
  --ok: #7af7c8;
  --radius: 12px;
  --shadow: 0 2px 16px rgba(0,0,0,0.25);
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  min-height: 100vh;
}

body {
  display: grid;
  grid-template-columns: 260px 1fr;
}

/* SIDEBAR */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  position: sticky;
  top: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #001520;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
}
.brand-name { font-weight: 700; letter-spacing: 1.5px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14.5px;
  font-family: inherit;
  display: flex;
  gap: 10px;
  align-items: center;
}
.nav-btn:hover { background: rgba(255,255,255,0.04); }
.nav-btn.active {
  background: rgba(93,192,255,0.12);
  color: var(--accent);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.health-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.health-dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.health-dot.bad { background: var(--danger); }

/* MAIN */
.main {
  padding: 32px 40px 80px;
  max-width: 1100px;
}
.view { display: none; }
.view.active { display: block; }
.view h1 {
  margin: 0 0 24px;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: 0.5px;
}
.view h2 {
  margin: 30px 0 14px;
  font-weight: 500;
  font-size: 18px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.view h3 {
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--accent);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* KPIs */
.grid.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.kpi-value { font-size: 32px; font-weight: 700; }
.kpi.danger .kpi-value { color: var(--danger); }
.kpi.success .kpi-value { color: var(--ok); }

/* Habit detail rows */
.habit-detail-list { display: flex; flex-direction: column; gap: 10px; }
.habit-detail-row {
  display: grid;
  grid-template-columns: 1fr 80px 140px;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.habit-detail-row:last-child { border-bottom: none; }
.bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.bar.low > span { background: var(--danger); }
.bar.mid > span { background: var(--warn); }

/* Forms */
.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.form-row input[type=text], .form-row input[type=date], .form-row select {
  flex: 1 1 180px;
}
input, select, textarea, button {
  font-family: inherit;
  font-size: 14.5px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
button {
  background: var(--accent);
  color: #001520;
  border: none;
  font-weight: 600;
  cursor: pointer;
  padding: 9px 18px;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button:hover { filter: brightness(1.08); }

.filter-row { padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; font-size: 13px; color: var(--muted); }

/* List */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: none; }
.list li.done .title { text-decoration: line-through; color: var(--muted); }
.title { flex: 1; }
.meta { color: var(--muted); font-size: 12px; }
.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid var(--border);
}
.pill.high { color: var(--danger); border-color: var(--danger); }
.pill.med { color: var(--warn); border-color: var(--warn); }
.pill.low { color: var(--ok); border-color: var(--ok); }
.streak {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 100px;
  background: rgba(122,247,200,0.12);
  color: var(--ok);
}
.btn-x {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 16px;
}
.btn-x:hover { color: var(--danger); }
.check {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.check.on {
  background: var(--ok);
  border-color: var(--ok);
  color: #001520;
}
.check.on::after { content: "✓"; font-weight: 800; }

/* Zones */
.zones-list { list-style: none; margin: 0; padding: 0; }
.zones-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
}
.zones-list li:last-child { border-bottom: none; }
.zones-list.big li { padding: 16px 8px; font-size: 15px; }
.sev {
  width: 8px; height: 36px;
  border-radius: 3px;
  background: var(--muted);
  flex-shrink: 0;
}
.sev.high { background: var(--danger); }
.sev.medium { background: var(--warn); }
.sev.low { background: var(--muted); }
.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* CHAT */
.chat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 70vh;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  padding-right: 6px;
}
.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.45;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #001520;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.msg.tool {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--accent-2);
  font-size: 12.5px;
  padding: 6px 10px;
  max-width: 90%;
}
.msg .src {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}
.msg.user .src { color: rgba(0, 21, 32, 0.65); }
.chat-form {
  display: flex;
  gap: 10px;
}
.chat-form textarea {
  flex: 1;
  resize: vertical;
}
.chat-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.tts-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
#chat-mic.recording {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,107,0.55); }
  50% { box-shadow: 0 0 0 8px rgba(255,107,107,0); }
}
.msg audio {
  display: block;
  margin-top: 6px;
  width: 100%;
  max-width: 320px;
}

/* SETTINGS */
.settings-card { display: flex; flex-direction: column; gap: 18px; }
.settings-list { padding-left: 18px; line-height: 1.7; }
.settings-card code {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.settings-card pre {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
}
.settings-card a { color: var(--accent); }

/* RESPONSIVE */
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    min-height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }
  .sidebar-foot { margin-left: auto; margin-top: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 20px; }
}
