:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1a1f29;
  --muted: #667085;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --today: #fffbea;
  --weekend: #fafbfc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --radius: 10px;
  --col-w: 200px;
  --date-w: 88px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
    --text: #e6e8ec; --muted: #9aa3b2; --accent: #6b9cff; --accent-soft: #1d2a45;
    --danger: #f87171; --ok: #4ade80; --ok-soft: #15291d; --warn: #fbbf24; --warn-soft: #2d2412;
    --today: #262414; --weekend: #14171d; --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
  --text: #e6e8ec; --muted: #9aa3b2; --accent: #6b9cff; --accent-soft: #1d2a45;
  --danger: #f87171; --ok: #4ade80; --ok-soft: #15291d; --warn: #fbbf24; --warn-soft: #2d2412;
  --today: #262414; --weekend: #14171d; --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* header */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.nav a:hover { text-decoration: none; background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
main.wide { max-width: none; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; min-height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=url], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); min-height: 38px;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .title { font-weight: 600; font-size: 16px; margin: 0 6px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* grid */
.grid-wrap {
  overflow: auto; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px);
}
table.grid { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.grid th, .grid td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); vertical-align: top; }
.grid thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface);
  padding: 10px; min-width: var(--col-w); width: var(--col-w); text-align: left; font-weight: 600;
}
.grid thead th a { color: var(--text); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid thead th .sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.grid th.corner { left: 0; z-index: 4; min-width: var(--date-w); width: var(--date-w); }
.grid tbody th {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  padding: 8px 10px; text-align: left; font-weight: 500; white-space: nowrap; min-width: var(--date-w);
}
.grid tbody th .dow { font-size: 12px; color: var(--muted); font-weight: 400; display: block; }
.grid tr.sun th .dow, .grid tr.sun th .d { color: #dc2626; }
.grid tr.sat th .dow, .grid tr.sat th .d { color: #2563eb; }
.grid tr.weekend td { background: var(--weekend); }
.grid tr.today td, .grid tr.today th { background: var(--today); }
.grid tr.today th .d::after { content: " 오늘"; font-size: 11px; color: var(--warn); font-weight: 700; }
.grid td.cell { padding: 6px; height: 56px; cursor: pointer; }
.grid td.cell:hover { background: var(--surface-2); }
.grid td.cell .add-hint { display: none; color: var(--muted); font-size: 12px; text-align: center; padding-top: 6px; }
.grid td.cell:hover .add-hint { display: block; }
.grid td.cell:has(.chip):hover .add-hint { display: none; }
.empty-grid { padding: 40px; text-align: center; }

.chip {
  display: flex; align-items: flex-start; gap: 6px; padding: 5px 8px; margin-bottom: 4px;
  border-radius: 7px; background: var(--accent-soft); font-size: 13px; line-height: 1.35; cursor: pointer;
  border: 1px solid transparent;
}
.chip:hover { border-color: var(--accent); }
.chip input { margin: 1px 0 0; width: 15px; height: 15px; flex: none; cursor: pointer; }
.chip .t { font-variant-numeric: tabular-nums; color: var(--muted); flex: none; }
.chip .ttl { overflow-wrap: anywhere; }
.chip.done { background: var(--ok-soft); }
.chip.done .ttl { text-decoration: line-through; color: var(--muted); }
.chip.overdue { background: var(--warn-soft); }
.chip .by { font-size: 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 3px; flex: none; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }
.page-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 16px; }
.page-title h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.cols { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

.meta { font-size: 12px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.item { display: flex; gap: 10px; align-items: flex-start; }
.item .main { flex: 1; min-width: 0; }
.item .main .ttl { font-weight: 500; overflow-wrap: anywhere; }
.item .main .desc { font-size: 13px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.item .acts { display: flex; gap: 4px; flex: none; }
.item input[type=checkbox] { width: 18px; height: 18px; margin-top: 3px; flex: none; }
.item.done .ttl { text-decoration: line-through; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 4px; font-weight: 500; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
code.box {
  display: block; padding: 10px; background: var(--surface-2); border-radius: 8px;
  font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* modal */
.modal-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 17, 21, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); padding: 20px;
}
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal .foot { display: flex; gap: 8px; margin-top: 8px; align-items: center; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

/* auth */
.auth { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.auth h1 { font-size: 24px; margin: 0 0 4px; }
.auth p { color: var(--muted); margin: 0 0 20px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

@media (max-width: 640px) {
  :root { --col-w: 150px; --date-w: 64px; }
  main { padding: 12px; }
  .brand { display: none; }
  .nav { margin-left: 0; width: 100%; justify-content: space-between; }
  .nav a { flex: 1; text-align: center; padding: 6px 4px; }
  .grid-wrap { max-height: calc(100dvh - 170px); }
  .row.wrap-sm { flex-direction: column; gap: 0; }
}
