:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --ink: #172126;
  --muted: #66747c;
  --line: #d9e1e4;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #b45309;
  --shadow: 0 8px 24px rgba(23, 33, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-family:
    Inter, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", system-ui,
    sans-serif;
  background: var(--bg);
  color: var(--ink);
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  background: #0e2728;
  color: #f8fafc;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.app-header__inner {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #94e2d5;
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: #cbd5e1;
  font-size: 13px;
}

.header-meta span {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 7px 10px;
}

.page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.summary-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.result-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.result-label,
.panel-subtitle,
.hint {
  color: var(--muted);
}

.result-label {
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
}

.result-title {
  font-size: clamp(24px, 3.2vw, 36px);
  line-height: 1.1;
  font-weight: 800;
}

.result-caption {
  margin: 8px 0 0;
  font-size: 14px;
}

.result-delta {
  color: var(--accent-dark);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.metric-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfc;
}

.metric span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 18px;
}

.bar-compare {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 84px minmax(80px, 1fr) minmax(110px, auto);
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

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

.bar-fill {
  width: 0;
  height: 100%;
  transition: width 180ms ease;
}

.bar-fill.keep {
  background: var(--blue);
}

.bar-fill.switch {
  background: var(--accent);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 14px;
  font-weight: 700;
}

.tab.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.calc-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.calc-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.calc-status.is-pending {
  color: var(--amber);
}

.calculate-button {
  min-width: 112px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  font-weight: 900;
}

.calculate-button.is-pending {
  background: var(--amber);
  border-color: var(--amber);
}

.summary-band.is-stale {
  border-color: #f59e0b;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 4px 14px rgba(23, 33, 38, 0.04);
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel-heading {
  min-height: 38px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-subtitle {
  margin: 5px 0 0;
  font-size: 13px;
}

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

label,
.wide-label,
.field-control {
  display: grid;
  gap: 6px;
  color: #344047;
  font-size: 13px;
  font-weight: 700;
}

.field-label-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.help-wrap {
  position: relative;
  display: inline-flex;
}

.help-button {
  border: 1px solid #b8c9ce;
  border-radius: 999px;
  background: #f8fbfb;
  color: var(--accent-dark);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.help-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  left: auto;
  right: 0;
  width: min(760px, calc(100vw - 48px));
  max-height: 420px;
  overflow: auto;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px;
  color: #344047;
  line-height: 1.5;
}

.rate-help-panel {
  width: min(560px, calc(100vw - 48px));
}

.help-panel--align-left {
  right: auto;
  left: 0;
}

.help-wrap:hover .help-panel,
.help-wrap:focus-within .help-panel {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

.help-wrap .help-panel.is-closed {
  visibility: hidden;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.help-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.help-title {
  margin-bottom: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.help-close {
  display: none;
  border: 1px solid #b8c9ce;
  border-radius: 999px;
  background: #f8fbfb;
  color: var(--accent-dark);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.help-summary {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

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

.help-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 10px;
}

.help-note-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.help-note p {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
}

.help-note small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-pill {
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 900;
}

.status-pill.confirmed {
  background: #dff6ef;
  color: #0f5f53;
}

.status-pill.unconfirmed {
  background: #fff3d7;
  color: #92400e;
}

.status-pill.pending {
  background: #eef2f7;
  color: #475569;
}

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

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 2px;
}

.hint {
  margin: 12px 0 0;
  font-size: 13px;
}

.inline-readout {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: #2b4243;
  font-size: 14px;
}

.primary-button,
.secondary-button,
.danger-button {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 9px 12px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  background: #eef2f4;
  color: #223137;
}

.danger-button {
  background: #fff1f2;
  color: var(--red);
  border-color: #fecdd3;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.bank-box {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  color: #344047;
  font-size: 14px;
}

.text-block {
  margin: 8px 0 0;
  color: #344047;
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.text-block strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.rate-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #eaf5f3;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
}

.data-table th {
  color: var(--muted);
  font-size: 13px;
}

.data-table td:last-child,
.data-table th:last-child {
  width: 96px;
}

.warning-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.warning-item {
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  color: var(--amber);
  padding: 10px 12px;
  font-size: 14px;
}

.search-input {
  max-width: 320px;
}

.bank-list {
  display: grid;
  gap: 12px;
}

.bank-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfc;
}

.bank-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.bank-card p {
  margin: 8px 0 0;
  color: #344047;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.component-list,
.event-list,
.source-list,
.logic-list {
  display: grid;
  gap: 10px;
}

.component-item,
.event-item,
.source-item,
.logic-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.component-item h3,
.event-item h3,
.logic-item h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.logic-item ul {
  margin: 0;
  padding-left: 20px;
  color: #344047;
  font-size: 14px;
  line-height: 1.65;
}

.logic-item li + li {
  margin-top: 4px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  color: #344047;
  font-size: 14px;
}

.kv-grid span:nth-child(odd) {
  color: var(--muted);
}

.source-item a {
  color: var(--accent-dark);
  font-weight: 800;
}

@media (max-width: 900px) {
  .app-header__inner,
  .result-main {
    align-items: flex-start;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .result-delta {
    text-align: left;
  }

  .metric-grid,
  .form-grid,
  .details-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-header__inner,
  .page-shell {
    width: min(100% - 20px, 1280px);
  }

  .page-shell {
    padding-bottom: 88px;
  }

  .summary-band,
  .panel {
    padding: 14px;
  }

  .metric-grid,
  .form-grid,
  .details-grid,
  .field-grid,
  .income-grid,
  .help-note-grid,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .field-label-row {
    align-items: flex-start;
  }

  .help-panel {
    position: fixed;
    top: auto;
    right: 10px;
    bottom: 76px;
    left: 10px;
    width: auto;
    max-height: min(68vh, 520px);
  }

  .help-panel--align-left {
    right: 10px;
    left: 10px;
  }

  .help-close {
    display: inline-flex;
  }

  .bar-row {
    grid-template-columns: 76px minmax(80px, 1fr);
  }

  .bar-row strong {
    grid-column: 2;
  }

  .panel-heading {
    display: grid;
  }

  .tabs {
    display: block;
  }

  .tab-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .calc-actions {
    position: fixed;
    z-index: 20;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 12px;
    margin-left: 0;
    justify-content: space-between;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
    padding: 10px;
  }

  .calculate-button {
    min-width: 132px;
  }

  .search-input {
    max-width: none;
  }
}
