/* Korea Salary Calculator - shared stylesheet
   Mobile-first, calm financial-tool aesthetic, WCAG AA contrast. */

:root {
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-border: #d8dce3;
  --color-text: #1a2233;
  --color-text-muted: #4b5563;
  --color-primary: #1d4e89;
  --color-primary-dark: #143a66;
  --color-primary-contrast: #ffffff;
  --color-accent: #0a7a4a;
  --color-danger: #b3261e;
  --color-danger-bg: #fdecea;
  --color-focus: #1d4e89;

  --seg-net: #1d7a46;
  --seg-pension: #1d4e89;
  --seg-health: #3b7dd8;
  --seg-ltci: #6aa9e8;
  --seg-employment: #8a5cc7;
  --seg-income-tax: #c77b1e;
  --seg-local-tax: #e0a24a;

  --radius: 6px;
  --max-width: 880px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #12161f;
    --color-surface: #1a2030;
    --color-border: #333c4f;
    --color-text: #eef1f6;
    --color-text-muted: #aab2c5;
    --color-primary: #6ea3e6;
    --color-primary-dark: #4d86d6;
    --color-primary-contrast: #0c1220;
    --color-accent: #4fd192;
    --color-danger: #ff8a80;
    --color-danger-bg: #3a1c1c;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Pretendard, Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.55;
}

img { max-width: 100%; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  padding: var(--space-2) var(--space-3);
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus {
  left: 0;
}

a { color: var(--color-primary); }
a:hover { color: var(--color-primary-dark); }

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

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.site-header__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.site-header__brand {
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--color-text);
}
.lang-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}
.lang-nav a { text-decoration: none; }
.lang-nav a[aria-current="page"] {
  font-weight: 700;
  color: var(--color-text);
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-3);
}

.hero {
  padding: var(--space-4) 0 var(--space-3);
}
.hero__eyebrow {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  border-radius: 999px;
  padding: var(--space-1) var(--space-3);
  margin-bottom: var(--space-2);
}
.hero h1 {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  margin: 0 0 var(--space-2);
  line-height: 1.25;
}
.hero p {
  color: var(--color-text-muted);
  font-size: 1.05rem;
  max-width: 62ch;
}

h2 {
  font-size: 1.3rem;
  margin-top: var(--space-5);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-4);
}
h3 { font-size: 1.05rem; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.notice {
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface));
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  font-size: 0.95rem;
}
.notice--foreign { border-left-color: var(--color-accent); }

/* Form */
fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: 0 0 var(--space-4);
}
legend {
  font-weight: 600;
  padding: 0 var(--space-2);
}

.field {
  position: relative;
  margin-bottom: var(--space-3);
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: var(--space-1);
}
.field .help-text {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: var(--space-1) 0 0;
}
.field .field-error {
  color: var(--color-danger);
  font-size: 0.85rem;
  margin-top: var(--space-1);
  min-height: 1.1em;
}
.field input[type="number"],
.field input[type="text"],
.field select {
  width: 100%;
  max-width: 22rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  min-height: 44px;
}
.field input:invalid { box-shadow: none; }

/* Required / Optional form sections */
.form-section__heading {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3);
}
.form-section--required,
.form-section--optional {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: 0 0 var(--space-4);
}
.form-section--optional > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-2);
  row-gap: 0.2rem;
  padding: var(--space-1) 0;
  margin: -0.1rem 0 0;
}
.form-section--optional > summary::-webkit-details-marker { display: none; }
.form-section--optional > summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 0.4rem;
  color: var(--color-primary);
}
.form-section--optional[open] > summary::before { content: "\25BE"; }
.form-section--optional > summary:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: 3px;
}
.optional-summary-text {
  font-size: 0.85rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--color-text-muted);
}
.form-section--optional[open] > summary .optional-summary-text { display: none; }
.form-section__content {
  padding-top: var(--space-3);
  margin-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

/* Field label row + contextual help popover.
   The popover's positioning context is the surrounding .field (or, for the
   withholding-percentage fieldset, the fieldset itself via #field-
   withholdingPercentage below) rather than .field-label-row, so an open
   popover anchors below the whole field - input, help text, and error
   message - instead of overlapping the field's own input. */
.field-label-row {
  display: flex;
  align-items: center;
  /* nowrap is required, not just a default: with flex-wrap:wrap, the
     browser decides line breaks using each item's un-shrunk (max-content)
     size, so a long label gets pushed to its own flex line entirely
     instead of shrinking in place beside the button. With nowrap (and
     min-width:0 + flex:1 1 auto on the label below), the label shrinks and
     wraps its own text while the button stays pinned on the same row. */
  flex-wrap: nowrap;
  gap: 0.45rem;
  margin-bottom: var(--space-1);
}
.field-label-row label {
  margin-bottom: 0;
  /* flex-grow:0 keeps the label at its natural text width (button sits
     immediately beside it) whenever there's room, e.g. on desktop.
     flex-shrink:1 + min-width:0 (flex items default to min-width:auto,
     which refuses to shrink below the single-line max-content width) lets
     the label wrap its own text and shrink instead of pushing the button
     onto its own line when space is tight, e.g. on mobile. */
  min-width: 0;
  flex: 0 1 auto;
}
.field-label-row__text {
  font-weight: 600;
  min-width: 0;
  flex: 0 1 auto;
}
#field-withholdingPercentage { position: relative; }

.help-trigger {
  appearance: none;
  cursor: pointer;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-primary);
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
}
.help-trigger:hover { background: var(--color-bg); }
.help-trigger[aria-expanded="true"] {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  border-color: var(--color-primary);
}

