:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f6feb;
  --accent-fg: #ffffff;
  --danger: #c0392b;
  --card: #f9fafb;
}
/* Telegram이 알려주는 colorScheme 기반으로 명시적 light/dark — prefers-color-scheme보다 우선 */
body.light {
  --bg: var(--tg-bg, #ffffff);
  --fg: var(--tg-fg, #111111);
  --muted: var(--tg-hint, #6b7280);
  --line: var(--tg-section-separator, #e5e7eb);
  --accent: var(--tg-button, #1f6feb);
  --accent-fg: var(--tg-button-text, #ffffff);
  --card: var(--tg-section-bg, #f9fafb);
  --danger: #c0392b;
}
body.dark {
  --bg: var(--tg-bg, #0e0e10);
  --fg: var(--tg-fg, #f5f5f5);
  --muted: var(--tg-hint, #9ca3af);
  --line: var(--tg-section-separator, #2a2a2e);
  --accent: var(--tg-button, #4c8bf5);
  --accent-fg: var(--tg-button-text, #ffffff);
  --card: var(--tg-section-bg, #18181b);
  --danger: #ef6b5d;
}
@media (prefers-color-scheme: dark) {
  body:not(.light):not(.dark) {
    --bg: #0e0e10; --fg: #f5f5f5; --muted: #9ca3af; --line: #2a2a2e;
    --accent: #4c8bf5; --accent-fg: #ffffff; --danger: #ef6b5d; --card: #18181b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar .title { font-size: 17px; font-weight: 700; }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}
button.danger { color: var(--danger); border-color: var(--line); background: transparent; }

.list { padding: 12px 16px 80px; display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.card .row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card .name { font-weight: 600; font-size: 16px; word-break: break-word; }
.card .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; word-break: break-word; }
.card .memo { margin-top: 6px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.card .actions { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }
.card .actions button { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.card .tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; border: 1px solid var(--line); color: var(--muted);
  margin-right: 6px;
}
.card .tag.high { color: var(--danger); border-color: var(--danger); }
.card .name .tag-urgent { color: #ef4444; font-weight: 700; }
.card .name .tag-important { color: #f59e0b; font-weight: 700; }
.card a { color: var(--accent); text-decoration: none; }
.card a:hover { text-decoration: underline; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--fg);
  padding: 0;
  max-width: 92vw;
  width: 420px;
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog form { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog input, dialog textarea, dialog select {
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
dialog textarea { resize: vertical; }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

.loading { padding: 32px; text-align: center; color: var(--muted); }
.error { padding: 16px; color: var(--danger); text-align: center; }
