/* ==========================================================================
   Sourcing Margin · dicekorea.com
   일본 도매 소싱 마진·관부가세 계산기
   외부 CDN·폰트 의존성 없음. CSP `default-src 'self'; style-src 'self';
   script-src 'self'` 환경에서 그대로 동작합니다.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #F4F7FC;
  --surface: #FFFFFF;
  --surface-2: #F8FAFE;
  --ink: #0F172A;
  --ink-2: #3B4A63;
  --muted: #6B7A90;
  --line: #E3E9F4;
  --line-soft: #EEF2F9;
  --brand: #2563EB;
  --brand-dark: #1D4ED8;
  --brand-soft: #EDF3FF;
  --green: #0E9F6E;
  --green-soft: #E7F8F0;
  --amber: #B45309;
  --amber-soft: #FEF5E7;
  --red: #D92D20;
  --red-soft: #FEECEB;
  --radius-lg: 20px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 18px 38px -28px rgba(15, 23, 42, .45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
          "Malgun Gothic", "Noto Sans KR", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 24px; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip:focus { left: 16px; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; height: 64px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand__mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 11px;
  background: linear-gradient(150deg, #3B82F6, #1D4ED8);
  color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 14px -6px rgba(37, 99, 235, .8);
  letter-spacing: -.02em;
}
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text strong { font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand__text small { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }

.topbar__actions { display: flex; align-items: center; gap: 10px; }

.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: #EEF2F9; border-radius: 11px;
}
.seg button {
  border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
  color: var(--muted); padding: 6px 11px; border-radius: 8px;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button:hover { color: var(--ink-2); }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.seg--wide button { padding: 8px 14px; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 13.5px; font-weight: 650; cursor: pointer;
  padding: 9px 15px; border-radius: 10px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .1s ease;
}
.btn:hover { border-color: #C8D5EC; background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 8px 18px -12px rgba(37, 99, 235, .95);
}
.btn--primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--ghost:hover { background: #EEF2F9; color: var(--ink-2); }
.btn--sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn--danger { color: var(--red); border-color: #F4D3D0; background: #fff; }
.btn--danger:hover { background: var(--red-soft); border-color: #EFC4C0; }

/* ---------- hero ---------- */

