/* ===== ElecEng Handbook - global styles ===== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --border: #dde3ee;
  --text: #1f2937;
  --text-soft: #5b6474;
  --primary: #0f5bd0;
  --primary-soft: #e7effc;
  --accent: #0e8a72;
  --warn: #b45309;
  --warn-bg: #fdf3e2;
  --danger: #c0392b;
  --mono: "SFMono-Regular", "Consolas", "JetBrains Mono", "Menlo", monospace;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 6px 20px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Microsoft YaHei", "Noto Sans JP", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
}

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

/* ---- Top bar ---- */
.topbar {
  background: #0f2544;
  color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: 8px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2f7bff, #17b9a0);
  font-size: 18px;
}
.brand .brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
.brand .brand-sub { display: block; font-size: 11px; color: #aebdd4; font-weight: 500; }

.top-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: .15s; line-height: 1.3;
}
.btn-home { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.28); }
.btn-home:hover { background: rgba(255,255,255,.22); text-decoration: none; }
.btn-mail { background: #17b9a0; color: #06332c; }
.btn-mail:hover { background: #23c9af; text-decoration: none; }

/* PDF export bar (Testing page) */
.export-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.btn-export { background: #1f6feb; color: #fff; }
.btn-export:hover { background: #2a7bff; }
.export-hint { font-size: 12.5px; color: var(--text-soft); }

.lang-select {
  appearance: none; padding: 6px 26px 6px 10px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.1); color: #fff;
  font-size: 14px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='white' fill='none' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.lang-select option { color: #111; background: #fff; }

/* ---- Page nav (tabs) ---- */
.navtabs {
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.navtabs-inner { max-width: 1200px; margin: 0 auto; display: flex; gap: 4px; padding: 0 14px; }
.navtabs a {
  padding: 12px 14px; font-weight: 600; font-size: 14.5px; color: var(--text-soft);
  white-space: nowrap; border-bottom: 3px solid transparent;
}
.navtabs a:hover { color: var(--primary); text-decoration: none; }
.navtabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- Dropdown module menu (Windows-style grouped menu) ---- */
.nav-drop { position: relative; display: flex; }
.nav-drop-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 12px 14px; font-weight: 600; font-size: 14.5px; font-family: inherit;
  color: var(--text-soft); background: transparent; border: none; cursor: pointer;
  white-space: nowrap; border-bottom: 3px solid transparent;
}
.nav-drop-btn:hover { color: var(--primary); }
.nav-drop.open .nav-drop-btn { color: var(--primary); border-bottom-color: var(--primary); }
.nav-drop-menu {
  position: absolute; top: 100%; left: 0; z-index: 60; min-width: 248px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 7px; display: none;
  text-align: left;
}
.nav-drop.open .nav-drop-menu,
.nav-drop:hover .nav-drop-menu { display: block; }
.nav-drop-menu a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; font-weight: 600; font-size: 14px;
  color: var(--text-soft); border-radius: 8px; border: none; white-space: nowrap;
}
.nav-drop-menu a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.nav-drop-menu a.active { background: var(--primary); color: #fff; }
@media (max-width: 900px) {
  .nav-drop-menu { position: fixed; left: 14px; right: 14px; top: 72px; min-width: 0; }
}

/* ---- Layout ---- */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 18px 60px; }
.page-head { margin-bottom: 22px; }
.crumbs { font-size: 13px; color: var(--text-soft); margin-bottom: 6px; }
.page-title { font-size: 26px; font-weight: 800; margin: 0 0 6px; letter-spacing: -.3px; }
.page-desc { color: var(--text-soft); margin: 0; max-width: 860px; }
.note {
  display: flex; gap: 8px; background: var(--warn-bg); color: var(--warn);
  border: 1px solid #f2dcb6; border-radius: 8px; padding: 9px 13px; font-size: 13.5px;
  margin-top: 14px; max-width: 900px;
}
.note svg { flex: none; margin-top: 2px; }

/* ---- Cards grid ---- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-3{grid-template-columns:repeat(2,1fr);} .grid-5{grid-template-columns:repeat(3,1fr);} }
@media (max-width: 600px) { .grid-4,.grid-3,.grid-2,.grid-5 { grid-template-columns: 1fr; } }

/* Home module grid: 5 cards -> 3+2 on desktop, 2 on tablet, 1 on phone */
.home-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
@media (max-width: 960px) { .home-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .home-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.navcard { display: flex; flex-direction: column; gap: 10px; transition: .15s; border-top: 3px solid var(--primary); }
.navcard:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(16,24,40,.1); text-decoration: none; }
.navcard .ic {
  width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); font-size: 22px; margin-bottom: 4px;
}
.navcard h3 { margin: 0; font-size: 17px; color: var(--text); }
.navcard p { margin: 0; font-size: 13.5px; color: var(--text-soft); }

/* ---- Section ---- */
.section { margin-bottom: 34px; }
.section-title { font-size: 20px; font-weight: 800; margin: 0 0 4px; display:flex; align-items:center; gap:8px; }
.section-sub { color: var(--text-soft); font-size: 14px; margin: 0 0 16px; }

/* ---- Calculator widget ---- */
.calc { margin-bottom: 22px; }
.calc .card h3 { margin: 0 0 4px; font-size: 17px; }
.calc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.calc-head h3 { margin: 0 !important; }
.calc-inc { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-soft); cursor: pointer; user-select: none; white-space: nowrap; }
.calc-inc input { accent-color: #1f6feb; width: 15px; height: 15px; cursor: pointer; }
.calc .calc-formula {
  font-family: var(--mono); background: var(--surface-2); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; margin: 8px 0 12px; color: #24344d;
  border-left: 3px solid var(--primary); overflow-x: auto;
}
.calc .field { margin-bottom: 12px; }
.calc label { display: block; font-size: 13.5px; color: var(--text-soft); margin-bottom: 4px; font-weight:600; }
.input-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.calc input[type=number], .calc select {
  width: 100%; flex: 1; min-width: 120px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: var(--mono); background: #fff; color: var(--text);
}
.unit {
  font-family: var(--mono); font-size: 13px; color: var(--text-soft);
  background: var(--surface-2); padding: 8px 9px; border-radius: 8px; white-space: nowrap;
}
.calc input:focus, .calc select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }

.result-box {
  margin-top: 6px; background: var(--primary-soft); border: 1px solid #c6d9f6;
  border-radius: 10px; padding: 12px 14px;
}
.result-box .r-label { font-size: 12.5px; color: var(--text-soft); text-transform: uppercase; letter-spacing:.4px; font-weight:700; }
.result-box .r-value { font-family: var(--mono); font-size: 24px; font-weight: 800; color: var(--primary); margin-top: 2px; }
.result-box .r-note { font-size: 12.5px; color: var(--text-soft); margin-top: 4px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 14px; min-width: 620px; }
table.data th {
  background: #eef2fa; color: #24344d; text-align: left; font-weight: 700;
  padding: 9px 12px; border-bottom: 2px solid var(--border); position: sticky; top: 0; white-space: nowrap;
}
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:nth-child(even) td { background: #fafbfe; }
table.data tr:last-child td { border-bottom: none; }
table.data td.mono, table.data .mono { font-family: var(--mono); font-size: 13px; }
code {
  font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px;
  font-size: .92em; color: #1752a8;
}
.badge { display:inline-block; padding:2px 8px; border-radius:20px; font-size:12px; font-weight:600; }
.badge.ok { background:#e3f6ef; color:#0e8a72; }
.badge.warn { background:#fdf3e2; color:#b45309; }
.badge.info { background:var(--primary-soft); color:var(--primary); }
.block { display:block; }
.muted { color: var(--text-soft); font-size: 13px; }

/* Pinout chip */
.pin {
  display: inline-grid; grid-template-columns: auto auto; gap: 2px 10px;
  font-family: var(--mono); font-size: 12.5px; text-align: right;
  background: #101827; color: #cfe0ff; padding: 10px 14px; border-radius: 10px; line-height: 1.5;
}
.pin .p-no { color: #7d8fb0; }

.chip {
  display: inline-block; background: #0f1422; color: #cfe0ff;
  border-radius: 10px; padding: 14px 16px; font-family: var(--mono); min-width: 210px;
  border: 1px solid #232c44;
}
.chip-name { text-align: center; color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .5px; padding-bottom: 6px; border-bottom: 1px solid #2a3550; margin-bottom: 8px; }
.chip-grid { display: flex; gap: 16px; align-items: stretch; justify-content: center; }
.chip-col { display: flex; flex-direction: column; justify-content: center; gap: 3px; font-size: 12.5px; line-height: 1.35; }
.chip-col .p { color: #8fa2c4; }
.chip-col.right { text-align: left; }
.chip-col.right .p { display: inline-block; min-width: 16px; text-align: right; margin-right: 4px; }
.chip-col:not(.right) .p { display: inline-block; min-width: 16px; text-align: right; margin-right: 4px; }
.chip-core { display: flex; align-items: center; justify-content: center; font-size: 12px; color: #5d6d8f; text-align: center; min-width: 12px; }
.chip-foot { text-align: center; color: #5d6d8f; font-size: 11px; margin-top: 10px; }
.chip-row { font-size: 12.5px; white-space: nowrap; }
.chip-row .p { color: #8fa2c4; }

/* Protocol chip */
.level-band { display:inline-block; width:34px; height:14px; border-radius:3px; margin:0 2px; vertical-align:middle; }

/* Resistor color-ring preview */
.ringbar { display: flex; gap: 6px; align-items: center; padding: 8px 12px; background: #eef1f7; border-radius: 10px; margin: 4px 0 12px; }
.ringbar .rb-label { font-size: 12.5px; color: var(--text-soft); margin-right: 10px; font-weight: 600; }
.ring-swatch { width: 30px; height: 24px; border-radius: 8px; border: 1px solid rgba(0,0,0,.22); background: #ccc; }
.ring-swatch.bp { width: 20px; }

/* Wireframe svg / diagram box */
.diagram {
  background:#0f1422; border-radius:10px; padding:16px; color:#cfe0ff;
  font-family: var(--mono); font-size: 13px; overflow:auto;
  margin-top: 10px;
}

/* Component photo gallery */
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.gcard {
  margin: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.gcard .gimg { aspect-ratio: 4 / 3; background: #f7f9fc; }
.gcard .gimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcard figcaption { padding: 10px 12px; font-size: 13.5px; font-weight: 600; color: var(--text); }
@media (max-width: 960px) { .gallery { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .gallery { grid-template-columns: 1fr; } }

/* Working diagrams & symbols */
.wk-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.wkcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
}
.wkcard svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.wkcaption { margin: 10px 0 0; font-size: 13.5px; color: var(--text-soft); }
.wkcap-title { font-weight: 700; color: var(--text); }
@media (max-width: 600px) { .wk-grid { grid-template-columns: 1fr; } }

/* Footer */
footer { background: #0f2544; color: #b8c4d6; margin-top: 40px; padding: 26px 18px; font-size: 13.5px; }
.footer-inner { max-width: 1200px; margin: 0 auto; display: flex; gap: 20px; justify-content: space-between; flex-wrap: wrap; }
footer a { color: #dbe6ff; }

@media (max-width: 600px) {
  .page-title { font-size: 22px; }
  .topbar-inner { gap: 8px; }
}

/* ---- PDF export sheet: hidden on screen, printable summary ---- */
#printSheet { display: none; }
@media print {
  body > :not(#printSheet) { display: none !important; }
  #printSheet {
    display: block !important; color: #111; background: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    padding: 24px 30px;
  }
  #printSheet .ps-head { border-bottom: 3px solid #1f6feb; padding-bottom: 12px; margin-bottom: 16px; }
  #printSheet .ps-brand { font-size: 12px; letter-spacing: .4px; color: #1f6feb; font-weight: 700; text-transform: uppercase; }
  #printSheet h1 { font-size: 22px; margin: 4px 0 2px; }
  #printSheet .ps-date { font-size: 12px; color: #555; margin: 0; }
  #printSheet .ps-block { margin-bottom: 18px; }
  #printSheet h2 { font-size: 15px; margin: 0 0 6px; padding-bottom: 4px; border-bottom: 1px solid #ddd; }
  #printSheet .ps-table { width: 100%; border-collapse: collapse; }
  #printSheet .ps-table td { border: 1px solid #d5d9e0; padding: 5px 10px; font-size: 12.5px; }
  #printSheet .ps-table td:first-child { color: #555; width: 62%; }
  #printSheet .ps-table tr.ps-res td { background: #f2f5fb; font-weight: 700; color: #0b1f3a; }
  #printSheet .ps-table tr.ps-res td:first-child { color: #0b1f3a; }
  #printSheet .ps-note { font-size: 11px; color: #666; margin-top: 18px; border-top: 1px solid #e3e6ec; padding-top: 10px; }
}