:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --info-bg: #dbeafe;
  --info-text: #1e3a8a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2a2f37;
    --accent: #3b82f6;
    --danger: #f87171;
    --error-bg: #3b1515;
    --error-text: #fecaca;
    --info-bg: #172554;
    --info-text: #bfdbfe;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 32px 16px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.layout {
  display: grid;
  gap: 24px;
  max-width: 600px;
  margin: 0 auto;
}

.card {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1 { margin: 0; font-size: 1.5rem; }

.docs-link { color: var(--muted); font-size: 0.875rem; }

input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.6; cursor: wait; }

.add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.add-form #description { grid-column: 1; }
.add-form button { grid-column: 2; grid-row: 1 / span 2; }

.banner {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
}

.banner.error { background: var(--error-bg); color: var(--error-text); }
.banner.info { background: var(--info-bg); color: var(--info-text); }

.filters {
  display: flex;
  gap: 6px;
  margin: 20px 0 8px;
}

.filters button { padding: 4px 12px; font-size: 0.875rem; }
.filters button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.todo-list { list-style: none; margin: 0; padding: 0; }

.todo {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.todo:last-child { border-bottom: none; }

.toggle { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.title { overflow-wrap: anywhere; }
.description { color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
.description:empty { display: none; }

.todo.done .title { text-decoration: line-through; color: var(--muted); }

.actions { display: flex; gap: 6px; flex-shrink: 0; }
.actions button { padding: 4px 10px; font-size: 0.875rem; }

.empty { color: var(--muted); text-align: center; margin: 24px 0 8px; }

h2 { margin: 0; font-size: 1.25rem; }
.hint { margin: 4px 0 12px; color: var(--muted); font-size: 0.875rem; }

.assistant { display: flex; flex-direction: column; }

.assistant iframe {
  display: block;
  width: 100%;
  height: max(560px, 80vh);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

/* Wide screens: todos on the left, a full-height chat on the right. */
@media (min-width: 1000px) {
  .layout {
    max-width: 1400px;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    align-items: start;
  }

  body { padding: 24px; }

  .assistant {
    position: sticky;
    top: 24px;
    /* Fill the window, but never shrink the chat below a usable size on short screens. */
    height: max(640px, calc(100vh - 48px));
  }

  .assistant iframe { flex: 1; height: auto; min-height: 0; }
}

@media (max-width: 480px) {
  body { padding: 16px; }
  .card { padding: 16px; }
  .add-form { grid-template-columns: 1fr; }
  .add-form button { grid-column: 1; grid-row: auto; }
  .todo { flex-wrap: wrap; }
  .actions { width: 100%; justify-content: flex-end; }
  .assistant iframe { height: 85vh; }
}
