/* SECA 탄소절감 폐기물 측정 모듈 — 무채색 디자인 시스템 (hairline, 가중치, 여백으로만 강조) */
:root {
  --ink: #111; --ink-2: #333; --ink-3: #555; --muted: #777; --faint: #999;
  --line: #ddd; --line-strong: #999; --line-soft: #eee;
  --surface: #fff; --surface-2: #f5f5f5; --surface-3: #eee;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --dur: 180ms;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--surface); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.5; overflow-x: hidden; }
a { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font-family: inherit; font-size: 16px; color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; color: var(--ink-2); }
p { margin: 0; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: var(--s3); border: 1px solid var(--line-soft); }

/* 레이아웃 */
.wrap { max-width: 1600px; margin: 0 auto; padding: 0 var(--s4); }
header.app { border-bottom: 1px solid var(--line-strong); }
header.app .wrap { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2) var(--s5); padding-top: var(--s4); padding-bottom: var(--s3); }
header.app .sub { color: var(--muted); font-size: 13px; }
header.app .health { margin-left: auto; font-size: 12px; color: var(--muted); }
nav.tabs { border-bottom: 1px solid var(--line); overflow-x: auto; }
nav.tabs .wrap { display: flex; gap: 0; }
nav.tabs [role="tab"] { background: none; border: 0; border-bottom: 2px solid transparent; padding: var(--s3) var(--s4); font-size: 14px; color: var(--ink-3); cursor: pointer; white-space: nowrap; margin-bottom: -1px; }
nav.tabs [role="tab"]:hover { color: var(--ink); background: var(--surface-2); }
nav.tabs [role="tab"][aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
main { padding: var(--s4) 0 var(--s6); }
main .wrap, header.app .wrap { min-width: 0; }
.grid > * { min-width: 0; }
.box, .card, .hero, .stat { min-width: 0; }
.tbl-wrap { max-width: 100%; }
.stat .value, .hero .value { overflow-wrap: anywhere; }
[role="tabpanel"] { animation: fade var(--dur) ease-out; }
[role="tabpanel"][hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.status { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line-soft); font-size: 12.5px; color: var(--ink-3); min-height: 24px; padding: 2px 0; }
.status.err { color: var(--ink); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s4); align-items: start; }
.col-2 { grid-column: span 2; } .col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; } .col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; } .col-9 { grid-column: span 9; } .col-12 { grid-column: span 12; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: end; }
.row > * { min-width: 0; }
.row > .field { flex: 1 1 180px; max-width: 100%; }
.row > .btn { flex: 0 0 auto; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.mt { margin-top: var(--s3); } .mt2 { margin-top: var(--s5); } .mb { margin-bottom: var(--s3); }
.muted { color: var(--muted); } .small { font-size: 12px; } .tiny { font-size: 11px; } .b { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.loading { opacity: 0.45; transition: opacity var(--dur); }

/* 박스·타일 */
.box { border: 1px solid var(--line); padding: var(--s3); background: var(--surface); }
.box.strong { border-color: var(--line-strong); }
.box-title { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-bottom: var(--s2); display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); }
.hero { border: 1px solid var(--ink); padding: var(--s4); }
.hero .label { font-size: 12px; color: var(--ink-3); }
.hero .value { font-size: 48px; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; margin-top: var(--s1); }
.hero .unit { font-size: 16px; font-weight: 500; color: var(--ink-3); margin-left: var(--s1); }
.hero .delta { font-size: 13px; color: var(--ink-3); margin-top: var(--s2); }
.stat { border: 1px solid var(--line); padding: var(--s3); min-height: 84px; }
.stat .label { font-size: 12px; color: var(--ink-3); }
.stat .value { font-size: 24px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.stat .value.long { font-size: 19px; }
.stat .value .unit { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: var(--s3); }
.stats.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.badge { display: inline-block; border: 1px solid var(--line-strong); padding: 0 6px; font-size: 11px; line-height: 18px; color: var(--ink-2); white-space: nowrap; }
.badge.strong { border-color: var(--ink); background: var(--ink); color: #fff; }
.badge.soft { border-color: var(--line); color: var(--muted); }

/* 폼 */
label { font-size: 12px; color: var(--ink-3); display: block; }
.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field input, .field select, .field textarea { border: 1px solid #bbb; background: var(--surface); padding: 6px 8px; min-height: 36px; width: 100%; max-width: 100%; border-radius: 0; }
select { max-width: 100%; text-overflow: ellipsis; }
.field input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.field .hint { font-size: 11px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); min-height: 36px; }
.check input { width: 16px; height: 16px; margin: 0; }
.btn { white-space: nowrap; border: 1px solid var(--ink); background: var(--surface); color: var(--ink); padding: 7px 14px; font-size: 14px; cursor: pointer; min-height: 36px; border-radius: 0; transition: background var(--dur); }
.btn:hover { background: var(--surface-2); }
.btn:disabled { color: var(--faint); border-color: var(--line); cursor: default; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--ink-2); }
.btn.ghost { border-color: var(--line); color: var(--ink-3); }
.btn.sm { padding: 3px 8px; font-size: 12px; min-height: 26px; }
.btn.link { border: 0; padding: 0; min-height: 0; text-decoration: underline; text-underline-offset: 2px; font-size: 12px; color: var(--ink-3); background: none; }
textarea { min-height: 120px; font-family: var(--mono); font-size: 12.5px; }
details.panel { border: 1px solid var(--line); }
details.panel > summary { cursor: pointer; padding: var(--s2) var(--s3); font-size: 13px; font-weight: 600; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "+"; display: inline-block; width: 14px; color: var(--muted); }
details.panel[open] > summary::before { content: "−"; }
details.panel > .body { padding: var(--s3); border-top: 1px solid var(--line-soft); }
.pgroup { border-top: 1px solid var(--line-soft); padding-top: var(--s2); margin-top: var(--s2); }
.pgroup h4 { font-size: 12px; color: var(--ink-3); margin-bottom: var(--s2); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s2) var(--s3); }

/* 표 */
.tbl-wrap { overflow-x: hidden; }
.scroll .tbl-wrap { overflow: visible; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--ink-3); border-bottom: 1px solid var(--line-strong); padding: 6px 8px; white-space: normal; vertical-align: bottom; }
table.tbl td { border-bottom: 1px solid var(--line-soft); padding: 6px 8px; vertical-align: top; white-space: normal; overflow-wrap: anywhere; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl tr.click { cursor: pointer; }
table.tbl tr.click:hover td { background: var(--surface-2); }
table.tbl tr.selected td { background: var(--surface-3); }
table.tbl.compact td, table.tbl.compact th { padding: 3px 6px; font-size: 12px; }
table.tbl input, table.tbl select { border: 1px solid #bbb; padding: 3px 6px; font-size: 13px; min-height: 28px; width: 100%; min-width: 96px; }
table.tbl td:has(> .btn) { white-space: nowrap; }
table.tbl input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--s3); font-size: 12.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

/* 카드·목록 */
.card { border: 1px solid var(--line); padding: var(--s3); }
.card.critical { border-color: var(--ink); }
.card .title { font-weight: 600; font-size: 14px; }
.list { margin: 0; padding-left: 18px; }
.list li { margin: 2px 0; }
ol.trace { margin: 0; padding-left: 22px; }
ol.trace li { margin: 4px 0; border-bottom: 1px solid var(--line-soft); padding-bottom: 4px; }
ol.trace .basis { color: var(--muted); font-size: 12px; }

/* 드로어 */
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: min(520px, 100%); background: var(--surface); border: 1px solid var(--line-strong); z-index: 20; overflow: auto; padding: var(--s4); transform: translateX(100%); transition: transform var(--dur) ease-out; }
.drawer.open { transform: translateX(0); }
.drawer .close { position: absolute; top: var(--s3); right: var(--s3); }

