:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e1e7ef;
  --text: #0f172a;
  --muted: #55657a;
  --primary: #0f4c81;
  --primary-dark: #0a355c;
  --primary-soft: #eaf2fb;
  --accent: #d97706;
  --accent-soft: #fef3c7;
  --success: #0f766e;
  --success-soft: #d1fae5;
  --warn-soft: #fef3c7;
  --warn-text: #92400e;
  --radius: 12px;
  --shadow: 0 1px 6px rgba(15, 23, 42, 0.05);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: #0b1f33;
  color: #ffffff;
  border-bottom: 3px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--accent);
  color: #0b1f33;
  font-weight: 800;
  font-size: 0.95rem;
}

.brand-title {
  display: block;
  font-size: 1.12rem;
  font-weight: 700;
}

.brand-sub {
  display: block;
  font-size: 0.76rem;
  color: #b7c8db;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-outline {
  border: 1px solid rgba(255,255,255,0.35);
  color: #ffffff;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}
.btn-outline:hover { background: rgba(255,255,255,0.12); text-decoration: none; }

/* Unit Toggle */
.unit-toggle {
  display: inline-flex;
  background: rgba(255,255,255,0.14);
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
}

.card .unit-toggle { background: #e2e8f0; }

.toggle-btn {
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: #cbd5e1;
  transition: 0.15s ease;
}

.card .toggle-btn { color: var(--muted); }
.toggle-btn.active {
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* Hidden AdSense slots until connected */
.ad-slot[hidden],
.ad-slot:empty {
  display: none !important;
}

/* Hero / Filters */
.hero-bar { padding: 18px 0 6px; }
.hero-bar h1 {
  margin: 0 0 4px;
  font-size: clamp(1.4rem, 2.3vw, 1.85rem);
  font-weight: 800;
  color: #0b1f33;
}
.hero-lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.94rem;
}

.section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.sec-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.sec-btn:hover { border-color: var(--primary); color: var(--primary); }
.sec-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.search-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 2.3fr 1fr 0.75fr auto;
  gap: 10px;
  align-items: center;
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap input {
  width: 100%;
  padding: 10px 38px 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.94rem;
  outline: none;
}

.search-toggle-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.95rem;
  display: grid;
  place-items: center;
}
.search-toggle-btn:hover { background: #edf2f7; color: var(--text); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
  max-height: 360px;
  overflow-y: auto;
  z-index: 60;
}

.sd-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-bottom: 1px solid #f1f5f9;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.sd-item:last-child { border-bottom: none; }
.sd-item:hover, .sd-item.active { background: var(--primary-soft); }
.sd-item.selected { background: #e0ecfa; }
.sd-name { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.sd-sec { font-size: 0.75rem; color: var(--muted); background: #f1f5f9; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }

.search-input-wrap input:focus,
.filter-select:focus,
.calc-inputs input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.14);
}

.filter-select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.88rem;
  background: #ffffff;
  color: var(--text);
}

.btn-reset {
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.btn-reset:hover { background: #e2e8f0; color: var(--text); }

/* Link from the calculator card to the statically rendered activity page */
.btn-detail {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-detail:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  text-decoration: none;
}
.btn-detail[hidden],
.btn-detail[aria-disabled="true"] { display: none; }

/* Single-Column Workspace (Full Width Calculator) */
.workspace-single {
  margin-top: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  margin-top: 16px;
  align-items: start;
}

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

.results-card {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 780px;
}

.results-header {
  padding: 12px 16px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.83rem;
  color: var(--muted);
  font-weight: 600;
}

.results-list { overflow-y: auto; flex: 1; }

.act-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid #edf2f7;
  padding: 13px 16px;
  cursor: pointer;
  display: block;
  transition: background 0.12s ease;
}
.act-item:hover { background: #f8fbff; }
.act-item.selected {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  padding-left: 12px;
}

.act-item-top {
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 3px;
}
.act-item-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text);
}

/* Configurator Box */
.config-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

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

.config-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #334155;
}

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

