/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --border-strong: #cdd2de;

  --text: #161a26;
  --text-2: #4a5165;
  --text-muted: #6b7286;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --on-primary: #ffffff;
  --focus: #6366f1;

  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf3e2;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --danger: #c0262d;
  --danger-soft: #fdecec;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .12);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1119;
  --surface: #161a25;
  --surface-2: #1d2230;
  --border: #272d3d;
  --border-strong: #363e52;
  --text: #eef0f6;
  --text-2: #b9bfce;
  --text-muted: #8b92a5;
  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: #23264a;
  --on-primary: #10132b;
  --focus: #a5b4fc;
  --success: #4ade80;
  --success-soft: #12301f;
  --warning: #fbbf24;
  --warning-soft: #33270f;
  --info: #93b4ff;
  --info-soft: #1a2647;
  --danger: #f87171;
  --danger-soft: #3a1719;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1119;
    --surface: #161a25;
    --surface-2: #1d2230;
    --border: #272d3d;
    --border-strong: #363e52;
    --text: #eef0f6;
    --text-2: #b9bfce;
    --text-muted: #8b92a5;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #23264a;
    --on-primary: #10132b;
    --focus: #a5b4fc;
    --success: #4ade80;
    --success-soft: #12301f;
    --warning: #fbbf24;
    --warning-soft: #33270f;
    --info: #93b4ff;
    --info-soft: #1a2647;
    --danger: #f87171;
    --danger-soft: #3a1719;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 var(--space-4); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: var(--space-4); top: -48px;
  background: var(--primary); color: var(--on-primary);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); z-index: 10;
}
.skip-link:focus { top: var(--space-3); }

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

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-6);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); padding-top: var(--space-4); padding-bottom: var(--space-4);
}
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: var(--radius);
  background: var(--primary-soft); color: var(--primary); font-size: 22px;
}
.brand h1 { font-size: 1.25rem; line-height: 1.2; letter-spacing: -.01em; }
.tagline { font-size: .875rem; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: var(--space-2); flex: none; }

.api-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8125rem; color: var(--text-2);
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.api-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.api-status[data-state="ok"] .dot { background: var(--success); }
.api-status[data-state="error"] .dot { background: var(--danger); }
.api-status[data-state="checking"] .dot { animation: pulse 1.2s ease-in-out infinite; }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; font-size: 18px; color: var(--text-2);
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* ---------- Cards & sections ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.section-title { font-size: 1rem; font-weight: 650; letter-spacing: -.005em; }
.count { color: var(--text-muted); font-weight: 500; }

.composer { padding: var(--space-5); margin-bottom: var(--space-6); }
.composer .section-title { margin-bottom: var(--space-4); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-size: .875rem; font-weight: 600; color: var(--text-2); }
.optional { font-weight: 400; color: var(--text-muted); }

input[type="text"], input[type="search"], textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}
input[aria-invalid="true"] { border-color: var(--danger); }

.composer-footer {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap;
}
.field-inline { margin-bottom: 0; min-width: 160px; }

.form-error { margin-top: var(--space-3); color: var(--danger); font-size: .875rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 10px 18px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn-sm { padding: 6px 12px; font-size: .875rem; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.95); }

/* ---------- Toolbar ---------- */
.list-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4);
}
.toolbar-controls { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; width: 100%; }
.search { flex: 1 1 220px; width: auto; padding: 8px 12px; }

.filters { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 5px 12px; font-size: .8125rem; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* ---------- Notes ---------- */
.note-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }

.note { padding: var(--space-4) var(--space-5); transition: border-color .15s, box-shadow .15s; }
.note:hover { border-color: var(--border-strong); }
.note.is-busy { opacity: .6; pointer-events: none; }

.note-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.note-title { font-size: 1rem; font-weight: 650; line-height: 1.4; overflow-wrap: anywhere; }
.note[data-status="done"] .note-title { color: var(--text-muted); text-decoration: line-through; }

.note-body {
  margin-top: var(--space-1); color: var(--text-2); white-space: pre-wrap;
  overflow-wrap: anywhere; max-width: 65ch;
}
.note-body:empty { display: none; }

.note-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); margin-top: var(--space-3); flex-wrap: wrap;
}
.note-time { font-size: .8125rem; color: var(--text-muted); }
.note-actions { display: flex; gap: var(--space-1); }

.pill {
  flex: none; font-size: .75rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 10px; border-radius: 999px; text-transform: uppercase;
}
.pill[data-status="todo"]  { background: var(--info-soft); color: var(--info); }
.pill[data-status="doing"] { background: var(--warning-soft); color: var(--warning); }
.pill[data-status="done"]  { background: var(--success-soft); color: var(--success); }

/* Edit mode */
.note-edit .field { margin-bottom: var(--space-3); }
.note-edit .edit-footer { display: flex; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; }
.note-edit .edit-buttons { display: flex; gap: var(--space-2); }

/* Delete confirm */
.confirm {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  flex-wrap: wrap; margin-top: var(--space-3); padding: var(--space-3);
  background: var(--danger-soft); border-radius: var(--radius-sm); color: var(--danger); font-size: .875rem; font-weight: 600;
}
.confirm .edit-buttons { display: flex; gap: var(--space-2); }

/* Skeleton */
.skeleton { padding: var(--space-4) var(--space-5); }
.skeleton .bar {
  height: 12px; border-radius: 6px; background: var(--surface-2); margin-bottom: 10px;
  animation: pulse 1.4s ease-in-out infinite;
}
.skeleton .bar:nth-child(1) { width: 45%; height: 14px; }
.skeleton .bar:nth-child(2) { width: 85%; }
.skeleton .bar:nth-child(3) { width: 25%; margin-bottom: 0; }

/* Empty & banner */
.empty {
  text-align: center; padding: var(--space-7) var(--space-4);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); color: var(--text-muted);
}
.empty-icon { font-size: 32px; color: var(--primary); margin-bottom: var(--space-2); }
.empty-title { color: var(--text); font-weight: 650; margin-bottom: var(--space-1); }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius); margin-bottom: var(--space-4); font-size: .9375rem;
}
.banner-error { background: var(--danger-soft); color: var(--danger); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: var(--space-5); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow-lg); font-size: .9375rem; font-weight: 500; z-index: 20;
  max-width: calc(100% - 32px); text-align: center;
}
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* Footer */
.site-footer {
  margin-top: var(--space-7); padding-top: var(--space-5); padding-bottom: var(--space-6);
  border-top: 1px solid var(--border); font-size: .8125rem; color: var(--text-2);
  display: grid; gap: var(--space-1);
}

@keyframes pulse { 50% { opacity: .45; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  .tagline { display: none; }
  .api-status .label { display: none; }
  .composer { padding: var(--space-4); }
  .note { padding: var(--space-4); }
  .toolbar-controls, .search { width: 100%; }
  .composer-footer .btn { width: 100%; }
  .field-inline { width: 100%; }
}
