/* Power Piping Toolbox - light theme, responsive, zero dependency */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f4f9;
  --border: #d8e0ea;
  --text: #1e2733;
  --muted: #5f6d7e;
  --accent: #0b5fa5;
  --accent-dark: #084577;
  --ok: #0f8a4f;
  --warn: #b7791f;
  --bad: #c0392b;
  --shadow: 0 1px 3px rgba(20, 40, 70, .08), 0 1px 2px rgba(20, 40, 70, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Microsoft YaHei", "Hiragino Sans", sans-serif;
  font-size: 15px; line-height: 1.55;
}

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

/* ---------- header ---------- */
#site-header .hdr {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
#site-header .hdr-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand {
  font-weight: 700; font-size: 17px; color: var(--accent-dark);
  letter-spacing: .2px; display: flex; align-items: center; gap: 8px;
}
.brand .mark {
  display: inline-block; width: 26px; height: 26px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #2fa4e7);
  color: #fff; font-size: 14px; line-height: 26px; text-align: center;
}
.hdr-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-block; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface-2); color: var(--text);
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #e4ecf6; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; }

select.sel, input[type="text"], input[type="number"], input {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); font-size: 14px; font-family: inherit;
  width: 100%;
}
select.sel { width: auto; min-width: 130px; }
input:focus, select:focus { outline: 2px solid rgba(11, 95, 165, .25); border-color: var(--accent); }

/* ---------- layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
h1 { font-size: 24px; margin: 4px 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; color: var(--accent-dark); }
.intro { color: var(--muted); margin: 0 0 18px; max-width: 860px; }

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

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 18px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.lbl { font-size: 13px; color: var(--muted); font-weight: 600; }
.unit { font-size: 12px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- results ---------- */
table.res { width: 100%; border-collapse: collapse; font-size: 14px; }
table.res th, table.res td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.res th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
table.res td.v { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.res td.u { text-align: left; color: var(--muted); width: 1%; white-space: nowrap; }
/* formula back-substitution shown under the row label */
.fsub { display: block; margin-top: 3px; font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--muted); line-height: 1.5; }
.fsub .fexpr { display: block; }
.fsub .fsub2 { display: block; }
tr.hl td { background: #eef6ff; font-weight: 600; }
tr.ok td.v { color: var(--ok); font-weight: 600; }
tr.bad td.v { color: var(--bad); font-weight: 600; }
tr.warn td.v { color: var(--warn); font-weight: 600; }

.verdict { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 600; font-size: 14px; border: 1px solid; }
.verdict.ok { background: #eaf7ef; border-color: #b6e0c6; color: var(--ok); }
.verdict.bad { background: #fdecea; border-color: #f3c1bb; color: var(--bad); }
.verdict.warn { background: #fdf6e6; border-color: #f0dfae; color: var(--warn); }
.verdict.info { background: #eef4fb; border-color: #cbdff3; color: var(--accent-dark); }

.note {
  background: #fffaf0; border: 1px solid #f0dfae; border-left: 4px solid var(--warn);
  padding: 10px 14px; border-radius: 6px; font-size: 13px; color: #6b5716; margin-top: 6px;
}

/* ---------- module index cards ---------- */
.mod-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.mod-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow);
  color: var(--text); transition: transform .12s ease, box-shadow .12s ease;
}
.mod-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20, 40, 70, .12); text-decoration: none; border-color: var(--accent); }
.mod-card .t { font-weight: 700; color: var(--accent-dark); margin-bottom: 4px; }
.mod-card .d { font-size: 13px; color: var(--muted); }
.mod-card .tag { display: inline-block; margin-top: 8px; font-size: 11px; padding: 2px 7px; border-radius: 20px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- code selector + report actions ---------- */
.code-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 14px;
}
.code-bar .lbl { margin-right: 2px; }
.code-bar select { min-width: 300px; }

.acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.acts .btn { font-size: 13px; }
#share-badge {
  font-size: 12px; color: var(--ok); opacity: 0; transition: opacity .2s ease;
}
#share-badge.on { opacity: 1; }

.sub { font-size: 15px; font-weight: 700; color: var(--accent-dark); margin: 6px 0 8px; }

/* ---------- footer ---------- */
#site-footer { border-top: 1px solid var(--border); background: #eef2f7; margin-top: 30px; }
#site-footer .ft-inner { max-width: 1180px; margin: 0 auto; padding: 18px 16px; font-size: 13px; color: var(--muted); }
#site-footer .ft-links { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
#site-footer .disc { line-height: 1.6; }

@media (max-width: 640px) {
  h1 { font-size: 20px; }
  .container { padding: 14px 12px 36px; }
  .card { padding: 12px 13px; }
  table.res { font-size: 13px; }
}

@media print {
  .hdr-actions, .actions, #site-footer .ft-links, .code-bar select, .acts { display: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
  .code-bar { background: #fff; }
  #site-header .hdr { position: static; box-shadow: none; }
  table.res { page-break-inside: auto; }
  table.res tr { page-break-inside: avoid; }

  /* printable calculation-sheet header, injected only when printing */
  .sheet-head { display: block !important; margin-bottom: 14px; border-bottom: 2px solid #1e2733; padding-bottom: 8px; }
  .sheet-head .sh-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
  .sheet-head .sh-brand { font-weight: 700; font-size: 15px; }
  .sheet-head .sh-what { font-weight: 700; font-size: 16px; }
  .sheet-head .sh-meta { display: flex; gap: 18px; flex-wrap: wrap; font-size: 11px; color: #5f6d7e; margin-top: 4px; }
}

.sheet-head { display: none; }
