/* =========================================================
 * screw-selection / css/style.css
 * Shared styling for all pages. Light engineering theme.
 * ========================================================= */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dfe4ea;
  --text: #1f2937;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1e40af;
  --accent-light: #eaf1fe;
  --warn-bg: #fef3c7;
  --warn-border: #f59e0b;
  --err-bg: #fee2e2;
  --err-border: #dc2626;
  --ok-bg: #dcfce7;
  --ok-border: #16a34a;
  --grid-color: #d9dee5;
  --axis-color: #8a94a3;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

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

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 7px;
  font-size: 15px;
}

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.tabs a {
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.tabs a:hover { background: var(--accent-light); color: var(--accent-dark); text-decoration: none; }
.tabs a.active { background: var(--accent); color: #fff; }

.topbar .spacer { flex: 1; }

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lang-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
}
.lang-wrap select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn-home { background: var(--accent); color: #fff; }
.btn-mail { background: var(--surface); color: var(--accent-dark); border-color: var(--accent); }
.btn-theme { background: var(--surface); color: var(--accent-dark); border-color: var(--border); }
.btn-theme:hover { border-color: var(--accent); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-weight: 500;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------- layout ---------------- */
.container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 26px 22px 40px;
}

h1.page-title {
  font-size: 24px;
  margin: 0 0 6px;
}

.live-note {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 18px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
}

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

.card h2 {
  font-size: 16.5px;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--accent-dark);
}

/* ---------------- inputs ---------------- */
.input-row {
  display: grid;
  grid-template-columns: 1fr 120px 66px;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  border-radius: 6px;
}
.input-row:hover { background: #f8fafc; }
.input-row.row-bad { background: var(--err-bg); outline: 1px solid var(--err-border); }
.input-row.seg-row { grid-template-columns: auto 96px 36px auto 60px 36px 30px 30px 30px 34px; }
.input-row.seg-row label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.input-row label { font-size: 14px; }
.input-row input {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: Consolas, "Courier New", monospace;
  text-align: right;
  background: #fbfcfe;
}
.input-row input:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
.unit { color: var(--text-muted); font-size: 12.5px; }

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------------- results ---------------- */
.result-row {
  display: grid;
  grid-template-columns: 1fr auto minmax(96px, auto) 58px;
  align-items: baseline;
  gap: 10px;
  padding: 5px 6px;
  border-radius: 6px;
  border-bottom: 1px dashed #edf0f4;
}
.result-row:last-child { border-bottom: none; }
.result-row.row-hl { background: var(--accent-light); border: 1px solid var(--accent); }
.res-label { font-size: 14px; }
.res-formula { color: var(--text-muted); font-size: 12px; font-family: Consolas, monospace; }
.res-value {
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
  font-size: 14.5px;
  text-align: right;
  color: var(--text);
}
.row-hl .res-value { color: var(--accent-dark); }

/* ---------------- notes & alerts ---------------- */
.note {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin: 12px 0 0;
  color: var(--text);
}
.note.ratio {
  background: var(--ok-bg);
  border-left-color: var(--ok-border);
  display: none;
}
.alert {
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin: 12px 0 0;
  display: none;
}
.alert.warn { background: var(--warn-bg); border-left: 3px solid var(--warn-border); }
.alert.err { background: var(--err-bg); border-left: 3px solid var(--err-border); }

/* ---------------- chart ---------------- */
.chart-box { width: 100%; }
/* editable case name in the comparison header (wave 25) */
.cmp-name {
  width: 100%;
  min-width: 90px;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
}
.cmp-name:hover { border-color: var(--border); }
.cmp-name:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.life-bring { margin-top: 8px; }
/* per-case restore link in the batch report pack (wave 27) */
.pack-share { font-size: 10.5px; word-break: break-all; color: #555; margin: 6px 0 0; }
/* source tag in the debug storage dump (wave 27) */
.dbg-src { font-size: 10.5px; font-weight: 400; color: var(--text-muted); margin-left: 6px; }
#curve {
  width: 100%;
  height: 320px;
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.chart-legend {
  display: flex;
  gap: 22px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------------- home ---------------- */
.hero {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 42px 36px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 10px; font-size: 28px; }
.hero p { margin: 0; font-size: 15.5px; opacity: 0.92; max-width: 760px; }

.cards3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.nav-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.nav-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.nav-card .ic { font-size: 26px; }
.nav-card h3 { margin: 0; font-size: 17px; color: var(--accent-dark); }
.nav-card p { margin: 0; font-size: 13.5px; color: var(--text-muted); flex: 1; }
.nav-card .go { font-weight: 700; color: var(--accent); font-size: 14px; }

.feat-list {
  margin: 0;
  padding: 0 0 0 18px;
}
.feat-list li { margin: 4px 0; font-size: 14.5px; }

/* ---------------- theory ---------------- */
.th-sec { margin-bottom: 20px; }
.th-sec h3 { margin: 0 0 6px; font-size: 15.5px; color: var(--accent-dark); }
.th-sec p { margin: 0; font-size: 14.5px; }
.formula-block {
  font-family: Consolas, "Courier New", monospace;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 13.5px;
  overflow-x: auto;
  white-space: nowrap;
}
.chain {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 10px 0 4px;
  font-size: 12.5px;
  font-family: Consolas, monospace;
}
.chain .step {
  background: var(--accent-light);
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  border-radius: 6px;
  padding: 4px 10px;
  white-space: nowrap;
}
.chain .arr { color: var(--text-muted); }

.disclaimer {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

/* ---------------- footer ---------------- */
.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 16px 22px;
  margin-top: 10px;
}
.footer a { color: var(--text-muted); }
.footer a:hover { color: var(--accent); }

/* ---------------- badges & checks ---------------- */
.badge {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: #15803d; border: 1px solid var(--ok-border); }
.badge.ng { background: var(--err-bg); color: #b91c1c; border: 1px solid var(--err-border); }
.badge.warn { background: var(--warn-bg); color: #b45309; border: 1px solid var(--warn-border); }

.arr-row { margin-bottom: 8px; }
.arr-select {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfe;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.arr-select:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }

/* ---------------- catalog table ---------------- */
.cat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.cat-table th, .cat-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.cat-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12.5px;
}
.cat-table td.num, .cat-table th.num { text-align: right; font-family: Consolas, "Courier New", monospace; }
.cat-table tbody tr { cursor: pointer; }
.cat-table tbody tr:hover { background: #f8fafc; }
.cat-table tbody tr.sel {
  background: var(--accent-light);
  outline: 1px solid var(--accent);
}
.cat-table tbody tr.sel td:first-child { font-weight: 700; color: var(--accent-dark); }
.cat-table tbody tr.reco { background: var(--ok-bg); }
.cat-table tbody tr.reco.sel { background: var(--accent-light); }
.cat-table tbody tr.reco td:first-child::after { content: " ★"; color: #15803d; }
.cmp-del { padding: 2px 9px; font-size: 12px; }
.cmp-table td:first-child { font-weight: 500; }

/* ---------------- report page ---------------- */
.rp-meta { display: flex; flex-wrap: wrap; gap: 6px 28px; }
.rp-meta-row { font-size: 14px; color: var(--text-muted); }
.rp-meta-row strong { color: var(--text); }
/* shareable link row (wave 26): long encoded URL wraps and prints smaller */
.rp-share-row { max-width: 100%; }
.rp-share-row .share-val {
  word-break: break-all;
  font-size: 11.5px;
  font-weight: 500;
  user-select: all;
}

@media print {
  .topbar, .footer, .btn-row, .tabs, .no-print, .chart-legend, .cmp-del, .actions { display: none !important; }
  body { background: #fff; color: #111; }
  .container { max-width: none; padding: 0; }
  .grid { display: block; }
  .card { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; page-break-inside: avoid; margin-bottom: 12px; }
  h1.page-title { font-size: 20px; }
  a { color: inherit; text-decoration: none; }
  .badge { border: 1px solid #999; }
  /* batch report pack: when generated, print the pack instead of the table */
  body.has-pack #cmpWrap, body.has-pack #cmpNone { display: none !important; }
  .pack-case { break-inside: avoid; page-break-inside: avoid; }
  .pack-case h3 { page-break-after: avoid; }
  .pack-case .result-row { font-size: 12px; }
}

/* ---------------- touch adaptation ---------------- */
@media (pointer: coarse) {
  .input-row input,
  .input-row select,
  .btn,
  .tabs a,
  select,
  button {
    min-height: 44px;
  }
  .tabs a { padding: 12px 16px; }
  .btn { padding: 11px 18px; }
  .cmp-table tbody tr { min-height: 44px; }
  .cat-table tbody tr td { padding-top: 10px; padding-bottom: 10px; }
}

@media (max-width: 640px) {
  .container { padding: 0 10px; }
  .card { padding: 14px 12px; }
  .input-row { grid-template-columns: 1fr 96px 58px; gap: 6px; }
  .input-row.seg-row { grid-template-columns: 1fr 84px 36px auto 56px 36px 30px 30px 30px 34px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tabs a { white-space: nowrap; padding: 10px 12px; font-size: 13.5px; }
  .btn-row { flex-wrap: wrap; gap: 8px; }
  .result-row { flex-wrap: wrap; row-gap: 2px; }
}

/* ---------------- dark theme ---------------- */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #60a5fa;
  --accent-dark: #93c5fd;
  --accent-light: #1e3a8a;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --warn-border: #f59e0b;
  --err-bg: rgba(220, 38, 38, 0.18);
  --err-border: #ef4444;
  --ok-bg: rgba(22, 163, 74, 0.2);
  --ok-border: #22c55e;
  --grid-color: #2c3a4f;
  --axis-color: #64748b;
  --nc-ff: #60a5fa;
  --nc-fs: #fbbf24;
  --nc-ss: #34d399;
  --nc-fe: #f87171;
  --chart-strong: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .input-row:hover { background: #26334a; }
html[data-theme="dark"] .input-row input { background: #172236; color: var(--text); }
html[data-theme="dark"] .formula-block { background: #172236; }
html[data-theme="dark"] .cat-table th { background: #172236; }
html[data-theme="dark"] .cat-table tbody tr:hover { background: #26334a; }
html[data-theme="dark"] #curve { background: #172236; }
html[data-theme="dark"] .chart-box canvas { background: #172236; border: 1px solid var(--border); border-radius: 8px; }
html[data-theme="dark"] .badge.ok { color: #4ade80; }
html[data-theme="dark"] .badge.ng { color: #fca5a5; }
html[data-theme="dark"] .badge.warn { color: #fcd34d; }
html[data-theme="dark"] .cat-table tbody tr.reco td:first-child::after { color: #4ade80; }

/* ---------------- accessibility ---------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------- result-row inline help (wave 16) ---------------- */
.row-help {
  justify-self: end;
  align-self: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.row-help:hover,
.row-help:focus-visible { color: var(--accent); border-color: var(--accent); }
.help-note {
  grid-column: 1 / -1;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 6px 10px;
}

/* ---------------- debug / diagnostics page (wave 16) ---------------- */
.dbg-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.dbg-row:last-child { border-bottom: none; }
.dbg-head span { font-weight: 600; }
.dbg-key {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
  min-width: 170px;
  color: var(--accent);
}
.dbg-val {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  flex: 1;
  color: var(--text-muted);
}
.dbg-bad { color: #dc2626; }
.btn-dbg-clear { padding: 2px 10px; font-size: 12px; }

/* ---------------- export center (wave 17) ---------------- */
.ex-row { grid-template-columns: 1fr auto auto; align-items: center; }
.ex-row .res-label { font-weight: 600; }
.ex-desc {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--text-muted);
}
.ex-status { font-size: 12px; padding: 2px 10px; border-radius: 999px; }
.ex-status.ok { background: var(--ok-bg); color: #15803d; }
.ex-status.ng { background: var(--err-bg); color: #dc2626; }
.ex-btn { justify-self: end; }

/* ---------------- batch report pack (wave 17) ---------------- */
#cmpPack { margin-top: 16px; }
.pack-case { margin-bottom: 14px; }
.pack-case h3 { margin-top: 0; }

/* ---------------- theory interactive formulas (wave 18) ---------------- */
.try-slot { margin-top: 10px; }
.try-head {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.try-unit {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.try-ins { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.try-in { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.try-in label { color: var(--text-muted); white-space: nowrap; }
.try-in input {
  width: 90px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.try-outs { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 18px; }
.try-out { font-size: 13.5px; font-weight: 600; color: var(--accent); }

/* ---------------- screw life page (wave 18) ---------------- */
#lifeCurve { width: 100%; height: 320px; margin-top: 10px; }

/* ---------------- print chrome (wave 19) ---------------- */
.print-head, .print-foot, .quote-head { display: none; }
#mtCurve { width: 100%; height: 300px; margin-top: 10px; }
#rpTm { width: 100%; height: 300px; margin-top: 10px; }
@media print {
  .print-head {
    display: block;
    font-size: 12px;
    color: #333;
    border-bottom: 1px solid #bbb;
    padding-bottom: 4px;
    margin-bottom: 10px;
  }
  .print-foot {
    display: block;
    font-size: 11px;
    color: #666;
    border-top: 1px solid #bbb;
    padding-top: 4px;
    margin-top: 12px;
  }
  /* quote header (wave 24): print-only, formal quotation letterhead */
  .quote-head {
    display: block;
    font-size: 12px;
    color: #222;
    border: 1px solid #bbb;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 12px;
  }
  .quote-head .quote-company {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 2px;
  }
}

/* wave 31: export file names + quote history rows */
.ex-file { font-size: 11px; opacity: .75; word-break: break-all; }
.qhist-row span { flex: 1; }
/* wave 36: keyboard focus visibility */
.badge[role="button"]:focus-visible,
#catBody tr:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}