/* 차트 */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; font-family: var(--font); }
.chart .bar { transition: opacity var(--dur); }
.chart .bar:hover, .chart .bar:focus { opacity: 0.75; outline: none; }
.chart .grid line { stroke: #e5e5e5; stroke-width: 1; }
.chart .axis text, .chart .lbl { fill: var(--ink-3); font-size: 11px; }
.chart .val { fill: var(--ink); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .legend { display: flex; gap: var(--s3); font-size: 12px; color: var(--ink-3); margin-top: var(--s2); flex-wrap: wrap; }
.chart .legend .sw { display: inline-block; width: 14px; height: 10px; border: 1px solid var(--ink-2); vertical-align: middle; margin-right: 4px; }
.tooltip { position: fixed; z-index: 30; background: var(--ink); color: #fff; font-size: 12px; padding: 4px 8px; pointer-events: none; opacity: 0; transition: opacity var(--dur); white-space: nowrap; }
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 600; }

/* 반응형 */
@media (max-width: 1280px) { .p2 { display: none !important; } }
@media (max-width: 1024px) {
  .col-2, .col-3 { grid-column: span 4; }
  .p3 { display: none !important; }
  .stats.six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .grid > * { grid-column: span 1 !important; }
  .hero .value { font-size: 40px; }
  header.app .health { margin-left: 0; }
  .pgrid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) { .pgrid { grid-template-columns: 1fr; } .stats, .stats.six { grid-template-columns: repeat(2, minmax(0, 1fr)); } .hero .value { font-size: 36px; } .tbl-wrap { overflow-x: auto; } }
@media (prefers-reduced-motion: reduce) {
  [role="tabpanel"] { animation: none; }
  .drawer, .btn, .chart .bar, .tooltip, .loading { transition: none; }
}
@media print { nav.tabs, .status, .btn { display: none !important; } }

@media (max-width: 600px) { .stats.six { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stat .value { font-size: 20px; } }

/* 내부 스크롤 섹션 (두 열 중 한쪽이 길게 삐져나오지 않도록 높이 상한 + 내부 스크롤) */
.scroll { max-height: min(72vh, 780px); overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; }
.scroll table.tbl thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; border-bottom: 0; box-shadow: 0 1px 0 var(--line-strong); }
/* 2행 셀·모노·요약 스트립 */
.cell-2l .l1 { font-weight: 600; } .cell-2l .l1.plain { font-weight: 400; } .cell-2l .l2 { color: var(--muted); font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.strip { display: flex; gap: var(--s5); flex-wrap: wrap; align-items: baseline; font-size: 12px; color: var(--ink-3); }
.strip b { font-size: 18px; font-weight: 600; color: var(--ink); margin-right: 4px; font-variant-numeric: tabular-nums; }
.box > .box-title + .scroll, .box > .scroll { margin-top: 0; }
