/* ASME B31.8-2025 Calculator — shared styles */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #1e3a5f;
  --navy2: #2b5580;
  --accent: #2b6cb0;
  --accent-light: #ebf4ff;
  --green: #1e7d46;
  --green-light: #eaf7ef;
  --amber: #9a6700;
  --amber-light: #fdf3d7;
  --red: #b3382c;
  --red-light: #fdecea;
  --bg: #f2f5f9;
  --card: #ffffff;
  --line: #dbe3ec;
  --text: #22303f;
  --muted: #5b6b7b;
  --mono: "Consolas", "SF Mono", "Cascadia Code", "Menlo", monospace;
}

html { font-size: 16px; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Malgun Gothic", "Apple SD Gothic Neo", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  background: linear-gradient(90deg, var(--navy) 0%, var(--navy2) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(20, 40, 60, .25);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: .2px;
  white-space: nowrap;
}
.brand small { display: block; font-weight: 400; font-size: .85rem; opacity: .85; letter-spacing: .4px; }
.topnav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: 6px; }
.topnav a {
  color: #dbe7f3;
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 6px;
  font-size: .9rem;
  transition: background .15s, color .15s;
}
.topnav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topnav a.active { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }

/* ---------- Dropdown menu (Windows-style) ---------- */
.dd { position: relative; display: inline-flex; }
.dd-btn { cursor: pointer; user-select: none; }
.dd-btn::after { content: " \25BE"; font-size: .68em; opacity: .8; }
.dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 240px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(20, 40, 60, .22);
  padding: 6px;
  flex-direction: column;
  gap: 2px;
  z-index: 80;
}
.dd:hover .dd-menu, .dd:focus-within .dd-menu { display: flex; }
.dd-menu a {
  display: block;
  color: var(--text) !important;
  font-size: .88rem;
  padding: 7px 12px;
  border-radius: 6px;
}
.dd-menu a:hover { background: var(--accent-light); color: var(--navy) !important; }
.dd-menu a.active { background: var(--accent); color: #fff !important; font-weight: 600; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: .85rem;
  transition: background .15s;
}
.tbtn:hover { background: rgba(255,255,255,.16); }
.tbtn .ic { font-size: .95rem; line-height: 1; }

.langbox { display: flex; align-items: center; gap: 6px; }
.langbox label { font-size: .85rem; opacity: .9; }
#langSel {
  font-size: .85rem;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  max-width: 150px;
}

/* ---------- Layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 26px 18px 40px; width: 100%; flex: 1; }

.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 1.5rem; color: var(--navy); margin-bottom: 6px; }
.page-head p { color: var(--muted); font-size: .95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  box-shadow: 0 1px 3px rgba(30,50,80,.06);
}
.card + .card { margin-top: 18px; }
.card h2 { font-size: 1.06rem; color: var(--navy); margin-bottom: 14px; padding-bottom: 8px; border-bottom: 2px solid var(--accent); }
.card h3 { font-size: .95rem; color: var(--accent); margin: 14px 0 8px; }

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

/* ---------- Forms ---------- */
fieldset { border: none; }
.frow { margin-bottom: 13px; }
.frow > label, .frow > .flabel { display: block; font-size: .86rem; font-weight: 600; color: #33475b; margin-bottom: 4px; }
.frow .hint { font-size: .85rem; color: var(--muted); font-weight: 400; }

.frow input[type=number], .frow input[type=text], .frow select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #c7d2de;
  border-radius: 6px;
  font-size: .95rem;
  background: #fff;
  color: var(--text);
}
.frow input:focus, .frow select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.frow input[type=number] { font-family: var(--mono); }
.unit-suffix { position: relative; }
.unit-suffix input { padding-right: 64px; }
.unit-suffix .usuf { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: .85rem; color: var(--muted); pointer-events: none; }

.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid #c7d2de;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: .88rem;
  cursor: pointer;
  background: #fbfcfe;
  transition: border-color .15s, background .15s;
}
.radio-row label:hover { border-color: var(--accent); }
.radio-row input:checked + span { color: var(--accent); font-weight: 600; }
.radio-row input { accent-color: var(--accent); }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 11px 26px;
  font-size: .98rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
button.primary:hover { background: #24538a; }
button.primary:active { transform: translateY(1px); }

/* ---------- Results ---------- */
.results {
  background: var(--accent-light);
  border: 1px solid #c4dcf5;
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 4px;
}
.rrow { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-bottom: 1px dashed #c9d9ea; }
.rrow:last-child { border-bottom: none; }
.rrow .k { font-size: .86rem; color: #33506b; }
.rrow .v { font-family: var(--mono); font-size: 1.06rem; font-weight: 700; color: var(--navy); white-space: nowrap; }
.rrow .v small { font-size: .85rem; font-weight: 400; color: var(--muted); }

.formula-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: .88rem;
  color: var(--navy);
  text-align: center;
  margin: 6px 0;
}

.warn { border-radius: 6px; padding: 9px 12px; font-size: .85rem; margin-top: 10px; }
.warn-amber { background: var(--amber-light); border: 1px solid #e6cf8f; color: var(--amber); }
.warn-red { background: var(--red-light); border: 1px solid #ecc0ba; color: var(--red); }
.warn-green { background: var(--green-light); border: 1px solid #bfe3cc; color: var(--green); }

.loc-rules { list-style: none; margin-top: 8px; }
.loc-rules li {
  padding: 8px 10px 8px 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: .86rem;
  color: var(--text);
  position: relative;
  background: #fbfcfe;
}
.loc-rules li::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c3d0de;
}
.loc-rules li[style*="700"] { border-color: var(--accent); background: var(--accent-light); }
.loc-rules li[style*="700"]::before { background: var(--accent); }

/* ---------- Index cards ---------- */
.idx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; margin-top: 8px; }
.idx-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(30,50,80,.06);
  transition: transform .15s, box-shadow .15s;
}
.idx-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(30,50,80,.12); }
.idx-card .ic { font-size: 1.5rem; }
.idx-card h3 { font-size: 1rem; color: var(--navy); }
.idx-card p { font-size: .85rem; color: var(--muted); flex: 1; }
.idx-card a {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 6px;
}
.idx-card a:hover { background: #24538a; }

/* ---------- Tables ---------- */
.tbl-scroll { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: .85rem; margin-top: 4px; }
table.data th {
  background: var(--navy);
  color: #fff;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:nth-child(even) td { background: #f7fafc; }
table.data td.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
table.data caption { caption-side: top; text-align: left; font-weight: 700; color: var(--navy); font-size: .95rem; padding: 10px 0 6px; }
table.data .muted { color: var(--muted); font-size: .85rem; }
.tabnote { font-size: .85rem; color: var(--muted); margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }

/* ---------- Footer ---------- */
footer {
  background: var(--navy);
  color: #b9c9da;
  padding: 18px;
  font-size: .85rem;
  text-align: center;
  margin-top: auto;
}
footer .std { color: #dfe9f3; margin-bottom: 4px; }

@media print { .topbar, footer { display: none; } }
