/* 흰색 기반의 단순한 화면. 색은 PASS(초록)·FAIL(빨강)에만 쓴다. FHD(1920×1080, 100%) 기준. */
:root {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --line: #e4e4e4;
  --line-strong: #cfcfcf;
  --text: #1a1a1a;
  --muted: #6e6e6e;
  --subtle: #f2f2f2;
  --ink: #1a1a1a;
  --pass: #00b458;
  --pass-text: #00703a;
  --pass-soft: #eaf8f0;
  --fail: #ff1f26;
  --fail-text: #d0021b;
  --fail-soft: #fff0f0;
  --radius: 10px;
  --topbar-h: 52px;
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; line-height: 1; cursor: pointer; white-space: nowrap; vertical-align: middle;
}
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #000; }
.btn.secondary { background: var(--surface); border-color: var(--line-strong); }
.btn.secondary:hover:not(:disabled) { border-color: var(--ink); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { border-color: var(--ink); color: var(--ink); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; font-weight: 500; }
.btn.large { height: 48px; padding: 0 28px; font-size: 15px; }
.btn.link { height: auto; padding: 0; border: 0; background: none; color: var(--muted); font-weight: 400; font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.btn.link:hover { color: var(--ink); }
.btn.block { width: 100%; }

/* ---------- 상단 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand strong { font-size: 15px; white-space: nowrap; }
.brand span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.account-id { font-size: 13px; color: var(--muted); }
.engine { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.engine .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.engine[data-state="loading"] .dot { animation: pulse 1.2s infinite; }
.engine[data-state="ready"] .dot { background: var(--pass); }
.engine[data-state="error"] { color: var(--fail-text); }
.engine[data-state="error"] .dot { background: var(--fail); }
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---------- 본문 (FHD에서 한 화면) ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start;
  max-width: 1560px; margin: 0 auto; padding: 16px 28px 20px;
}
.col-main { display: grid; gap: 12px; min-width: 0; }
.col-side { position: sticky; top: calc(var(--topbar-h) + 16px); min-width: 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 22px; }
.panel h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 15px; }
.panel h2 .btn.link { margin-left: auto; }
.step {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--subtle); color: var(--muted); font-size: 12px; font-weight: 700;
}
.count { font-size: 13px; font-weight: 400; color: var(--muted); }

/* 1. PDF */
.pdf-row { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.dropzone {
  position: relative; display: flex; align-items: center; gap: 14px; min-height: 74px; padding: 12px 18px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer;
}
.dropzone:hover, .dropzone.over { border-color: var(--ink); background: #fcfcfc; }
.dropzone.busy { cursor: progress; opacity: 0.7; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone-icon {
  display: grid; place-items: center; width: 38px; height: 46px; flex: none; border-radius: 5px;
  border: 1px solid var(--line-strong); color: var(--muted); font-size: 11px; font-weight: 700;
}
.dropzone-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dropzone-text strong { font-size: 14px; overflow-wrap: anywhere; }
.dropzone-text span { color: var(--muted); font-size: 12px; }
.recognized input[readonly] { background: var(--subtle); border-color: var(--line); font-weight: 600; }
.notice { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--subtle); color: var(--muted); font-size: 12px; }

/* 입력칸 */
.info-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr 0.7fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { display: flex; align-items: center; gap: 6px; height: 20px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field-note { min-height: 16px; font-size: 12px; color: var(--muted); }
.tag { font-style: normal; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--subtle); color: var(--muted); }
input, select {
  width: 100%; min-width: 0; height: 38px; padding: 0 10px; border: 1px solid var(--line-strong);
  border-radius: 7px; background: var(--surface);
}
input:focus, select:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06); }
input.autofilled, select.autofilled { animation: autofill 1.4s ease-out; }
@keyframes autofill { from { background: #ececec; } to { background: var(--surface); } }

.kit-head { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 8px; }
.kit-head h3 { margin: 0; font-size: 13px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }

/* Kit 표: 라벨 | 변경 전 | 변경 후 (엑셀 양식과 같은 배치) */
.kit-table {
  display: grid; grid-template-columns: 120px minmax(0, 1fr) minmax(0, 1fr);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.kit-table > * { padding: 4px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.kit-table > :nth-last-child(-n + 3) { border-bottom: 0; }
.kt-corner, .kt-col-head { background: var(--subtle); }
.kt-col-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 38px; font-weight: 700; font-size: 13px;
}
.kt-label { display: flex; align-items: center; font-size: 13px; font-weight: 600; color: var(--muted); background: #fcfcfc; }
.kt-cell { display: grid; gap: 6px; }
.kt-cell input, .kt-cell select { height: 34px; }
.kt-cell + .kt-cell, .kt-col-head + .kt-col-head { border-left: 1px solid var(--line); }

/* 유효기간 월 선택 (연·월만) */
.month-field { position: relative; display: flex; min-width: 0; }
.month-field input { padding-right: 38px; }
.month-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 28px; height: 28px;
  border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer;
}
.month-toggle:hover { background: var(--subtle); color: var(--ink); }
input.invalid { border-color: var(--fail); }
.month-picker {
  position: absolute; z-index: 30; width: 256px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
.mp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.mp-year { font-size: 14px; }
.mp-nav {
  width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font-size: 16px; line-height: 1; cursor: pointer;
}
.mp-nav:hover { border-color: var(--ink); }
.mp-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.mp-grid button {
  height: 36px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font-size: 13px; cursor: pointer;
}
.mp-grid button:hover { border-color: var(--ink); }
.mp-grid button.this-month { font-weight: 700; }
.mp-grid button.selected { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.mp-foot { display: flex; justify-content: space-between; margin-top: 10px; }

/* 평가 + 만들기 버튼 (입력 흐름 끝, 화면 가운데) */
.action-panel {
  position: sticky; bottom: 16px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
}
.verdict {
  display: flex; align-items: center; gap: 14px; min-width: 0; padding: 10px 16px; border-radius: 8px; border: 1px solid;
}
.verdict-label { font-size: 12px; font-weight: 600; }
.verdict strong { font-size: 22px; line-height: 1; white-space: nowrap; }
.verdict-detail { font-size: 13px; }
.verdict.pass { background: var(--pass-soft); border-color: #a6e2c3; color: var(--pass-text); }
.verdict.fail { background: var(--fail-soft); border-color: #ffb8b8; color: var(--fail-text); }
.action-buttons { display: flex; align-items: center; gap: 10px; flex: none; }
.save-status { max-width: 280px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 3. 측정값 */
.rows-panel { display: flex; flex-direction: column; max-height: calc(100vh - var(--topbar-h) - 40px); }
.table-wrap { overflow: auto; min-height: 0; border: 1px solid var(--line); border-radius: 8px; }
.rows-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.rows-table th { position: sticky; top: 0; background: var(--subtle); font-weight: 600; font-size: 12px; color: var(--muted); padding: 7px 8px; border-bottom: 1px solid var(--line); }
.rows-table td { padding: 3px 8px; text-align: center; border-bottom: 1px dotted var(--line); }
.rows-table tr.over td { color: var(--fail-text); font-weight: 700; background: var(--fail-soft); }
.empty { margin: 0; padding: 22px 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- 로그인 ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card form { display: grid; gap: 14px; }
.login-card input[type="text"], .login-card input[type="password"] { height: 42px; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.remember input { width: 16px; height: 16px; margin: 0; accent-color: var(--ink); }
.login-error { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--fail-soft); color: var(--fail-text); font-size: 13px; }
.login-card .btn { height: 44px; }

/* ---------- 작은 화면 ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: minmax(0, 1fr) 360px; padding: 16px 20px 20px; }
  .info-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .col-side { position: static; }
  .rows-panel { max-height: none; }
  .table-wrap { max-height: 420px; }
  .action-panel { flex-wrap: wrap; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; }
  .brand span, .engine #engine-text { display: none; }
  .layout { padding: 14px 16px 16px; gap: 14px; }
  .panel { padding: 16px; }
  .pdf-row, .info-grid { grid-template-columns: 1fr; }
  .panel h2 { flex-wrap: wrap; row-gap: 4px; }
  .panel h2 .btn.link { flex-basis: 100%; margin-left: 0; text-align: left; justify-content: flex-start; }
  .kit-head { flex-direction: column; gap: 2px; }
  .mp-grid button, .mp-nav { height: 44px; }
  .mp-nav { width: 44px; }
  input, select, .kt-cell input, .kt-cell select { height: 44px; font-size: 16px; }
  /* Kit 표: 라벨을 한 줄 위로 올리고 변경 전·후 칸을 나란히 */
  .kit-table { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kt-corner { display: none; }
  .kt-col-head { flex-direction: column; align-items: flex-start; }
  .kt-label { grid-column: 1 / -1; padding-bottom: 0; border-bottom: 0; background: none; }
  .kt-cell:nth-child(3n + 2) { border-left: 0; }
  .action-panel { bottom: 8px; padding: 12px; gap: 10px; }
  .verdict { width: 100%; }
  .verdict-detail { display: none; }
  .action-buttons { width: 100%; }
  .action-buttons .save-status, #blank-btn { display: none; }
  #build-btn { flex: 1; }
}
