:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --pri-1: #ef4444;
  --pri-2: #f97316;
  --pri-3: #eab308;
  --pri-4: #94a3b8;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== 설정 화면 ===== */
#setup {
  max-width: 480px;
  margin: 4rem auto;
  padding: 1.5rem;
}
#setup h1 { margin-top: 0; }
#setup label { display: block; margin: 1rem 0; color: var(--muted); font-size: .9rem; }
#setup input {
  width: 100%;
  padding: .8rem;
  margin-top: .3rem;
  border: 1px solid var(--bg-3);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 10px;
  font-size: 1rem;
}
#setup button {
  background: var(--accent); color: white; border: none;
  padding: .9rem 1.5rem; border-radius: 10px; font-size: 1rem; cursor: pointer;
}
.hint { font-size: .8rem; color: var(--muted); }

/* ===== 앱 레이아웃 ===== */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  height: 100dvh;
}
#app.detail-open { grid-template-columns: 240px 360px 1fr; }

#sidebar {
  background: #020617;
  border-right: 1px solid var(--bg-3);
  overflow-y: auto;
  padding-top: var(--safe-top);
}
#sidebar header {
  display: flex; align-items: center; gap: .5rem;
  padding: 1rem; border-bottom: 1px solid var(--bg-3);
}
#sidebar header h2 { margin: 0; font-size: 1.1rem; flex: 1; }
#menu-close { display: none; }
#sidebar nav { padding: .5rem; }
#sidebar nav a, #sidebar nav button.text-btn {
  display: block;
  padding: .6rem .8rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  background: transparent;
  border: none;
  font-size: .95rem;
  width: 100%; text-align: left;
  cursor: pointer;
}
#sidebar nav a:hover, #sidebar nav button.text-btn:hover { background: var(--bg-2); }
#sidebar nav a.active { background: var(--accent); color: white; }
#sidebar nav h3 {
  margin: 1rem .8rem .3rem;
  font-size: .75rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
#project-list { list-style: none; padding: 0; margin: 0; }
#project-list li a {
  display: flex; justify-content: space-between;
  padding: .5rem .8rem; color: var(--text);
  text-decoration: none; border-radius: 6px;
}
#project-list li a:hover { background: var(--bg-2); }
#project-list li a.active { background: var(--accent); color: white; }
#project-list .count { color: var(--muted); font-size: .8rem; }
#sidebar nav button#new-project-btn {
  margin: .5rem 0; padding: .5rem .8rem;
  background: transparent; border: 1px dashed var(--bg-3); color: var(--muted);
  border-radius: 6px; cursor: pointer; width: 100%; text-align: left;
  font-size: .85rem;
}
#sidebar nav hr { border: 0; border-top: 1px solid var(--bg-3); margin: 1rem 0; }

#list-pane, #detail-pane {
  overflow-y: auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
#list-pane { background: var(--bg); }
#detail-pane { background: var(--bg-2); border-left: 1px solid var(--bg-3); }

#list-pane header, #detail-pane header {
  display: flex; align-items: center; gap: .5rem;
  padding: .8rem 1rem;
  position: sticky; top: 0;
  background: inherit;
  border-bottom: 1px solid var(--bg-3);
  z-index: 5;
}
#list-pane header h1 { margin: 0; font-size: 1.2rem; flex: 1; }
#menu-open { display: none; }

.icon-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  width: 36px; height: 36px;
  font-size: 1rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-2); }

#quick-add { padding: .5rem 1rem; border-bottom: 1px solid var(--bg-3); }
#quick-add input {
  width: 100%; padding: .8rem 1rem;
  border: 1px solid var(--bg-3); background: var(--bg-2); color: var(--text);
  border-radius: 10px; font-size: 1rem;
}

