:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --panel-soft: #f9faf7;
  --ink: #222831;
  --muted: #68707a;
  --line: #d9ded7;
  --teal: #0f766e;
  --teal-soft: #e2f3ef;
  --amber: #b7791f;
  --amber-soft: #fff3d6;
  --blue: #2563a8;
  --red: #b42318;
  --shadow: 0 10px 30px rgba(35, 43, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--teal);
  cursor: pointer;
  font-weight: 700;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

button:hover {
  filter: brightness(0.96);
}

button.secondary,
.file-box {
  color: var(--ink);
  background: #eef1ed;
  border: 1px solid var(--line);
}

button.danger {
  color: #fff;
  background: var(--red);
}

button.small {
  padding: 7px 10px;
  font-size: 13px;
}

button.tab {
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
}

button.tab.active {
  color: var(--teal);
  background: #fff;
  border-color: var(--line);
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: #404852;
  font-size: 13px;
  font-weight: 700;
}

main {
  max-width: 1680px;
  margin: 0 auto;
  padding: 0 18px 40px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.app-header h1 {
  margin: 2px 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
}

.notice {
  max-width: 900px;
  margin: 0;
  color: var(--muted);
}

.header-actions,
.button-row,
.building-api-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.header-actions {
  justify-content: flex-end;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 6px;
  padding: 10px 18px;
  background: rgba(244, 246, 243, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
  padding-top: 16px;
  min-width: 0;
}

.input-panel,
.side-summary,
.report-output,
.archive-table-wrap,
.panel-section,
.report-toolbar,
.archive-header,
.archive-filters {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.input-panel {
  display: grid;
  gap: 14px;
  border: 0;
  background: transparent;
  box-shadow: none;
  min-width: 0;
}

.panel-section {
  padding: 16px;
  min-width: 0;
}

.section-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 14px;
}

.section-title.inline {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.section-title h2,
.side-summary h2,
.report-toolbar h2,
.archive-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.section-title span,
.archive-header p,
.report-toolbar p {
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.wide {
  grid-column: span 2;
}

.field-with-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.radius-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 8px 10px;
  font-weight: 800;
}

.check-pill input {
  width: auto;
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #45505c;
  background: #f1f4ef;
  font-size: 12px;
}

td input,
td select {
  min-width: 96px;
}

td:first-child input {
  min-width: 150px;
}

.csv-tools {
  display: grid;
  gap: 10px;
}

.auto-lookup-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 220px) minmax(180px, 220px);
  gap: 12px;
  align-items: end;
}

.auto-actions {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
}

.api-status {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

.api-status strong {
  color: var(--ink);
}

.api-status.ok {
  border-color: #9fd5ca;
  background: var(--teal-soft);
}

.api-status.warn {
  border-color: #edd08d;
  background: var(--amber-soft);
}

.api-status.error {
  border-color: #efc4bd;
  background: #fff6f4;
}

.file-box {
  position: relative;
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}

.file-box.compact {
  padding: 9px 12px;
}

.file-box input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.status-line {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.demand-grid,
.revenue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric-editor {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.metric-editor strong {
  font-size: 13px;
}

.metric-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.side-summary {
  position: sticky;
  top: 62px;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.summary-list {
  display: grid;
  gap: 10px;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.summary-item strong {
  min-width: 0;
  color: var(--ink);
  text-align: right;
  overflow-wrap: anywhere;
}

.callout {
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  background: var(--amber-soft);
  padding: 12px;
}

.callout p {
  margin: 5px 0 0;
  color: #5f4a1d;
  font-size: 13px;
}

.report-shell {
  padding-top: 16px;
}

.report-toolbar,
.archive-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.report-output {
  padding: 0;
  overflow: hidden;
}

.report-output.empty {
  padding: 44px 20px;
}

.empty-state {
  max-width: 520px;
  margin: 0 auto;
  text-align: center;
  color: var(--muted);
}

.report-cover {
  padding: 34px;
  color: #fff;
  background: #24312f;
}

.report-cover h1 {
  max-width: 900px;
  margin: 0 0 24px;
  font-size: 34px;
  letter-spacing: 0;
}

.cover-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.cover-item {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 10px;
}

.cover-item span {
  display: block;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.cover-item strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.report-section {
  padding: 24px 28px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.report-section h2 {
  margin: 0 0 12px;
  font-size: 21px;
  letter-spacing: 0;
}

.report-section h3 {
  margin: 16px 0 8px;
  font-size: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.kpi-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.kpi-card strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  overflow-wrap: anywhere;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 8px 0 0;
}

.tag {
  border-radius: 8px;
  background: var(--teal-soft);
  color: #0b5f59;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.tag.warn {
  background: var(--amber-soft);
  color: #7a5010;
}

.manual-section {
  display: none;
}

.auto-dashboard {
  display: grid;
  gap: 14px;
}

.empty-state.compact {
  padding: 22px;
}

.dashboard-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.dashboard-kpi,
.dashboard-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dashboard-kpi {
  display: grid;
  gap: 4px;
  min-height: 96px;
  padding: 12px;
  min-width: 0;
}

.compact-kpis {
  margin-bottom: 12px;
}

.dashboard-kpi span,
.dashboard-kpi small,
.dashboard-note,
.muted {
  color: var(--muted);
}

.dashboard-kpi span,
.dashboard-kpi small {
  font-size: 12px;
}

.dashboard-kpi strong {
  font-size: 20px;
  line-height: 1.2;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.dashboard-kpi small,
.dashboard-card td,
.dashboard-card th,
.chart-row span,
.chart-row small {
  overflow-wrap: anywhere;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.dashboard-card {
  min-width: 0;
  padding: 14px;
}

.dashboard-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.dashboard-note {
  margin: 0 0 10px;
  font-size: 13px;
}

.analysis-verdict {
  display: grid;
  gap: 4px;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--teal-soft);
  color: #0b5f59;
  padding: 12px;
}

.analysis-verdict strong {
  font-size: 16px;
}

.analysis-verdict span {
  color: #175f58;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.analysis-comment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.analysis-comment-column {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.analysis-comment-column h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.analysis-comment-item {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.analysis-comment-item:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.analysis-comment-item strong,
.analysis-comment-item p,
.analysis-comment-item small {
  overflow-wrap: anywhere;
}

.analysis-comment-item p {
  margin: 0;
  font-size: 13px;
}

.analysis-comment-item small {
  color: var(--muted);
  font-size: 12px;
}

.mini-title {
  margin: 12px 0 8px;
  font-size: 14px;
}

.chart-list {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.mini-chart .chart-row {
  grid-template-columns: 70px minmax(0, 1fr) 88px;
}

.nearby-samples {
  display: grid;
  gap: 4px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.nearby-samples span {
  overflow-wrap: anywhere;
}

.unit-selector {
  margin-top: 12px;
}

.unit-summary {
  align-self: end;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  padding: 10px 12px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.chart-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 72px;
  gap: 9px;
  align-items: center;
  font-size: 13px;
  min-width: 0;
}

.chart-row > span {
  font-weight: 800;
}

.chart-row strong {
  text-align: right;
}

.chart-row small {
  grid-column: 2 / 4;
  color: var(--muted);
}

.compact-table th,
.compact-table td {
  font-size: 12px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.analysis-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px;
}

.analysis-card h3 {
  margin-top: 0;
}

.bar-cell {
  min-width: 130px;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: #e8ece6;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--amber));
}

.brief-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbff;
  padding: 14px;
  font-size: 16px;
}

.warning-box {
  border: 1px solid #efc4bd;
  border-radius: 8px;
  background: #fff6f4;
  padding: 14px;
  color: #70241e;
}

.archive-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 170px 170px 160px;
  gap: 8px;
  padding: 12px;
  margin-bottom: 14px;
}

.archive-table-wrap {
  background: #fff;
}

.archive-table td {
  font-size: 13px;
}

.archive-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 360px;
}

.archive-actions button {
  padding: 7px 9px;
  font-size: 12px;
}

.address-modal[hidden] {
  display: none;
}

.address-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
}

.address-modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: rgba(20, 28, 36, 0.52);
}

.address-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr);
  width: min(720px, 100%);
  height: min(680px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 80px rgba(20, 28, 36, 0.28);
}

.address-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8faf7;
}

.address-modal-header h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.postcode-embed {
  min-height: 420px;
  background: #fff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: 360px;
  transform: translateY(20px);
  opacity: 0;
  border-radius: 8px;
  background: #1f2a29;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-summary {
    position: static;
  }

  .form-grid.four,
  .auto-lookup-grid,
  .demand-grid,
  .revenue-grid,
  .cover-grid,
  .kpi-grid,
  .dashboard-kpis,
  .dashboard-grid,
  .analysis-grid,
  .archive-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  main {
    padding: 0 10px 28px;
  }

  .app-header,
  .report-toolbar,
  .archive-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions,
  .button-row {
    justify-content: stretch;
  }

  .header-actions button,
  .button-row button,
  .file-box {
    width: 100%;
  }

  .form-grid.four,
  .auto-lookup-grid,
  .demand-grid,
  .revenue-grid,
  .cover-grid,
  .kpi-grid,
  .dashboard-kpis,
  .dashboard-grid,
  .analysis-grid,
  .archive-filters {
    grid-template-columns: 1fr;
  }

  .chart-row {
    grid-template-columns: 84px minmax(0, 1fr) 58px;
  }

  .chart-row small {
    grid-column: 2 / 4;
  }

  .wide {
    grid-column: auto;
  }

  .field-with-action {
    grid-template-columns: 1fr;
  }

  .address-modal {
    padding: 10px;
  }

  .address-modal-panel {
    height: min(640px, calc(100vh - 20px));
  }

  .auto-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .api-status {
    grid-template-columns: 1fr;
  }

  .report-cover,
  .report-section {
    padding: 20px;
  }

  .report-cover h1 {
    font-size: 26px;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 14mm;
  }

  body {
    background: #fff;
  }

  .no-print,
  .tabs,
  #inputView,
  #archiveView,
  .report-toolbar,
  .toast {
    display: none !important;
  }

  main {
    max-width: none;
    padding: 0;
  }

  #reportView,
  #reportView.active,
  .report-output {
    display: block !important;
  }

  .report-output {
    border: 0;
    box-shadow: none;
  }

  .report-cover {
    min-height: 250mm;
    color: #111;
    background: #fff;
    border: 1px solid #999;
    break-after: page;
  }

  .cover-item {
    border-color: #ccc;
  }

  .cover-item span {
    color: #555;
  }

  .report-section {
    padding: 12mm 0;
    border-bottom: 1px solid #ccc;
    break-inside: avoid;
  }

  table,
  tr,
  .analysis-card,
  .kpi-card {
    break-inside: avoid;
  }
}
