/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f5f5;
  --surface:   #ffffff;
  --border:    #e0e0e0;
  --text:      #1a1a1a;
  --text-muted:#666;
  --primary:   #c0392b;   /* safety red */
  --primary-dk:#922b21;
  --ok:        #1e8449;
  --ok-bg:     #d5f5e3;
  --marginal:  #d4ac0d;
  --marginal-bg:#fef9e7;
  --bad:       #922b21;
  --bad-bg:    #fadbd8;
  --radius:    10px;
  --shadow:    0 2px 8px rgba(0,0,0,.10);
  font-size: 16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.4;
}

/* ── App shell ──────────────────────────────────────────────── */
#app {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px 10px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.header-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.header-text p {
  font-size: .75rem;
  opacity: .8;
  margin-top: 2px;
}

#install-btn {
  flex-shrink: 0;
  background: none;
  border: 1.5px solid rgba(255,255,255,.7);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
#install-btn:hover { background: rgba(255,255,255,.15); }

/* ── Tab nav ────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  background: var(--primary-dk);
  border-bottom: 2px solid rgba(0,0,0,.15);
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,.65);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}

.tab-btn.active {
  color: #fff;
  border-bottom-color: #fff;
}

/* ── Sling type toggle ──────────────────────────────────────── */
#sling-type-strip {
  display: flex;
  background: var(--primary-dk);
  padding: 7px 12px;
  gap: 6px;
  border-bottom: 1px solid rgba(0,0,0,.2);
}

.sling-type-btn {
  padding: 4px 16px;
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,.4);
  background: transparent;
  color: rgba(255,255,255,.65);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}

.sling-type-btn:hover {
  border-color: rgba(255,255,255,.7);
  color: #fff;
}

.sling-type-btn.active {
  background: #fff;
  border-color: #fff;
  color: var(--primary-dk);
}

/* ── Panels ─────────────────────────────────────────────────── */
main { flex: 1; padding: 12px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Table ──────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
}

.wll-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 920px;
  font-size: .82rem;
}

.wll-table th {
  background: #2c3e50;
  color: #fff;
  padding: 8px 6px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.1);
}

.wll-table th.col-sling {
  text-align: left;
  padding-left: 12px;
  border-right: 2px solid rgba(255,255,255,.25) !important;
  min-width: 80px;
}

.wll-table th.col-section-group {
  background: #1a2a3a;
  text-align: center;
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-bottom: 2px solid rgba(255,255,255,.15);
  border-right: 2px solid rgba(255,255,255,.2);
}

.wll-table th.col-angle-group {
  background: #253545;
  text-align: center;
  font-size: .72rem;
  letter-spacing: .04em;
  border-bottom: 1px solid rgba(255,255,255,.15);
  border-right: 1px solid rgba(255,255,255,.15);
}

/* Divider after the last column of each section */
.wll-table .section-end {
  border-right: 2px solid rgba(255,255,255,.25) !important;
}
.wll-table tbody .section-end {
  border-right: 2px solid var(--border) !important;
}

.wll-table th.active-config {
  background: var(--primary);
}

.config-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 4px;
  display: block;
}

.config-icon svg {
  width: 100%;
  height: 100%;
  color: inherit;
}

th .config-icon svg { color: rgba(255,255,255,.9); }

th span { display: block; font-size: .7rem; }

/* Table rows */
.wll-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}

.wll-table tbody tr:hover { background: rgba(0,0,0,.03); }

.cell-sling {
  padding: 10px 12px;
  border-right: 2px solid var(--border) !important;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
}

.cell-sling small {
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 400;
}

.wll-table th.col-mm {
  border-right: 2px solid rgba(255,255,255,.25) !important;
}

.cell-mm {
  text-align: center;
  padding: 10px 6px;
  border-right: 2px solid var(--border) !important;
  font-size: .82rem;
  color: var(--text-muted);
  border-right: 2px solid var(--border) !important;
  white-space: nowrap;
}

.sling-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--sling-color, #999);
  flex-shrink: 0;
}

.cell-wll {
  text-align: center;
  padding: 10px 6px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}

.cell-wll.active-col { color: var(--text); font-weight: 700; }

