:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --navy: #0f172a;
  --navy-soft: #1e293b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
  --max-w: 1120px;
}

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

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a:hover {
  text-decoration: underline;
}

.num {
  font-variant-numeric: tabular-nums;
}

.container {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: var(--navy);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}

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

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  font-size: 0.9rem;
}

.nav-links a {
  color: #cbd5e1;
  font-weight: 500;
}

.nav-links a:hover,
.nav-links a.active {
  color: #fff;
  text-decoration: none;
}

/* Main */
main {
  flex: 1;
  padding: 28px 0 64px;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-subtle);
  margin-bottom: 14px;
}

.breadcrumbs a {
  color: var(--text-muted);
}

/* Hero */
.hero {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 65%, #172554 100%);
  color: #fff;
  padding: 44px 0 48px;
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  margin: 12px 0 12px;
  font-size: clamp(1.75rem, 3.6vw, 2.5rem);
  line-height: 1.18;
  letter-spacing: -0.025em;
  max-width: 820px;
}

.hero p {
  margin: 0;
  color: #cbd5e1;
  font-size: 1.05rem;
  max-width: 720px;
}

.hero-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.pill-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.16);
  transition: background 0.15s ease;
}

.pill-link:hover {
  background: rgba(255, 255, 255, 0.18);
  text-decoration: none;
}

.pill-link.highlight {
  background: #10b981;
  border-color: #10b981;
  color: #052e16;
}

.pill-link.highlight:hover {
  background: #34d399;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.new {
  background: #fef3c7;
  color: #92400e;
}

.badge.green {
  background: var(--emerald-soft);
  color: var(--emerald);
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 8px 0 8px;
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  line-height: 1.22;
  letter-spacing: -0.02em;
}

.page-header p {
  margin: 0;
  color: var(--text-muted);
  max-width: 780px;
}

/* Search & Filter Bar on Home */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.search-input {
  min-width: 240px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-size: 0.92rem;
  background: var(--surface);
}

/* Tool Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

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

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  text-decoration: none;
}

.tool-card h2 {
  margin: 10px 0 8px;
  font-size: 1.08rem;
  color: var(--text);
  line-height: 1.3;
}

.tool-card p {
  margin: 0 0 14px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.tool-card .card-cta {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--accent);
}

/* Calculator Workspace */
.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .calc-layout {
    grid-template-columns: 1fr;
  }
}

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

.panel-title {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.field label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.field input[type="number"],
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.96rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-subtle);
  margin-top: 4px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  cursor: pointer;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.checkbox-row span {
  font-size: 0.88rem;
  font-weight: 600;
}

/* KPI Output Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.kpi.primary {
  background: var(--emerald-soft);
  border-color: #a7f3d0;
}

.kpi.primary.negative {
  background: var(--rose-soft);
  border-color: #fecdd3;
}

.kpi.warning {
  background: var(--amber-soft);
  border-color: #fde68a;
}

.kpi-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-subtle);
}

.kpi-val {
  margin-top: 4px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.kpi.primary .kpi-val {
  color: #065f46;
}

.kpi.primary.negative .kpi-val {
  color: #9f1239;
}

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

/* Stacked Distribution Bar */
.bar-wrap {
  margin: 16px 0 18px;
}

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

.bar-seg {
  height: 100%;
  transition: width 0.2s ease;
}

.bar-profit { background: #10b981; }
.bar-fees { background: #f59e0b; }
.bar-cogs { background: #3b82f6; }
.bar-ship { background: #8b5cf6; }

.bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}

/* Breakdown Table */
.breakdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.breakdown-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.breakdown-list li.total-row {
  font-weight: 700;
  color: var(--text);
}

.impact-callout {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border: 1px solid #fcd34d;
  font-size: 0.88rem;
  color: #78350f;
}

.impact-callout strong {
  color: #451a03;
}

.note-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
  font-size: 0.84rem;
  color: #1e3a8a;
}

.note-box ul {
  margin: 0;
  padding-left: 18px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: var(--surface-alt);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

/* Reverse Solver & Batch CSV Sections */
.sub-section {
  margin-top: 24px;
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.inline-controls .field {
  flex: 1;
  min-width: 150px;
}

.reverse-result {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--emerald-soft);
  border: 1px solid #a7f3d0;
  font-size: 0.92rem;
  color: #064e3b;
  display: none;
}

.reverse-result.show {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Data Tables */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

table.data-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table tr.winner-row {
  background: #ecfdf5;
}

.winner-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #10b981;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Editorial Content Sections (SEO & AdSense Value) */
.content-section {
  margin-top: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.content-section h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
}

.faq-list details {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.faq-list details:last-child {
  border-bottom: 1px solid var(--border);
}

.faq-list summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.96rem;
  list-style: none;
}

.faq-list summary::-webkit-details-marker {
  display: none;
}

.faq-list p {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.related-card {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.related-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

/* Footer */
.site-footer {
  background: var(--navy);
  color: #94a3b8;
  padding: 36px 0 28px;
  font-size: 0.85rem;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  gap: 28px;
  margin-bottom: 24px;
}

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

.site-footer h3 {
  margin: 0 0 10px;
  color: #fff;
  font-size: 0.92rem;
}

.site-footer ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-footer li {
  margin-bottom: 6px;
}

.site-footer a {
  color: #cbd5e1;
}

.footer-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 16px;
  font-size: 0.78rem;
  color: #64748b;
}

.prose {
  max-width: 820px;
}

.prose h2 {
  margin-top: 28px;
}

.prose p, .prose li {
  color: var(--text-muted);
}