/* ===== 태스크 리스트 ===== */
ul#task-list { list-style: none; padding: 0; margin: 0; }
li.task {
  display: flex; align-items: flex-start; gap: .7rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--bg-3);
  cursor: pointer;
  border-left: 4px solid transparent;
}
li.task:hover { background: var(--bg-2); }
li.task.selected { background: var(--bg-2); border-left-color: var(--accent); }
li.task.pri-1 { border-left-color: var(--pri-1); }
li.task.pri-2 { border-left-color: var(--pri-2); }
li.task.pri-3 { border-left-color: var(--pri-3); }
li.task.done { opacity: .45; }
li.task.done .title { text-decoration: line-through; }

li.task .check {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  cursor: pointer; margin-top: 2px;
}
li.task.done .check { background: var(--ok); border-color: var(--ok); }
li.task .body { flex: 1; min-width: 0; }
li.task .title { font-size: 1rem; line-height: 1.4; }
li.task .preview { color: var(--muted); font-size: .85rem; margin-top: .25rem;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden; }
li.task .row2 { display: flex; gap: .6rem; align-items: center; margin-top: .25rem; font-size: .75rem; color: var(--muted); }
li.task .tag { padding: .1rem .4rem; background: var(--bg-3); border-radius: 4px; }
li.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
li.empty.error { color: var(--danger); }

/* ===== 상세 패널 ===== */
#detail-pane header input.title-input {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-size: 1.15rem; font-weight: 500; padding: .3rem;
  border-radius: 6px;
}
#detail-pane header input.title-input:hover { background: var(--bg); }
#detail-pane header input.title-input:focus { background: var(--bg); outline: 1px solid var(--accent); }

.detail-meta {
  display: flex; gap: .5rem; padding: .6rem 1rem;
  border-bottom: 1px solid var(--bg-3); flex-wrap: wrap;
}
.detail-meta select {
  background: var(--bg); color: var(--text); border: 1px solid var(--bg-3);
  padding: .4rem .6rem; border-radius: 6px; font-size: .9rem;
}
.completed-toggle { display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.completed-toggle input { width: 18px; height: 18px; }

#detail-pane h3 {
  margin: 1rem 1rem .4rem; font-size: .8rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
#detail-pane h3 small { color: var(--muted); font-size: .75rem; text-transform: none; letter-spacing: 0; margin-left: .4rem; }

textarea#detail-memo {
  width: calc(100% - 2rem); margin: 0 1rem;
  min-height: 220px;
  padding: .8rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--bg-3); border-radius: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .9rem; line-height: 1.6;
  resize: vertical;
  white-space: pre-wrap;
}

ul#subtask-list { list-style: none; padding: 0; margin: .3rem 1rem 0; }
li.subtask {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .6rem; border-radius: 6px;
}
li.subtask:hover { background: var(--bg); }
li.subtask.done { opacity: .5; }
li.subtask.done .title { text-decoration: line-through; }
li.subtask input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; cursor: pointer; }
li.subtask .title { flex: 1; cursor: pointer; }
li.subtask button.sub-del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; padding: .2rem .4rem; border-radius: 4px;
  opacity: 0; transition: opacity .15s;
}
li.subtask:hover button.sub-del { opacity: 1; }
li.subtask button.sub-del:hover { color: var(--danger); background: var(--bg); }

form#subtask-add { padding: .5rem 1rem; }
form#subtask-add input {
  width: 100%; padding: .6rem;
  border: 1px dashed var(--bg-3); background: transparent; color: var(--text);
  border-radius: 6px; font-size: .9rem;
}

.status { padding: .4rem 1rem; font-size: .8rem; min-height: 1.4em; }
.status.ok { color: var(--ok); }
.status.pending { color: var(--warn); }
.status.err { color: var(--danger); }

/* ===== 모바일 ===== */
@media (max-width: 768px) {
  #app { grid-template-columns: 1fr; }
  #app.detail-open { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  #app.menu-open #sidebar { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.5); }
  #menu-close, #menu-open { display: inline-flex; }
  #list-pane { grid-column: 1 / -1; }
  #app.detail-open #list-pane { display: none; }
  #app.detail-open #detail-pane { grid-column: 1 / -1; }
  #detail-pane { border-left: none; }
}
@media (min-width: 769px) {
  #app:not(.detail-open) #list-pane { grid-column: 2 / -1; }
}
