:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #667085;
  --border: #dde1e7;
  --primary: #2952cc;
  --primary-text: #ffffff;
  --danger: #c62828;
  --warn: #b26a00;
  --ok: #1b7f4a;
  --support: #2952cc;
  --benefit: #1b7f4a;
  --fund: #8a4b00;
  --global: #7b3fb8;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --surface: #1a1f27;
    --surface-2: #232a34;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #2f3744;
    --primary: #7a9cff;
    --primary-text: #0d1220;
    --danger: #ff7b7b;
    --warn: #f0b35a;
    --ok: #5fd39a;
    --support: #7a9cff;
    --benefit: #5fd39a;
    --fund: #f0b35a;
    --global: #c49bff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
[hidden] { display: none !important; }

button, .btn {
  font: inherit; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
button.primary, .btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; background: transparent; }
button.wide { width: 100%; }
.icon-btn { border: none; background: transparent; font-size: 20px; padding: 4px 8px; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; width: 100%; max-width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
input[type="checkbox"] { width: auto; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.brand span { font-weight: 400; color: var(--muted); margin-left: 4px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#menu-toggle { display: none; }
.sidebar {
  position: fixed; top: 52px; bottom: 0; left: 0; width: 200px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border); padding: 12px 8px;
}
.sidebar a { display: block; padding: 7px 12px; border-radius: 6px; color: var(--text); }
.sidebar a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar a.active { background: var(--surface-2); color: var(--primary); font-weight: 600; }
.nav-group { font-size: 12px; color: var(--muted); padding: 14px 12px 4px; }
.view { margin-left: 200px; padding: 24px; max-width: 1200px; outline: none; }

@media (max-width: 800px) {
  #menu-toggle { display: inline-block; }
  .brand span { display: none; }
  #me { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; z-index: 30; }
  .sidebar.open { transform: none; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  .view { margin-left: 0; padding: 16px; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .grid.cols-4, .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }
.stat { display: block; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat .num { font-size: 28px; font-weight: 700; }
.stat .label { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 120px; }
.filters input[type="search"] { flex: 1; min-width: 180px; }

.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge.support { color: var(--support); }
.badge.benefit { color: var(--benefit); }
.badge.fund { color: var(--fund); }
.badge.global { color: var(--global); }
.badge.neutral { color: var(--muted); }
.dday { font-weight: 600; font-size: 13px; white-space: nowrap; }
.dday.urgent { color: var(--danger); }
.dday.soon { color: var(--warn); }
.dday.closed { color: var(--muted); font-weight: 400; }
.score { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.score.pos { color: var(--ok); }
.score.neg { color: var(--danger); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: none; }
.ann-title { font-weight: 600; color: var(--text); word-break: keep-all; overflow-wrap: anywhere; }
.meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.star { border: none; background: transparent; font-size: 18px; padding: 0 4px; color: var(--muted); }
.star.on { color: #e6a700; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }

progress { width: 100%; height: 8px; accent-color: var(--primary); }
.check-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.check-item:last-child { border-bottom: none; }
.check-item .body { flex: 1; min-width: 0; }
.check-item.done .title { text-decoration: line-through; color: var(--muted); }
.check-item select { width: auto; max-width: 260px; font-size: 13px; padding: 4px 8px; }
.warnings { border-color: var(--warn); }
.warnings li { color: var(--warn); }
.section-edit { margin-bottom: 18px; }
.section-edit .guide { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.save-state { font-size: 12px; color: var(--muted); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--surface-2); font-size: 13px; }
.chip button { border: none; background: transparent; padding: 0 6px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login-card h1 { margin-bottom: 4px; }
.login-card p { margin-top: 0; margin-bottom: 20px; font-size: 13px; }

/* Inline rows: let fields share the line instead of stacking */
.row > progress { flex: 1; width: auto; min-width: 80px; }
.row > input:not([type="checkbox"]) { flex: 1; width: auto; min-width: 140px; }
.row > select { width: auto; }
.row > input[type="number"] { flex: 0 0 90px; min-width: 0; }
.filters input[type="checkbox"] { min-width: 0; }
.filters label { margin: 0; color: var(--text); font-size: 14px; }

/* v2: 상태 표시 */
:root { --ok-bg: #e7f5ee; --warn-bg: #fff4e0; --err-bg: #fdecec; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ok-bg: #173327; --warn-bg: #3a2c12; --err-bg: #3b1d1d; }
}
.badge.okb { color: var(--ok); }
.badge.warnb { color: var(--warn); }
.badge.errb { color: var(--danger); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.pill.st-met, .pill.ov-met_auto { background: var(--ok-bg); color: var(--ok); }
.pill.st-unmet, .pill.ov-unmet { background: var(--err-bg); color: var(--danger); }
.pill.st-check, .pill.ov-check, .pill.ov-needs_review { background: var(--warn-bg); color: var(--warn); }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 4px 0 10px; }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 14px; }
label.check input { margin: 0; }
.check-item.provisional { opacity: .8; }
textarea.tall { min-height: 220px; }
.scroll { max-height: 60vh; overflow-y: auto; background: var(--surface-2); padding: 10px; border-radius: var(--radius); }
.stat .num.sm { font-size: 18px; }
ul.sub { margin: 4px 0 0; padding-left: 18px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
details > summary { cursor: pointer; margin: 8px 0; }
details.card > summary { margin: 0; }
th { white-space: nowrap; }