.crew-total-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--primary-soft);
  border: 1px solid #cce0f5;
  color: var(--primary-dark);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  margin-bottom: 14px;
}

.calc-stack { display: flex; flex-direction: column; gap: 18px; }

.meta-pills { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #edf2f7;
  color: #334155;
}
.pill-domain { background: var(--primary-soft); color: var(--primary-dark); }
.pill-csi { background: var(--accent-soft); color: #92400e; }
.pill-verified { background: var(--success-soft); color: var(--success); }
.pill-warn { background: var(--warn-soft); color: var(--warn-text); }
.pill-flag {
  background: var(--warn-soft);
  color: var(--warn-text);
  border: 1px solid rgba(146, 64, 14, 0.25);
  white-space: normal;
  text-align: left;
}
.pill-flag[hidden] { display: none; }

.calc-title { margin: 0 0 4px; font-size: 1.35rem; color: #0b1f33; }
.subtitle { margin: 0 0 14px; color: var(--muted); font-size: 0.88rem; }
.activity-link-row { margin: -6px 0 16px; }
.activity-link-row[hidden] { display: none; }
.activity-link-row .btn-detail { vertical-align: middle; }

.calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.calc-header h2 { margin: 0; font-size: 1.05rem; color: #0b1f33; }
.calc-header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.calc-inputs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.calc-inputs label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
}

.calc-inputs input[type="number"] {
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.slider-wrap {
  grid-column: 1 / -1;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
}

.slider-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--muted);
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.out-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.out-card.highlight {
  background: #0b1f33;
  border-color: #0b1f33;
  color: #ffffff;
}

.out-card span {
  font-size: 0.74rem;
  font-weight: 600;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.out-card strong { font-size: 1.32rem; font-weight: 800; }
.out-card.highlight strong { color: #fbbf24; }

.breakdown-panel {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px 16px;
}
.breakdown-panel h4 { margin: 0 0 6px; font-size: 0.94rem; color: #0b1f33; }
.formula-mode { margin: 0 0 8px; font-size: 0.83rem; color: var(--muted); }
.formula-steps { margin: 0; padding-left: 18px; font-size: 0.85rem; display: grid; gap: 5px; }
.formula-steps code { background: #e2e8f0; padding: 1px 5px; border-radius: 4px; font-size: 0.81rem; }

.spec-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 0;
}
.spec-grid > div {
  background: var(--surface-alt);
  border: 1px solid #e6ecf2;
  border-radius: 8px;
  padding: 11px 12px;
}
.spec-grid dt {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}
.spec-grid dd { margin: 0; font-size: 0.89rem; color: var(--text); }
.spec-grid .full-span { grid-column: 1 / -1; }

/* Detail Page Shared */
.kpi-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.kpi-box { background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.kpi-label { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.kpi-value { display: block; font-size: 1.4rem; color: var(--primary-dark); margin: 2px 0; }
.kpi-unit { display: block; font-size: 0.78rem; color: var(--muted); }
.page-main { padding-top: 14px; padding-bottom: 36px; }
.breadcrumbs { font-size: 0.84rem; color: var(--muted); margin: 10px 0 14px; }
.detail-layout { display: grid; gap: 18px; }
.related-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.related-list a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.86rem; font-weight: 600; }
.related-list a span { color: var(--success); white-space: nowrap; }

.guide-section { margin-top: 24px; }
.guide-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 10px; }

.site-footer {
  margin-top: 32px;
  padding: 18px 0;
  border-top: 1px solid var(--border);
  background: #ffffff;
  color: var(--muted);
  font-size: 0.83rem;
}

@media (max-width: 1060px) {
  .workspace { grid-template-columns: 1fr; }
  .results-card { max-height: 360px; }
  .search-panel { grid-template-columns: 1fr 1fr; }
  .search-input-wrap { grid-column: 1 / -1; }
  .calc-inputs { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  .config-grid, .calc-inputs, .output-grid, .spec-grid, .kpi-strip, .guide-grid, .related-list {
    grid-template-columns: 1fr;
  }
  .search-panel { grid-template-columns: 1fr; }
}
