/* ==========================================================================
   SELLER MATH — Global Stylesheet (Mobile-First, Responsive, Print & CLS-Safe)
   ========================================================================== */

:root {
  --bg-page: #f4f6fa;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-navy: #0f1f3d;
  --bg-navy-soft: #172e59;

  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;

  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  --accent-primary: #1d4ed8;
  --accent-primary-hover: #1e40af;
  --accent-teal: #0f766e;
  --accent-teal-bg: #f0fdfa;
  --accent-amber: #b45309;
  --accent-amber-bg: #fffbeb;

  --positive: #059669;
  --positive-bg: #ecfdf5;
  --negative: #dc2626;
  --negative-bg: #fef2f2;
  --warning-bg: #fff7ed;
  --warning-border: #fdba74;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);

  --font-sans: -apple-system, BlinkMacSystemFont, "Pretendard Variable", "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 16px;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header & Navigation */
.site-header {
  background-color: var(--bg-navy);
  color: var(--text-inverse);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  max-width: 1180px;
  margin: 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  color: var(--text-inverse);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.72rem;
  color: #cbd5e1;
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nav-link {
  color: #e2e8f0;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  text-decoration: none;
}

.nav-link.active {
  background-color: var(--accent-primary);
  color: #ffffff;
}

/* CLS-Safe Ad Slots (AdSense / AdFit) */
.ad-slot {
  width: 100%;
  margin: 18px 0;
  background-color: #f1f5f9;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 8px;
  overflow: hidden;
}

.ad-slot-banner {
  min-height: 100px;
}

.ad-slot-incontent {
  min-height: 250px;
}

@media (min-width: 768px) {
  .ad-slot-banner {
    min-height: 110px;
  }
}

/* Page Hero & Cards */
.page-main {
  padding: 20px 0 48px;
}

.hero-card {
  background: linear-gradient(135deg, var(--bg-navy) 0%, var(--bg-navy-soft) 100%);
  color: var(--text-inverse);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-md);
}

.hero-eyebrow {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  background-color: rgba(255, 255, 255, 0.14);
  color: #bfdbfe;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.hero-card h1 {
  margin: 0 0 8px;
  font-size: 1.55rem;
  line-height: 1.3;
}

.hero-desc {
  margin: 0;
  color: #e2e8f0;
  font-size: 0.95rem;
  max-width: 820px;
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card-title {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-subtitle {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* Grid Layouts */
.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

@media (min-width: 960px) {
  .workspace-grid {
    grid-template-columns: 420px 1fr;
  }
}

.hub-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 22px;
}

@media (min-width: 768px) {
  .hub-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.hub-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.hub-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.hub-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-primary);
  background-color: #eff6ff;
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.hub-card h2 {
  margin: 0 0 8px;
  font-size: 1.12rem;
}

.hub-card p {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Forms & Inputs (Prevent iOS Safari auto-zoom: font-size >= 16px) */
.form-section-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 16px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
}

.form-section-label:first-child {
  margin-top: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 520px) {
  .form-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.field-help {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.input-control,
.select-control {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-control:focus,
.select-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 0;
}

.checkbox-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent-primary);
  flex-shrink: 0;
}

/* Segmented Tabs */
.tab-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background-color: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 9px 10px;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}

.tab-btn.active {
  background-color: #ffffff;
  color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

/* Advanced Settings Panel */
.advanced-panel {
  margin-top: 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
}

.advanced-panel summary {
  padding: 11px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
}

.advanced-panel summary::-webkit-details-marker {
  display: none;
}

.advanced-panel summary::before {
  content: "+ ";
  color: var(--accent-primary);
  font-weight: 800;
}

.advanced-panel[open] summary::before {
  content: "- ";
}

.advanced-inner {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border-color);
}

.vat-item-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.82rem;
}

.vat-item-table th,
.vat-item-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.vat-item-table th {
  font-weight: 700;
  color: var(--text-secondary);
}

/* Buttons */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-primary-hover);
  text-decoration: none;
}

.btn-secondary {
  background-color: var(--bg-navy);
  color: #ffffff;
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-navy-soft);
}

.btn-outline {
  background-color: #ffffff;
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--bg-subtle);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-ghost:hover:not(:disabled) {
  background-color: #f1f5f9;
}

.btn-mini-delete {
  padding: 4px 8px;
  font-size: 0.78rem;
  background-color: var(--negative-bg);
  color: var(--negative);
  border: 1px solid #fecaca;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

/* KPI Summary Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.kpi-card {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 13px;
}

.kpi-card.kpi-highlight {
  background-color: #eff6ff;
  border-color: #bfdbfe;
}

.kpi-card.kpi-positive {
  background-color: var(--positive-bg);
  border-color: #a7f3d0;
}

.kpi-card.kpi-negative {
  background-color: var(--negative-bg);
  border-color: #fecaca;
}

.kpi-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.kpi-value {
  display: block;
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.kpi-sub {
  display: block;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Verification & Alert Boxes */
.verify-badge {
  display: block;
  background-color: var(--positive-bg);
  border: 1px solid #6ee7b7;
  color: #065f46;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.alert-box {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.alert-warning {
  background-color: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: #9a3412;
}

.alert-danger {
  background-color: var(--negative-bg);
  border: 1px solid #fca5a5;
  color: #991b1b;
}

/* 2-Stage Waterfall Breakdown */
.basis-banner {
  background-color: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #1e3a8a;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.waterfall-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

@media (min-width: 768px) {
  .waterfall-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.waterfall-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: #ffffff;
  overflow: hidden;
}

.waterfall-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  background-color: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
}

.stage-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  color: #ffffff;
  white-space: nowrap;
}

