:root {
  --bg: #ffffff;
  --bg-secondary: #f6f7f9;
  --bg-hover: #eef1f5;
  --border: #e5e7eb;
  --text: #1f2328;
  --text-muted: #6e7681;
  --accent: #2f6fed;
  --accent-soft: #eaf1ff;
  --red: #e5484d;
  --orange: #ea9a20;
  --green: #12b76a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-secondary: #12161c;
    --bg-hover: #1c2129;
    --border: #262c35;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #5b9dff;
    --accent-soft: #17233b;
    --red: #f85149;
    --orange: #e3a008;
    --green: #3fb950;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

/* 사용자가 토글로 명시적으로 선택한 테마 - 시스템 설정보다 우선함 */
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f6f7f9;
  --bg-hover: #eef1f5;
  --border: #e5e7eb;
  --text: #1f2328;
  --text-muted: #6e7681;
  --accent: #2f6fed;
  --accent-soft: #eaf1ff;
  --red: #e5484d;
  --orange: #ea9a20;
  --green: #12b76a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-secondary: #12161c;
  --bg-hover: #1c2129;
  --border: #262c35;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #5b9dff;
  --accent-soft: #17233b;
  --red: #f85149;
  --orange: #e3a008;
  --green: #3fb950;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", "Pretendard", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  font-size: 14px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 21px;
  flex-shrink: 0;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.theme-toggle-slider::before {
  content: "";
  position: absolute;
  height: 15px;
  width: 15px;
  left: 3px;
  top: 3px;
  background: var(--bg);
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.theme-toggle input:checked + .theme-toggle-slider {
  background: var(--accent);
}

.theme-toggle input:checked + .theme-toggle-slider::before {
  transform: translateX(17px);
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.tree-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px 10px;
  text-align: center;
}

.sidebar-footer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.ghost-btn {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}

.ghost-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tree-node { margin: 1px 0; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
}

.tree-row:hover {
  background: var(--bg-hover);
}

.tree-row.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.tree-row.drop-before {
  box-shadow: inset 0 2px 0 0 var(--accent);
}

.tree-row.drop-after {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

.tree-row.drop-inside {
  background: var(--accent-soft);
  outline: 2px dashed var(--accent);
}

.tree-row.dragging {
  opacity: 0.4;
}

.tree-toggle {
  width: 14px;
  flex-shrink: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 10px;
}

.tree-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tree-children {
  list-style: none;
  margin: 0;
  padding-left: 16px;
}

.dot-red, .badge-red { background: var(--red); }
.dot-orange, .badge-orange { background: var(--orange); }
.dot-green, .badge-green { background: var(--green); }

/* ---------- Main content ---------- */

.content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px;
}

.content-inner {
  max-width: 680px;
  margin: 0 auto;
}

.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.breadcrumb .crumb {
  cursor: pointer;
}

.breadcrumb .crumb:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb .sep {
  margin: 0 6px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 12px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  margin: 0;
  overflow-wrap: anywhere;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.type-pill {
  display: inline-block;
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  margin: 8px 0 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 28px;
}

.stat-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stat-percent {
  font-size: 30px;
  font-weight: 700;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.15s ease;
}

.checklist-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.checklist-input {
  flex: 1;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
}

.checklist-input:focus {
  outline: none;
  border-color: var(--accent);
}

.checklist-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checklist-item-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
}

.checklist-item-wrap:hover {
  border-color: var(--accent);
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.checklist-item.drop-before {
  box-shadow: inset 0 2px 0 0 var(--accent);
}

.checklist-item.drop-after {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

.checklist-item.dragging {
  opacity: 0.4;
}

.checklist-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.checklist-text {
  flex: 1;
  font-size: 14px;
}

.checklist-item.checked .checklist-text {
  color: var(--text-muted);
  text-decoration: line-through;
}

.note-indicator {
  font-size: 13px;
  flex-shrink: 0;
}

.checklist-note {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  background: var(--bg-secondary);
}

.checklist-note-input {
  width: 100%;
  min-height: 60px;
  resize: none;
  overflow: hidden;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
}

.checklist-note-input:focus {
  outline: none;
  border-color: var(--accent);
}

.note-preview {
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  cursor: text;
}

.note-preview:hover {
  border-color: var(--accent);
}

.note-preview.empty {
  color: var(--text-muted);
  font-style: italic;
}

.checklist-empty {
  color: var(--text-muted);
  font-size: 13px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 28px 0 12px;
}

.child-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.child-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--bg);
}

.child-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.child-card .tree-dot { flex-shrink: 0; }

.child-name {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.child-percent {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.child-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 6px;
}

.child-remove:hover {
  background: var(--bg-hover);
  color: var(--red);
}

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.add-btn {
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
}

.add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 7px;
}

.text-btn:hover {
  background: var(--bg-hover);
}

.text-btn.danger:hover {
  background: #fdeceb;
  color: var(--red);
}

/* ---------- Empty / landing state ---------- */

.landing h2 {
  font-size: 24px;
  margin-bottom: 4px;
}

.landing p {
  color: var(--text-muted);
  margin-top: 0;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 24px;
}

.subject-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  background: var(--bg-secondary);
}

.subject-card:hover {
  border-color: var(--accent);
}

.subject-card .name {
  font-weight: 600;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subject-card .percent {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

/* ---------------- Modal dialogs ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 320px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.modal-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.modal-input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions button {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
}

.modal-cancel {
  background: var(--bg-secondary);
  color: var(--text-muted);
  border-color: var(--border);
}

.modal-cancel:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.accent-btn {
  background: var(--accent);
  color: white;
}

.danger-btn {
  background: var(--red);
  color: white;
}
