:root {
  color-scheme: light dark;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --text: #17201c;
  --muted: #5d6b64;
  --line: #dfe5e2;
  --brand: #0f7a55;
  --brand-ink: #ffffff;
  --danger: #b42318;
  --solar: #d97706;
  --offshore: #1d4ed8;
  --onshore: #0d9488;
  --ess: #7c3aed;
  --etc: #64748b;
  --policy: #be123c;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --surface: #1a211e;
    --text: #e6ece9;
    --muted: #9aa8a1;
    --line: #2c3631;
    --brand: #34b383;
    --brand-ink: #08130e;
    --danger: #f97066;
    --solar: #f59e0b;
    --offshore: #60a5fa;
    --onshore: #2dd4bf;
    --ess: #a78bfa;
    --etc: #94a3b8;
    --policy: #fb7185;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
a { color: inherit; }

.appbar { background: var(--surface); color: var(--text); border-bottom: 1px solid var(--line); }
.appbar-inner { display: flex; align-items: center; gap: 20px; min-height: 52px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 16px; letter-spacing: -0.02em; white-space: nowrap; }
.app-tabs { display: flex; gap: 4px; overflow-x: auto; }
.app-tab {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 8px 14px; border-radius: 8px;
  color: inherit; opacity: 0.7; text-decoration: none; font-weight: 700; font-size: 14.5px; white-space: nowrap;
}
.app-tab small { font-weight: 500; font-size: 11.5px; opacity: 0.8; }
.app-tab:hover { opacity: 1; }
.app-tab[aria-current="true"] { opacity: 1; color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); }

/*
 * 발전사업허가 화면: 메뉴 아래 남는 높이를 그 앱이 그대로 쓴다.
 * 예전에는 calc(100vh - 52px) 로 메뉴를 한 줄로 가정했는데, 휴대폰에서는 메뉴가
 * 두 줄(105px)이 되어 화면 아래 53px가 잘렸고 바깥 스크롤도 막혀 있어 볼 수 없었다.
 * 세로 flex 로 메뉴 높이와 상관없이 남는 만큼을 쓰게 한다.
 * 100dvh 는 휴대폰 주소창이 접히고 펴질 때의 실제 높이다(100vh 는 그 아래까지 잡는다).
 */