.help-popover {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  margin-top: 0.4rem;
  width: min(320px, 100%);
  max-width: calc(100vw - 2rem);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  font-size: 0.85rem;
  line-height: 1.55;
  font-weight: 400;
}
.help-popover[hidden] { display: none; }
.help-popover__title {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0 0 var(--space-2);
}
.help-popover__body { margin: 0 0 var(--space-2); }
.help-popover__body ul {
  margin: 0 0 var(--space-2);
  padding-left: 1.1rem;
}
.help-popover__body li { margin-bottom: 0.2rem; }
.help-popover__note {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
  border-left: 3px solid var(--color-primary);
  padding: var(--space-2);
  margin: 0 0 var(--space-2);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.help-popover__link { display: inline-block; font-size: 0.85rem; font-weight: 600; }

@media (max-width: 480px) {
  .help-popover { width: 100%; }
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.segmented label {
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  font-weight: 500;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.segmented input:checked + label {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}
.segmented input:focus-visible + label {
  outline: 3px solid var(--color-focus);
  outline-offset: -3px;
}

.toggle-list {
  display: grid;
  gap: var(--space-2);
}
.toggle {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.toggle input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.toggle label { font-weight: 500; }
.toggle .help-text { margin-top: 0.2rem; }
.toggle[data-disabled="true"] { opacity: 0.6; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

button {
  font: inherit;
  cursor: pointer;
  min-height: 44px;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 600;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover { background: var(--color-bg); }

.error-summary {
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  color: var(--color-danger);
}
.error-summary a { color: var(--color-danger); }
.error-summary__heading { font-weight: 700; margin: 0 0 var(--space-2); }

/* Results */
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin-top: var(--space-3);
  align-items: start;
}
@media (min-width: 640px) {
  .results-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  min-width: 0; /* allow grid children to shrink instead of overflowing */
}
.result-card h3 {
  margin-top: 0;
  margin-bottom: var(--space-1);
}
.result-card__subtitle {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0 0 var(--space-3);
}
/* Monthly take-home pay is the primary result: a restrained accent border,
   not a different layout or color scheme, keeps it consistent with the
   rest of the site while giving it slightly more visual weight. */
.result-card--monthly {
  border: 2px solid var(--color-primary);
}
.result-card--visualization {
  grid-column: 1 / -1;
}

#results table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-3);
  overflow-x: auto;
}
#results th, #results td {
  padding: 0.55rem var(--space-2);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
#results th {
  text-align: left;
  white-space: normal;
  font-weight: 500;
}
#results td {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#results tr:last-child th,
#results tr:last-child td {
  font-weight: 700;
  border-top: 2px solid var(--color-text);
}

.deduction-bar {
  display: flex;
  width: 100%;
  height: 28px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  margin: var(--space-3) 0;
}
.deduction-bar__segment { height: 100%; }
.segment-net { background: var(--seg-net); }
.segment-pension { background: var(--seg-pension); }
.segment-health { background: var(--seg-health); }
.segment-ltci { background: var(--seg-ltci); }
.segment-employment { background: var(--seg-employment); }
.segment-income-tax { background: var(--seg-income-tax); }
.segment-local-tax { background: var(--seg-local-tax); }

.deduction-legend {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}
.deduction-legend__swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
  margin-right: 0.4rem;
  vertical-align: -1px;
}

#copy-link-feedback {
  font-size: 0.85rem;
  color: var(--color-accent);
  min-height: 1.2em;
}

.language-banner {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin: var(--space-3) auto;
  max-width: var(--max-width);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
}

/* Ad slots: hidden by default, reserved dimensions available via .ad-enabled */
.ad-slot {
  display: none;
}
.ad-slot.ad-enabled {
  display: block;
  min-height: 100px;
  margin: var(--space-4) 0;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}
table.data-table th, table.data-table td {
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

.site-footer {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-3);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.site-footer__inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

@media print {
  .site-header, .site-footer, .language-banner, .form-actions, .ad-slot, #calculator-form {
    display: none !important;
  }
  body { background: #fff; color: #000; }
  main { max-width: 100%; }
}
