/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111113;
  --bg-card: #1a1a1f;
  --bg-hover: #222228;
  --bg-input: #1e1e24;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --border: #27272a;
  --accent: #22c55e;
  --accent-dim: #166534;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --purple: #a855f7;
  --teal: #14b8a6;
  --pink: #ec4899;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  padding: 0 16px;
  padding-top: calc(var(--safe-top) + 12px);
  padding-bottom: calc(var(--safe-bottom) + 80px);
}

/* ---- Header ---- */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 0 8px;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 600; }

.header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.icon-btn:active { background: var(--bg-hover); }

.header-stats {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px;
  font-size: 13px; color: var(--text-muted);
}
.stat-sep { color: var(--text-dim); }

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); opacity: 0.8;
  animation: pulse 2s ease-in-out infinite;
  margin-left: auto;
}
.live-dot.disconnected { background: var(--red); animation: none; }
@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---- Panels ---- */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 10px 0;
  animation: slideDown 0.2s ease-out;
}
.panel.hidden { display: none; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

#quick-add { display: flex; gap: 8px; flex-wrap: wrap; }
#quick-add.hidden { display: none; }
#add-input { flex: 1; min-width: 180px; }

input, textarea, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }
select { font-size: 13px; padding: 8px 6px; width: auto; }

button { cursor: pointer; font-family: inherit; }

.btn-primary, #add-submit, #transcript-submit, #proj-submit {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  transition: opacity 0.15s;
  width: auto;
}
.btn-primary:active, #add-submit:active, #transcript-submit:active { opacity: 0.8; }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.panel-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
#transcript-status { font-size: 12px; color: var(--text-muted); }

.text-btn {
  background: none; border: none;
  color: var(--accent);
  font-size: 14px; font-weight: 500;
  padding: 4px 8px;
}

/* ---- Project add form ---- */
#project-add-form {
  display: flex; flex-direction: column; gap: 8px;
}

/* ---- Category sections ---- */
.category-section { margin-top: 16px; }

.category-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.category-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-work-immediate .category-dot { background: var(--red); }
.cat-work-week .category-dot { background: var(--amber); }
.cat-work-projects .category-dot { background: var(--blue); }
.cat-work-tools .category-dot { background: var(--purple); }
.cat-personal .category-dot { background: var(--teal); }
.cat-someday .category-dot { background: var(--text-dim); }

/* ---- Todo items ---- */
.todo-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s, opacity 0.3s;
}
.todo-item:last-child { border-bottom: none; }
.todo-item:active { background: var(--bg-hover); }

.todo-check {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer; flex-shrink: 0; margin-top: 1px;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 12px;
}
.todo-check:active { border-color: var(--accent); background: var(--accent-dim); }

.todo-body { flex: 1; min-width: 0; }
.todo-text { font-size: 15px; line-height: 1.45; }
.todo-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }
.todo-deadline { font-size: 11px; color: var(--amber); }
.todo-source { font-size: 11px; color: var(--text-dim); }

/* ---- Project badge on todos ---- */
.todo-project-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  color: var(--blue);
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 4px;
  padding: 1px 6px;
}

/* ---- Dispatch button ---- */
.todo-dispatch {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600;
  color: var(--purple);
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: 0.03em;
}
.todo-dispatch:active { background: rgba(168, 85, 247, 0.2); }

/* Completed items */
.todo-item.completed .todo-check {
  border-color: var(--accent); background: var(--accent); color: #000;
}
.todo-item.completed .todo-text {
  text-decoration: line-through; color: var(--text-dim);
}

@keyframes flash-in {
  from { background: var(--accent-dim); }
  to { background: transparent; }
}
.todo-item.just-added { animation: flash-in 1.5s ease-out; }

/* ---- Projects list ---- */
.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
}
.project-card-name {
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.project-card-meta {
  font-size: 12px; color: var(--text-muted);
  margin-top: 4px;
}
.project-card-links {
  display: flex; gap: 8px; margin-top: 8px;
}
.project-card-links a {
  font-size: 12px; color: var(--blue);
  text-decoration: none;
}
.project-card-links a:active { text-decoration: underline; }

/* ---- Prompt modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%; max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
  font-size: 14px; font-weight: 600; color: var(--purple);
}
#prompt-text {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 40vh;
  overflow-y: auto;
}
.modal-actions {
  display: flex; gap: 10px; margin-top: 14px;
}

/* ---- Section headers ---- */
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0 8px;
}

/* ---- Completed / Projects views ---- */
#completed-view.hidden, #projects-view.hidden { display: none; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%; transform: translateX(-50%);
  background: var(--accent);
  color: #000;
  font-size: 13px; font-weight: 500;
  padding: 8px 16px;
  border-radius: 20px;
  z-index: 100;
  animation: toast-in 0.3s ease-out;
  white-space: nowrap;
}
.toast.hidden { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-dim); font-size: 14px;
}
.empty-state span { display: block; font-size: 32px; margin-bottom: 12px; }

.hidden { display: none !important; }

@media (min-width: 600px) {
  #app { padding: 20px 24px; }
  h1 { font-size: 22px; }
}