.stage-1 {
  background-color: var(--bg-navy);
}

.stage-2 {
  background-color: var(--accent-teal);
}

.stage-tax {
  background-color: var(--accent-amber);
}

.waterfall-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.waterfall-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.waterfall-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.86rem;
}

.waterfall-row:last-child {
  border-bottom: none;
}

.wf-label {
  color: var(--text-secondary);
}

.wf-value {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-minus .wf-value {
  color: var(--negative);
}

.row-plus .wf-value {
  color: var(--positive);
}

.row-subtotal {
  background-color: #f8fafc;
  font-weight: 700;
}

.row-subtotal-accent {
  background-color: #f0fdfa;
  font-weight: 700;
}

.row-subtotal-accent .wf-label,
.row-subtotal-accent .wf-value {
  color: var(--accent-teal);
}

.row-total {
  background-color: #eff6ff;
  font-size: 0.92rem;
}

.row-total .wf-label,
.row-total .wf-value {
  color: #1e3a8a;
}

.row-total-profit {
  background-color: var(--positive-bg);
  font-size: 0.92rem;
}

.row-total-profit .wf-label,
.row-total-profit .wf-value {
  color: #065f46;
}

.row-total-loss {
  background-color: var(--negative-bg);
  font-size: 0.92rem;
}

.row-total-loss .wf-label,
.row-total-loss .wf-value {
  color: #991b1b;
}

/* Tax Reference Card */
.tax-reference-card {
  border: 1px solid #fde68a;
  background-color: var(--accent-amber-bg);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
}

.tax-ref-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tax-summary-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #fcd34d;
}

.tax-type-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: #78350f;
}

.tax-amount-value {
  font-size: 1rem;
  color: #78350f;
  font-variant-numeric: tabular-nums;
}

.tax-math-line {
  margin: 8px 0 4px;
  font-size: 0.84rem;
  font-weight: 600;
  color: #92400e;
}

.tax-assumption-list {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 0.8rem;
  color: #78350f;
}

.tax-excluded-note {
  margin-top: 4px;
  font-weight: 600;
}

/* Formula Details */
.formula-details {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
}

.formula-details summary {
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.formula-body {
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border-color);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.formula-body p {
  margin: 4px 0;
}

/* Tables & Charts */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 600px;
}

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

.data-table thead th {
  background-color: var(--bg-subtle);
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table tr.row-highlight {
  background-color: #eff6ff;
  font-weight: 700;
}

.text-positive {
  color: var(--positive);
  font-weight: 700;
}

.text-negative {
  color: var(--negative);
  font-weight: 700;
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-profit {
  background-color: var(--positive-bg);
  color: #065f46;
}

.status-loss {
  background-color: var(--negative-bg);
  color: #991b1b;
}

.status-be {
  background-color: #fef3c7;
  color: #92400e;
}

/* Pure CSS / SVG Chart Container */
.chart-container {
  margin-top: 16px;
  padding: 14px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.bar-chart-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.bar-chart-row {
  display: grid;
  grid-template-columns: 78px 1fr 110px;
  align-items: center;
  gap: 10px;
  font-size: 0.83rem;
}

.bar-track {
  height: 18px;
  background-color: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.bar-fill-positive {
  background-color: var(--positive);
}

.bar-fill-negative {
  background-color: var(--negative);
}

/* Scenario Toolbar & Helpers */
.scenario-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.section-subtitle {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.helper-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.empty-state {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
}

/* Case Study & FAQ Articles */
.article-section {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.article-section h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
  color: var(--bg-navy);
}

.article-section h3 {
  margin: 20px 0 8px;
  font-size: 1.04rem;
  color: var(--text-primary);
}

.article-section p,
.article-section li {
  font-size: 0.93rem;
  color: var(--text-secondary);
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background-color: var(--bg-subtle);
}

.faq-item summary {
  font-weight: 700;
  font-size: 0.94rem;
  cursor: pointer;
  color: var(--text-primary);
}

.faq-item p {
  margin: 8px 0 0;
  font-size: 0.89rem;
  color: var(--text-secondary);
}

/* Toast Feedback */
.toast-msg {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--positive);
  min-height: 20px;
}

/* Footer */
.site-footer {
  background-color: var(--bg-navy);
  color: #cbd5e1;
  padding: 26px 0;
  margin-top: 32px;
  font-size: 0.84rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.footer-links a {
  color: #e2e8f0;
}

/* Print-Friendly Styles */
@media print {
  body {
    background-color: #ffffff;
    font-size: 12px;
  }
  .site-header,
  .ad-slot,
  .btn-row,
  .scenario-toolbar button,
  .site-footer {
    display: none !important;
  }
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .card,
  .article-section,
  .waterfall-card {
    box-shadow: none;
    border-color: #94a3b8;
    break-inside: avoid;
  }
}