.hero { padding: 46px 0 10px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .13em;
  color: var(--brand); text-transform: uppercase;
}
.eyebrow::before {
  content: ""; width: 18px; height: 2px; border-radius: 2px; background: var(--brand);
}
.hero h1 {
  margin-top: 14px;
  font-size: clamp(28px, 4.4vw, 44px);
  line-height: 1.22; letter-spacing: -.035em; font-weight: 700;
  max-width: 17em;
}
.hero h1 em {
  font-style: normal; color: var(--brand);
  background: linear-gradient(transparent 62%, #DCE7FF 62%);
  padding: 0 2px;
}
.hero__sub {
  margin-top: 14px; max-width: 46em;
  font-size: 15px; color: var(--ink-2);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.chips li {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px;
  box-shadow: var(--shadow-sm);
}
.chips li::before {
  content: "✓"; color: var(--green); font-weight: 700; font-size: 12px;
}

/* ---------- sections & cards ---------- */

.section { margin-top: 34px; }
.section__head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: 14px;
}
.section__title { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.section__desc { margin-top: 3px; font-size: 13px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2--channels { align-items: start; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 22px;
}
.card__head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.card__num {
  flex: none; display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 9px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 12.5px; font-weight: 700;
  margin-top: 1px;
}
.card__title { font-size: 15.5px; font-weight: 700; letter-spacing: -.01em; }
.card__hint { margin-top: 2px; font-size: 12.5px; color: var(--muted); }

/* ---------- form fields ---------- */

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--wide { grid-column: 1 / -1; }

.field > .seg { align-self: flex-start; }

.field > label,
.field .label {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 12.5px; font-weight: 650; color: var(--ink-2);
}
.label__unit { font-size: 11.5px; font-weight: 600; color: var(--muted); }

input[type="text"], input[type="number"], select {
  width: 100%; height: 42px;
  padding: 0 12px;
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  appearance: none; -webkit-appearance: none;
}
input[type="number"] { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
input:hover, select:hover { border-color: #CFD9EA; }
input:focus, select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .16);
}
input::placeholder { color: #A6B2C4; }
input.num { text-align: right; padding-right: 12px; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%236B7A90' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
  padding-right: 34px; cursor: pointer;
}

.affix { position: relative; display: flex; align-items: center; }
.affix__sym {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 13px; font-weight: 650; color: var(--muted); pointer-events: none;
}
.affix input { padding-left: 28px; }
.affix--suffix input { padding-right: 38px; padding-left: 12px; }
.affix__sym--right { left: auto; right: 12px; }

.fi-note { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.fi-note strong { color: var(--ink-2); font-weight: 650; }

.is-hidden { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- pills / badges ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .01em;
  white-space: nowrap;
}
.pill--green { background: var(--green-soft); color: var(--green); }
.pill--amber { background: var(--amber-soft); color: var(--amber); }
.pill--red { background: var(--red-soft); color: var(--red); }
.pill--blue { background: var(--brand-soft); color: var(--brand); }
.pill--grey { background: #EEF2F9; color: var(--muted); }
.pill__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- summary / KPI ---------- */

.kpi-row { display: flex; flex-wrap: wrap; gap: 26px; align-items: flex-end; }
.kpi { min-width: 0; }
.kpi__label { font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: .01em; }
.kpi__value {
  margin-top: 4px; font-size: clamp(26px, 3.2vw, 34px); font-weight: 700;
  letter-spacing: -.035em; line-height: 1.1;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.kpi__value small { font-size: 15px; font-weight: 650; color: var(--muted); letter-spacing: 0; }
.kpi__sub { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.kpi--muted .kpi__value { font-size: 20px; font-weight: 700; color: var(--ink-2); }

.bar {
  display: flex; width: 100%; height: 12px; margin-top: 18px;
  border-radius: 999px; overflow: hidden; background: #EDF1F8;
}
.bar span { display: block; height: 100%; transition: width .25s ease; }

.legend {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 8px 18px; margin-top: 14px;
}
.legend li {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-2); min-width: 0;
}
.legend li > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend i { flex: none; width: 9px; height: 9px; border-radius: 3px; }
.legend b {
  margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- duty block ---------- */

.duty-box {
  margin-top: 16px; padding: 14px 16px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.duty-box__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.duty-box__title { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.rows { margin-top: 10px; }
.rows > div {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 5px 0; font-size: 13px; color: var(--ink-2);
}
.rows > div + div { border-top: 1px dashed var(--line); }
.rows b { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .rows__total { font-weight: 700; color: var(--ink); }
.rows .rows__total b { font-size: 15px; color: var(--brand); }

/* ---------- channels ---------- */

.channel { position: relative; overflow: hidden; }
.channel::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), #60A5FA);
}
.channel--kr::before { background: linear-gradient(90deg, var(--green), #34D399); }

.channel__head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.channel__badge {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 11px;
  font-size: 15px; font-weight: 700; letter-spacing: -.03em;
  background: var(--brand-soft); color: var(--brand);
}
.channel--kr .channel__badge { background: var(--green-soft); color: var(--green); }
.channel__name { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.channel__meta { font-size: 11.5px; color: var(--muted); }

.channel__result {
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft);
}
.result-line {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 4px 0; font-size: 12.5px; color: var(--muted);
}
.result-line b { font-weight: 650; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.result-line--total { margin-top: 6px; padding-top: 9px; border-top: 1px solid var(--line-soft); }
.result-line--total span { color: var(--ink-2); font-weight: 650; }
.result-line--total b { font-weight: 750; color: var(--ink); }

.profit {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.profit__label { font-size: 12px; font-weight: 650; color: var(--muted); }
.profit__value {
  font-size: 27px; font-weight: 700; letter-spacing: -.035em; line-height: 1.15;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum";
}
.profit__value small { font-size: 13.5px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.profit--loss .profit__value { color: var(--red); }
.profit--gain .profit__value { color: var(--ink); }

.margin-box { text-align: right; }
.margin-box__value { font-size: 20px; font-weight: 700; letter-spacing: -.03em; }
.margin-box__label { font-size: 11px; color: var(--muted); font-weight: 600; }
.margin-box__value.is-pos { color: var(--green); }
.margin-box__value.is-warn { color: var(--amber); }
.margin-box__value.is-neg { color: var(--red); }

.solve {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; margin-top: 14px;
}
.solve__item {
  padding: 11px 13px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
}
.solve__label { font-size: 11.5px; font-weight: 650; color: var(--muted); }
.solve__value {
  margin-top: 3px; font-size: 16px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.solve__value.is-unreachable { font-size: 13px; font-weight: 650; color: var(--amber); }

.banner {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding: 13px 16px;
  background: linear-gradient(100deg, #EFF5FF, #F7FAFF);
  border: 1px solid #DCE8FF; border-radius: var(--radius);
  font-size: 13.5px; color: var(--ink-2);
}
.banner strong { color: var(--brand-dark); font-weight: 700; }
.banner__icon {
  flex: none; display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 9px;
  background: #fff; border: 1px solid #D9E5FF; color: var(--brand);
  font-size: 13px; font-weight: 700;
}

.target-ctrl { display: flex; align-items: center; gap: 10px; }
.target-ctrl label { font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
.target-ctrl .affix { width: 92px; }
.target-ctrl input { height: 38px; }

/* ---------- saved list ---------- */

.saves { margin-top: 14px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
thead th {
  text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .03em;
  color: var(--muted); text-transform: uppercase;
  padding: 11px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); color: var(--ink-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FBFCFF; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.win { font-weight: 700; color: var(--ink); }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty {
  padding: 34px 18px; text-align: center; color: var(--muted); font-size: 13px;
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface-2);
}
.empty strong { display: block; color: var(--ink-2); font-size: 13.5px; margin-bottom: 4px; }

/* ---------- footer ---------- */

.foot {
  margin: 44px 0 0; padding: 24px 0 46px;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; line-height: 1.7;
}
.foot p + p { margin-top: 6px; }
.foot strong { color: var(--ink-2); font-weight: 650; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 14px);
  background: #0F172A; color: #fff; font-size: 13px; font-weight: 600;
  padding: 11px 18px; border-radius: 12px; z-index: 80;
  box-shadow: 0 18px 34px -18px rgba(15, 23, 42, .8);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hero { padding-top: 32px; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .card { padding: 18px; border-radius: 16px; }
  .fields { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .topbar__inner { height: 58px; }
  .brand__text small { display: none; }
  .hero h1 { font-size: 27px; }
  .hero__sub { font-size: 14px; }
  .kpi-row { gap: 18px; }
  .kpi__value { font-size: 26px; }
  .profit__value { font-size: 23px; }
  .solve { grid-template-columns: minmax(0, 1fr); }
  .section { margin-top: 26px; }
  .btn { padding: 8px 12px; font-size: 13px; }
  .topbar .btn--ghost span { display: none; }
  #btnExample { display: none; }
  .brand__mark { width: 30px; height: 30px; border-radius: 10px; font-size: 14px; }
  .brand__text strong { font-size: 14px; }
  .seg button { padding: 6px 9px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .toast, .btn, .chips { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
