:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --btn: #111827;
  --btnText: #ffffff;
  --good: #16a34a;
  --bad: #dc2626;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans KR", sans-serif; background: var(--bg); color: var(--text); }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.brand { font-weight: 900; font-size: 20px; }
.menu-title { margin: 12px 0 4px; color: var(--muted); font-size: 12px; }
.menu { display: flex; flex-direction: column; gap: 6px; }
.menu a { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; font-size: 14px; }
.menu a:hover { background: #f3f4f6; }
.menu a.active { background: #f3f4f6; border-color: var(--line); }
.menu-icon { font-size: 18px; line-height: 1; }
.challenge-select {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
  background: #fff;
}
.challenge-select label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.challenge-select select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  background: #fff;
}

.content { padding: 24px; }
.center-wrap {
  min-height: calc(100vh - 48px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 6px 18px rgba(0,0,0,0.03); }
.card h2 { margin: 0 0 12px; font-size: 20px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.small { color: var(--muted); font-size: 13px; }

textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 14px; resize: vertical; min-height: 220px; outline: none; }
textarea:focus { border-color: #c7c9d3; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
button { border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button.primary { background: var(--btn); color: var(--btnText); }
button.secondary { background: #f3f4f6; color: var(--text); border: 1px solid var(--line); }
a.btnlink { text-decoration: none; }
.toggle { display: inline-flex; gap: 8px; align-items: center; margin-left: auto; color: var(--muted); font-size: 14px; }

.ai-box { margin-top: 16px; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; background: #fafafa; }
.ai-box h4 { margin: 0 0 10px; }
.ai-box p { margin: 10px 0; color: var(--text); }

.form-wrap { max-width: 740px; width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.checkbox-field { gap: 8px; }
.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  width: fit-content;
}
.checkbox-row input[type="checkbox"] { margin: 0; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"], select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px;
}

.badge { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); background: #f9fafb; margin-left: 8px; gap: 6px; }
.badge.good { border-color: rgba(22,163,74,.35); background: rgba(22,163,74,.08); color: var(--good); }
.badge.bad { border-color: rgba(220,38,38,.35); background: rgba(220,38,38,.08); color: var(--bad); }
.badge.warn { border-color: rgba(245,158,11,.35); background: rgba(245,158,11,.08); color: var(--warn); }
.badge-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: #f3f4f6;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.badge-btn:hover { background: #e5e7eb; }
.badge-btn.danger {
  border-color: rgba(220,38,38,.35);
  background: rgba(220,38,38,.08);
  color: var(--bad);
}
.badge-btn.disabled { opacity: 0.45; pointer-events: none; }
.inline-form { margin: 0; }

.messages { margin-bottom: 12px; }
.msg { padding: 10px 12px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 12px; }
.notice { padding: 8px 10px; border-radius: 10px; font-size: 12px; margin-bottom: 8px; border: 1px solid var(--line); }
.notice.success { background: #ecfdf3; color: #14532d; border-color: rgba(22,163,74,.35); }
.notice.error { background: #fef2f2; color: #7f1d1d; border-color: rgba(220,38,38,.35); }
.inline-notice { margin: 0 0 0 6px; padding: 6px 8px; }
.ai-status { font-size: 12px; color: var(--muted); margin-left: 8px; min-width: 60px; display: inline-flex; align-items: center; }

.challenge-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.challenge-item { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.challenge-item:last-child { border-bottom: none; padding-bottom: 0; }
.challenge-item strong { display: block; margin-bottom: 4px; }
.challenge-item .small { font-size: 12px; }
.challenge-row { width: 100%; }
.challenge-actions { margin-left: auto; }

.calendar-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  height: min(80vh, 760px);
  min-height: 420px;
}
.calendar-popup-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px;
  background: rgba(15, 23, 42, 0.45);
  z-index: 30;
}
.calendar-popup-overlay:empty { display: none; }
.calendar-popup {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
}
.popup-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.popup-header strong { font-size: 16px; }
.popup-question { font-weight: 600; margin-top: 10px; }
.popup-entry {
  margin-top: 12px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.popup-entry-empty { color: var(--muted); }
.calendar-weekdays,
.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 12px;
  min-width: 820px;
}
.calendar-days {
  margin-top: 4px;
  flex: 1;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
}
.calendar-weekdays {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.calendar-weekdays .weekday {
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding: 6px 0;
}
.day {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.challenge-flag {
  margin-top: auto;
  align-self: flex-end;
  font-size: 11px;
  color: var(--text);
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.4);
  border-radius: 8px;
  padding: 2px 6px;
}
.day-head { justify-content: space-between; align-items: center; }
.day .dnum { font-weight: 800; font-size: 14px; }
.day.muted { opacity: .5; }
.challenge-title { font-size: 12px; color: var(--muted); min-height: 18px; }
.pill { font-size: 11px; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line); display: inline-flex; width: fit-content; }
.pill.done { color: var(--good); border-color: rgba(22,163,74,.35); background: rgba(22,163,74,.08); }
.pill.miss { color: var(--bad); border-color: rgba(220,38,38,.35); background: rgba(220,38,38,.08); }
.pill.today { color: #2563eb; border-color: rgba(37,99,235,.35); background: rgba(37,99,235,.08); }
.status-btn { border: none; background: transparent; cursor: pointer; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; }
.table th { color: var(--muted); font-weight: 700; font-size: 12px; }
.table-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}
.table-link:hover { text-decoration: underline; }
.per-page-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.per-page-form select {
  width: auto;
  min-width: 90px;
}
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
  width: 100%;
}
.page-link {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
}
.page-link:hover { background: #f3f4f6; }
.page-link.active {
  background: #111827;
  color: #ffffff;
  border-color: #111827;
  pointer-events: none;
}
.page-link.disabled {
  color: var(--muted);
  pointer-events: none;
  background: #f9fafb;
}
.post-meta {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.post-meta .small { white-space: nowrap; }

.split { display:grid; grid-template-columns: 1fr 360px; gap: 14px; }
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .calendar-weekdays,
  .calendar-days {
    min-width: 680px;
    grid-template-columns: repeat(7, minmax(100px, 1fr));
  }
}
.spacer { flex: 1; }