body.app-permits {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
body.app-permits .appbar { flex: none; }
body.app-permits #view-permits:not([hidden]) { flex: 1; min-height: 0; display: flex; }
#view-permits iframe { display: block; flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); }

.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-inner { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding-top: 18px; padding-bottom: 18px; }
h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.ghost { color: var(--brand); }
.btn:disabled { opacity: 0.6; cursor: progress; }

/* 새로고침 결과 한 줄. 버튼 줄 아래 오른쪽에 붙는다. 비어 있으면 자리를 차지하지 않는다. */
.refresh-status { flex-basis: 100%; margin: 0; text-align: right; font-size: 12.5px; color: var(--muted); }
.refresh-status:empty { display: none; }
.refresh-status.ok { color: var(--brand); font-weight: 600; }
.refresh-status.error { color: var(--danger); }

.tabs-bar { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 12px 14px;
  text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
.count { font-size: 12px; font-weight: 500; background: var(--bg); border-radius: 999px; padding: 0 7px; }

.weeks-row { border-top: 1px solid var(--line); background: var(--bg); }
.weeks { display: flex; gap: 6px; overflow-x: auto; padding-top: 8px; padding-bottom: 8px; scrollbar-width: thin; }
.week {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.week:hover { color: var(--text); border-color: var(--brand); }
.week[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.week[aria-selected="true"] .count { background: rgba(255, 255, 255, 0.25); color: inherit; }
.week-title { font-weight: 700; }
.week-range { font-size: 12px; opacity: 0.85; }
.week.this-week:not([aria-selected="true"]) { border-color: var(--brand); color: var(--brand); }
.week-summary { margin: 0 0 4px; color: var(--muted); font-size: 13.5px; font-weight: 600; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { border: 0; background: var(--surface); color: var(--muted); font: inherit; font-size: 14px; padding: 0 12px; min-height: 34px; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

.sheet-wrap {
  margin-top: 12px; margin-bottom: 8px; overflow: auto; max-height: calc(100vh - 230px);
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.sheet { border-collapse: collapse; width: 100%; min-width: 1100px; font-size: 13px; }
.sheet th, .sheet td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.sheet thead th {
  position: sticky; top: 0; z-index: 1; background: var(--bg); font-weight: 700; white-space: nowrap; user-select: none;
  box-shadow: 0 1px 0 var(--line);
}
.sheet th[data-sort] { cursor: pointer; }
.sheet th[data-sort]:hover { color: var(--brand); }
.sheet tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bg) 55%, var(--surface)); }
.sheet tbody tr:hover { background: color-mix(in srgb, var(--brand) 9%, var(--surface)); }
.sheet .col-no { width: 44px; text-align: right; color: var(--muted); }
.sheet .col-week, .sheet .col-date, .sheet .col-source { white-space: nowrap; }
.sheet .col-category { white-space: nowrap; }
.sheet .col-title { min-width: 300px; font-weight: 600; }
.sheet .col-title a { color: var(--offshore); text-decoration: none; }
.sheet .col-title a:hover { text-decoration: underline; }
.sheet .col-summary { min-width: 320px; color: var(--muted); }
.sheet .col-tags { color: var(--muted); font-size: 12px; min-width: 110px; }
.sheet .col-actions { white-space: nowrap; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 6px; }
.toolbar input[type="search"] { flex: 1 1 260px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.cat-sec { margin-top: 26px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sec-head h2 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sec-count { color: var(--muted); font-size: 13px; font-weight: 500; }
.more { font-size: 13px; color: var(--brand); text-decoration: none; white-space: nowrap; }
.more:hover { text-decoration: underline; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 6px;
}
.card:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.src { font-weight: 600; color: var(--text); }
.chip { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; color: #fff; }
.card h3 { margin: 0; font-size: 15.5px; line-height: 1.45; }
.card h3 a { text-decoration: none; }
.card h3 a:hover { text-decoration: underline; color: var(--brand); }
.card h3 a::after { content: " ↗"; color: var(--muted); font-weight: 400; font-size: 13px; }
.summary { margin: 0; color: var(--muted); font-size: 13.5px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { border: 0; background: var(--bg); color: var(--muted); font: inherit; font-size: 12px; border-radius: 6px; padding: 1px 7px; cursor: pointer; }
.tag:hover { color: var(--brand); }
.card-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: auto; padding-top: 4px; }
.link { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; padding: 2px; }
.link:hover { color: var(--text); text-decoration: underline; }
.link.danger:hover { color: var(--danger); }
.more-btn { display: flex; margin: 12px auto 0; color: var(--brand); }
.empty { color: var(--muted); font-size: 14px; margin: 6px 0; }

.chip-solar, .dot-solar { background: var(--solar); }
.chip-offshore, .dot-offshore { background: var(--offshore); }
.chip-onshore, .dot-onshore { background: var(--onshore); }
.chip-ess, .dot-ess { background: var(--ess); }
.chip-etc, .dot-etc { background: var(--etc); }
.chip-policy, .dot-policy { background: var(--policy); }

/* 정부정책 탭 안의 전환: 뉴스 / 법안 발의 / 법령·고시 개정 */
.policy-switch { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 2px; }
.policy-switch[hidden] { display: none; }
.policy-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.policy-btn:hover { color: var(--text); border-color: var(--brand); }
.policy-btn[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.policy-btn[aria-selected="true"] .count { background: rgba(255, 255, 255, 0.25); color: inherit; }
/* 진행 상태 · 시행일 표시 */
.pstatus { font-size: 11.5px; font-weight: 700; padding: 0 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.pstatus-on { color: var(--text); }
.pstatus-ok { color: var(--brand); }
.pstatus-off { color: var(--muted); }
.pstatus-soon { color: var(--solar); }
/* 주요내용·개정이유: 처음엔 앞부분만, 펼치면 원문 그대로(줄바꿈 유지) */
.policy-card .summary.full { display: none; white-space: pre-line; }
.policy-card.open .summary.full { display: block; }
.policy-card.open .summary.short { display: none; }
.policy-card .expand { color: var(--brand); padding: 2px 0; }
.ptag { cursor: default; }
.ptag:hover { color: var(--muted); }
@media (prefers-color-scheme: dark) { .chip { color: #0b0f0d; } }

.refs { margin: 40px 0 48px; padding-top: 18px; border-top: 1px solid var(--line); }
.refs h2 { font-size: 15px; margin: 0 0 8px; }
.refs ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.refs a { color: var(--brand); font-size: 14px; }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
#form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
#form h2 { margin: 0 0 4px; font-size: 18px; }
#form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
#form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  #form .row { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
}

/* ── SMP·REC 주간 동향: 뉴스 화면 맨 위 두 칸 ── */
.market { background: var(--surface); border-bottom: 1px solid var(--line); }
.market-inner { padding-top: 14px; padding-bottom: 14px; }
.mk-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 10px; }
.mk-head h2 { margin: 0; font-size: 15px; }
.mk-src { margin: 0; font-size: 12px; color: var(--muted); }
.mk-src a { color: var(--brand); }
.mk-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.mk-tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 10px; background: var(--bg); min-width: 0; }
.mk-tile p { margin: 0; }
.mk-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.mk-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.25; font-variant-numeric: tabular-nums; }
.mk-unit { font-size: 13px; font-weight: 600; color: var(--muted); }
.mk-delta { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mk-foot { font-size: 12px; color: var(--muted); min-height: 1.5em; font-variant-numeric: tabular-nums; }
/* 선 그림 영역 위아래 여유 — 점이 칸 끝에서 잘리지 않게 */
.spark { position: relative; height: 48px; margin: 12px 4px 8px; touch-action: none; cursor: crosshair; }
.spark svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.spark-line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-pt { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 2px var(--bg); pointer-events: none; }
.spark-pt.hover { width: 10px; height: 10px; margin: -5px 0 0 -5px; }
.spark-cross { position: absolute; top: -6px; bottom: -6px; border-left: 1px dashed var(--muted); pointer-events: none; }
.spark-pt[hidden], .spark-cross[hidden] { display: none; }

/* ── 신재생 행사 화면 ── */
.ev-toolbar input[type="search"] { flex: 1 1 260px; }
.ev-past { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.ev-cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.ev-cats .policy-btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.ev-month { font-size: 17px; margin: 24px 0 10px; }
.ev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.ev-card { display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.ev-card:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.ev-card.is-past { opacity: 0.6; }
.ev-when { flex: 0 0 104px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ev-dday { align-self: flex-start; font-size: 12px; font-weight: 800; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--text); }
.ev-dday.soon { border-color: var(--brand); color: var(--brand); }
.ev-dday.now { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.ev-dday.past { color: var(--muted); }
.ev-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.ev-body h3 { margin: 0; font-size: 15px; line-height: 1.45; }
.ev-body h3 a { text-decoration: none; }
.ev-body h3 a:hover { text-decoration: underline; color: var(--brand); }
.ev-body h3 a::after { content: " ↗"; color: var(--muted); font-weight: 400; font-size: 13px; }
.ev-note { font-size: 12.5px; }
.chip-general { background: var(--muted); }
@media (max-width: 560px) {
  .ev-grid { grid-template-columns: 1fr; }
  .ev-card { flex-direction: column; gap: 8px; }
  .ev-when { flex: none; flex-direction: row; align-items: center; }
  .mk-value { font-size: 23px; }
}