/* Row highlight states (single-config mode) */
.row-ok        { background: var(--ok-bg)       !important; }
.row-marginal  { background: var(--marginal-bg)  !important; }
.row-insufficient { background: var(--bad-bg)    !important; opacity: .5; }

.row-ok .cell-wll.active-col        { color: var(--ok); }
.row-marginal .cell-wll.active-col  { color: var(--marginal); }
.row-insufficient .cell-wll.active-col { color: var(--bad); }

/* Per-cell states (all-configs mode) */
.cell-all-ok  { color: var(--ok); font-weight: 600; background: var(--ok-bg); }
.cell-all-bad { color: #bbb; background: #f5f5f5; }
.row-all-none { opacity: .45; }

/* Factor row */
.row-factor .cell-factor-label,
.row-factor .cell-mm,
.row-factor .cell-factor {
  background: #eef2f7;
  font-weight: 700;
  font-size: .78rem;
  color: var(--text);
  padding: 8px 6px;
  text-align: center;
}

.row-factor .cell-factor-label {
  text-align: left;
  padding-left: 12px;
}

/* ── Calculator ─────────────────────────────────────────────── */
/* Note: display is controlled by .tab-panel / .tab-panel.active */
#calc-panel.active { display: flex; flex-direction: column; gap: 16px; }

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: .9rem;
}

.form-group input[type="number"] {
  width: 100%;
  max-width: 240px;
  padding: 10px 14px;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}

.form-group input[type="number"]:focus { border-color: var(--primary); }

/* Config picker grid */
#config-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.config-card input { display: none; }

.config-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  text-align: center;
}

.config-card-inner .config-icon {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.config-card-inner .config-icon svg {
  height: 44px;
  width: auto;
  max-width: 100%;
}
.config-card-inner span { font-size: .78rem; font-weight: 600; }
.config-card-inner small { font-size: .7rem; color: var(--text-muted); }
.config-context { font-size: .65rem; color: var(--text-muted); line-height: 1.2; }

.config-card input:checked + .config-card-inner {
  border-color: var(--primary);
  background: #fdf2f1;
  color: var(--primary);
}

.config-card input:checked + .config-card-inner .config-icon { color: var(--primary); }

/* Submit button — hidden, calculation is live */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* Result area */
#calc-result { display: flex; flex-direction: column; gap: 12px; }

.result-summary {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .95rem;
}

.result-ok   { color: var(--ok);  background: var(--ok-bg);      padding: 12px; border-radius: var(--radius); }
.result-warn { color: var(--bad); background: var(--bad-bg);      padding: 12px; border-radius: var(--radius); }

.result-label { font-weight: 600; margin-bottom: 8px; font-size: .9rem; }

.result-section { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

.result-section-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.calc-options {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.calc-option {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid var(--ok);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: .78rem;
  white-space: nowrap;
}

/* ── Legend ─────────────────────────────────────────────────── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: .78rem;
  color: var(--text-muted);
  padding: 8px 0;
}

.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}

/* ── Disclaimer ─────────────────────────────────────────────── */
.disclaimer {
  font-size: .72rem;
  color: var(--text-muted);
  background: #fff8e1;
  border-left: 3px solid var(--marginal);
  padding: 8px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-top: 4px;
}

/* ── Section filter strip ───────────────────────────────────── */
.section-filter {
  display: flex;
  gap: 6px;
  padding: 10px 12px 4px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}

.filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* Filtered table needs no forced min-width — it fits in fewer columns */
.wll-table.table-filtered {
  min-width: 0;
}

/* ── Grade badge (chain slings) ─────────────────────────────── */
.grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
  white-space: nowrap;
}

.grade-badge.grade-8  { background: #5d6d7e; }
.grade-badge.grade-10 { background: #2e4057; }

/* ── Grade section header rows ──────────────────────────────── */
.row-grade-header { background: #eef2f7 !important; }
.cell-grade-header {
  padding: 6px 12px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Responsive tweaks ──────────────────────────────────────── */
@media (max-width: 480px) {
  header h1 { font-size: 1rem; }
  #config-picker { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .wll-table th, .wll-table td { font-size: .75rem; padding: 5px 6px; }
  .wll-table .col-config .config-icon svg { height: 28px; }
  .cell-sling strong { font-size: .75rem; }
}
