:root {
  --bg: #171A23;
  --bg-elevated: #1F2330;
  --cream: #F2EDE4;
  --muted: #8A93A6;
  --amber: #E8944A;
  --amber-soft: rgba(232, 148, 74, 0.18);
  --teal: #4FA89B;
  --stuck: #D9636C;
  --border: #2A2F3E;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: 'Rubik', system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px calc(12px + env(safe-area-inset-top, 0px));
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--amber), #C96E2C);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 20px; color: #171A23;
}

.brand-text h1 { font-size: 18px; font-weight: 700; margin: 0; }
.brand-text p { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.icon-btn {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--cream);
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

.badge {
  position: absolute; top: -6px; left: -6px;
  background: var(--amber); color: #171A23;
  font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.badge:empty, .badge[data-zero="true"] { display: none; }

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 15px;
  animation: rise 0.25s ease;
}
.msg p { margin: 0; }

.msg.assistant {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg.user {
  background: var(--amber-soft);
  border: 1px solid rgba(232, 148, 74, 0.35);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg.thinking { color: var(--muted); font-style: italic; }

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

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#text-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
#text-input:focus { border-color: var(--amber); }

.send-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--amber);
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

.mic-orb {
  position: relative;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--amber), #C96E2C);
  border: none;
  color: #171A23;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(232, 148, 74, 0.35);
}

.mic-orb-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--amber);
  opacity: 0;
}

.mic-orb.listening .mic-orb-ring {
  opacity: 1;
  animation: pulse 1.4s ease-out infinite;
}
.mic-orb.listening {
  box-shadow: 0 4px 24px rgba(232, 148, 74, 0.6);
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Tasks sheet */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s ease;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
}

.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px 12px;
}
.sheet-header h2 { font-size: 16px; margin: 0; }

.tasks-list {
  overflow-y: auto;
  padding: 0 20px;
  display: flex; flex-direction: column; gap: 8px;
}

.task-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.task-title { flex: 1; font-size: 14px; }
.task-title.done { text-decoration: line-through; color: var(--muted); }

.status-pill {
  font-size: 11px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
}
.status-pill.open { background: var(--border); color: var(--cream); }
.status-pill.stuck { background: rgba(217, 99, 108, 0.2); color: var(--stuck); }
.status-pill.done { background: rgba(79, 168, 155, 0.2); color: var(--teal); }

.add-task-form {
  display: flex; gap: 8px;
  padding: 14px 20px;
}
.add-task-form input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--cream);
  padding: 10px 14px;
  border-radius: 12px;
  font-family: inherit;
}
.add-task-form button {
  background: var(--amber);
  color: #171A23;
  border: none;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 10;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
