:root {
  color-scheme: light;
  --ink: #12252a;
  --muted: #556a70;
  --paper: #ffffff;
  --canvas: #eef5f4;
  --line: #cadbd8;
  --line-strong: #9bbab5;
  --deep: #102f36;
  --teal: #087d78;
  --teal-soft: #dff4f0;
  --coral: #d95f4c;
  --coral-soft: #fff0ec;
  --gold: #9a6900;
  --gold-soft: #fff5d5;
  --green: #147449;
  --green-soft: #e4f5eb;
  --red: #af3138;
  --red-soft: #ffeaeb;
  --shadow: 0 18px 45px rgba(16, 47, 54, .1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); scroll-behavior: smooth; }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--canvas); }
a { color: inherit; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid rgba(8, 125, 120, .28); outline-offset: 2px; }
.page { width: min(1380px, 100%); margin: 0 auto; padding: 12px; }

.topbar {
  position: relative;
  z-index: 30;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid #31535a;
  border-radius: 8px;
  color: #f7fbfa;
  background: var(--deep);
}
.brand { min-width: 0; display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand img { width: 42px; height: 42px; flex: 0 0 auto; }
.brand-text { min-width: 0; display: grid; gap: 1px; }
.brand-name { font-weight: 850; letter-spacing: 0; white-space: nowrap; }
.brand-sub { color: #bed2d4; font-size: 12px; letter-spacing: 0; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.nav-link { min-height: 40px; display: inline-flex; align-items: center; padding: 8px 11px; border: 1px solid #57747a; border-radius: 8px; text-decoration: none; white-space: nowrap; }
.nav-link:hover { background: #20444b; }
.language-menu { position: relative; }
.language-menu summary { width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border: 1px solid #57747a; border-radius: 50%; background: #183c43; list-style: none; cursor: pointer; }
.language-menu summary::-webkit-details-marker { display: none; }
.language-menu-list { position: absolute; top: calc(100% + 7px); right: 0; width: 48px; display: grid; grid-template-columns: 40px; justify-content: center; gap: 5px; padding: 5px 4px; border: 1px solid #31535a; border-radius: 8px; background: var(--deep); box-shadow: var(--shadow); }
.language-menu-list a { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; text-decoration: none; }
.language-menu-list a:hover, .language-menu-list a[aria-current="true"] { background: #31535a; }
.flag-circle { position: relative; width: 28px; height: 28px; display: inline-grid; place-items: center; overflow: hidden; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 1px 5px rgba(0,0,0,.25); background: #fff; }
.flag-circle::after { font-size: 15px; line-height: 1; }
.flag-en::after { content: "GB"; color: #183b6b; font-size: 10px; font-weight: 900; }
.flag-de { background: linear-gradient(to bottom, #171717 0 33.33%, #d22730 33.33% 66.66%, #f2c400 66.66%); }
.flag-fr { background: linear-gradient(to right, #1f4aa8 0 33.33%, #fff 33.33% 66.66%, #e33d45 66.66%); }
.flag-es { background: linear-gradient(to bottom, #ba1f2d 0 25%, #f4c542 25% 75%, #ba1f2d 75%); }
.flag-zh { background: #df2d2d; }
.flag-zh::after { content: "★"; color: #ffdf4d; font-size: 13px; }
.flag-ru { background: linear-gradient(to bottom, #fff 0 33.33%, #2455b2 33.33% 66.66%, #d9363e 66.66%); }
.flag-bg { background: linear-gradient(to bottom, #fff 0 33.33%, #2b9b58 33.33% 66.66%, #d93745 66.66%); }

.tool-intro { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 30px; align-items: end; margin-top: 12px; padding: 28px; border-radius: 8px; color: #f8fbfb; background: var(--deep); box-shadow: var(--shadow); }
.eyebrow, .section-label { margin: 0 0 7px; color: var(--coral); font-size: 12px; font-weight: 900; letter-spacing: 0; text-transform: uppercase; }
h1, h2, h3, h4 { letter-spacing: 0; }
h1 { max-width: 24ch; margin: 0; font-size: 42px; line-height: 1.08; }
.lead { max-width: 76ch; margin: 12px 0 0; color: #dcebea; font-size: 17px; line-height: 1.6; }
.trust { display: grid; gap: 7px; align-content: end; }
.trust span { padding: 7px 9px; border: 1px solid #5f7f83; border-radius: 6px; color: #e8f2f1; background: #173b42; font-size: 12px; font-weight: 800; white-space: nowrap; }

.workspace { margin-top: 12px; padding: 24px; border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); }
.workspace-heading { display: grid; grid-template-columns: minmax(0, .9fr) minmax(300px, 1.1fr); gap: 28px; align-items: end; }
.workspace-heading h2, .content-section h2 { margin: 0; font-size: 28px; line-height: 1.2; }
.workspace-heading > p, .section-heading > p { margin: 0; color: var(--muted); line-height: 1.6; }
.tool-toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin: 22px -24px 0; padding: 14px 24px; border-block: 1px solid var(--line); background: #f6faf9; }
.preset-control { min-width: 245px; display: grid; gap: 5px; }
.preset-control > span { color: #2f4b50; font-size: 12px; font-weight: 850; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.save-status { min-height: 20px; margin-left: auto; align-self: center; color: var(--muted); font-size: 12px; font-weight: 750; }
button { min-height: 40px; padding: 8px 12px; border: 1px solid var(--teal); border-radius: 7px; color: #fff; background: var(--teal); font-weight: 800; }
button:hover { border-color: #075f5c; background: #075f5c; }
button:disabled { cursor: not-allowed; opacity: .38; }
.secondary { border-color: var(--line-strong); color: var(--deep); background: #fff; }
.secondary:hover { border-color: var(--teal); color: var(--deep); background: var(--teal-soft); }
.danger-subtle { border-color: #e4aaa5; color: var(--red); background: #fff; }
.danger-subtle:hover { border-color: var(--red); background: var(--red-soft); }

.settings-grid { display: grid; grid-template-columns: 1fr 1.25fr .85fr; gap: 18px; margin-top: 22px; }
.settings-panel { min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; align-content: start; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; }
.settings-panel legend { padding: 0 8px; color: var(--deep); font-weight: 900; }
.field { min-width: 0; display: grid; align-content: start; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field > span { color: #2d484e; font-size: 12px; font-weight: 850; line-height: 1.35; }
.field small { min-height: 32px; color: var(--muted); font-size: 11px; line-height: 1.4; }
input, select { width: 100%; min-width: 0; min-height: 40px; padding: 8px 9px; border: 1px solid #a9c0bd; border-radius: 6px; color: var(--ink); background: #fff; }
input:hover, select:hover { border-color: var(--teal); }
.assumption-note { grid-column: 1 / -1; margin: 2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.termination-panel { grid-template-columns: 1fr; }
.termination-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(145px, .8fr); gap: 8px; align-items: center; }
.check-field { min-width: 0; display: flex; align-items: center; gap: 8px; color: #2d484e; font-size: 12px; font-weight: 800; }
.check-field input { width: 19px; height: 19px; min-height: 0; flex: 0 0 auto; accent-color: var(--teal); }

.editor-section, .diagram-section, .results-section, .bom-section { min-width: 0; margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
.section-heading, .results-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.section-heading h3, .results-heading h3 { margin: 0; font-size: 21px; line-height: 1.25; }
.section-heading > p { max-width: 66ch; font-size: 13px; }
.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; min-width: 670px; border-collapse: collapse; background: #fff; }
caption { padding: 12px; color: var(--muted); font-size: 12px; font-weight: 750; text-align: left; }
th, td { padding: 10px; border-bottom: 1px solid #dce7e5; color: #243d42; font-size: 12px; text-align: left; vertical-align: middle; }
th { color: #29464c; background: #f0f6f5; font-weight: 900; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
.editor-table input, .editor-table select { min-width: 92px; min-height: 36px; padding: 6px 7px; }
.editor-table td:first-child input { min-width: 180px; }
.editor-table td:nth-child(2) select { min-width: 150px; }
.row-actions { width: 126px; display: flex; gap: 4px; }
.icon-button { width: 34px; height: 34px; min-height: 34px; display: grid; place-items: center; padding: 0; border-color: #9ab4b0; color: var(--deep); background: #f8fbfa; font-size: 18px; }
.icon-button:last-child { color: var(--red); }
.empty-row { padding: 22px; color: var(--muted); text-align: center; }
.compact-table table { min-width: 560px; }

.diagram-scroll { width: 100%; overflow-x: auto; border-block: 1px solid var(--line); background: #f7fbfa; }
#networkDiagram { width: 100%; min-width: 760px; height: 330px; display: block; }
.backbone-line { stroke: #31585e; stroke-width: 8; stroke-linecap: round; }
.terminator { stroke-width: 2; }
.terminator.installed { fill: #e4b447; stroke: #6d4a00; }
.terminator.missing { fill: #fff; stroke: var(--red); stroke-dasharray: 4 3; }
.tee-node { fill: #fff; stroke: #31585e; stroke-width: 5; }
.drop-line { stroke: #6a8990; stroke-width: 3; stroke-dasharray: 6 4; }
.device-node { fill: #fff; stroke: var(--teal); stroke-width: 2; }
.device-alert { fill: var(--red-soft); stroke: var(--red); }
.power-node { fill: #f2b94b; stroke: #6d4a00; stroke-width: 2; }
.power-symbol { fill: #4b3400; font-size: 15px; font-weight: 950; }
.node-label, .device-name { fill: var(--ink); font-size: 12px; font-weight: 850; letter-spacing: 0; }
.diagram-small { fill: #62777c; font-size: 10px; letter-spacing: 0; }
.segment-label { fill: #3e5b61; font-size: 11px; font-weight: 800; letter-spacing: 0; }

.result-actions { display: flex; align-items: center; gap: 8px; }
.status-badge { min-width: 150px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; text-align: center; }
.status-badge.pass { border-color: #77b996; color: var(--green); background: var(--green-soft); }
.status-badge.caution { border-color: #d9b254; color: #765000; background: var(--gold-soft); }
.status-badge.fail { border-color: #df9095; color: var(--red); background: var(--red-soft); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.metric-grid > div { min-width: 0; min-height: 88px; display: grid; align-content: center; gap: 7px; padding: 13px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric-grid > div:nth-child(4n) { border-right: 0; }
.metric-grid > div:nth-last-child(-n + 4) { border-bottom: 0; }
.metric-grid span { color: var(--muted); font-size: 11px; font-weight: 750; line-height: 1.3; }
.metric-grid strong { overflow-wrap: anywhere; color: var(--deep); font-size: 17px; letter-spacing: 0; }
.issue-list { display: grid; gap: 7px; margin: 14px 0; padding: 0; list-style: none; }
.issue-list li { padding: 10px 12px; border-left: 4px solid var(--line-strong); border-radius: 0 5px 5px 0; color: #324c52; background: #f3f8f7; font-size: 12px; line-height: 1.5; }
.issue-list li.error { border-color: var(--red); color: #6f2026; background: var(--red-soft); }
.issue-list li.warning { border-color: #c38b17; color: #6d4c05; background: var(--gold-soft); }
.issue-list li.info { border-color: var(--green); color: #155437; background: var(--green-soft); }
.result-alert td { color: #76242a; background: var(--red-soft); }

.content-section { margin-top: 12px; border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); }
.content-section > section { min-width: 0; padding: 26px; border-bottom: 1px solid var(--line); }
.content-section > section:last-child { border-bottom: 0; }
.content-section p, .content-section li { color: #3e565c; line-height: 1.72; }
.content-section ul, .content-section ol { padding-left: 22px; }
.content-section li + li { margin-top: 7px; }
.content-section .table-wrap { margin-top: 16px; }
.worked-example { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr); gap: 26px; align-items: start; background: var(--gold-soft); }
.formula-box { min-width: 0; padding: 18px; border-left: 4px solid #c48a14; background: #fffaf0; }
.formula-box code { display: block; overflow-wrap: anywhere; color: #5a3b00; font-size: 17px; font-weight: 900; letter-spacing: 0; }
.content-split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; }
.safety-callout { border-left: 6px solid var(--coral); background: var(--coral-soft); }
.privacy-callout { border-left: 6px solid var(--teal); background: var(--teal-soft); }
.limitations-section { border-left: 6px solid #c08b22; background: #fffaf0; }
.sources-section ul { display: grid; gap: 10px; padding: 0; list-style: none; }
.sources-section li { display: grid; gap: 3px; }
.sources-section a { width: fit-content; color: #066e69; font-weight: 850; }
.sources-section span { color: var(--muted); font-size: 12px; }
.faq-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 16px; }
.faq-list details { min-width: 0; border: 1px solid var(--line); border-radius: 6px; background: #fbfdfd; }
.faq-list summary { padding: 13px; color: #253f45; font-weight: 850; cursor: pointer; }
.faq-list p { margin: 0; padding: 0 13px 14px; font-size: 13px; }

.footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 12px; padding: 18px 20px; border-radius: 8px; color: #dcebea; background: var(--deep); }
.footer p { margin: 0; font-size: 12px; }
.footer nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; }
.footer a, .privacy-settings { color: #eef7f6; font-size: 12px; }
.footer .privacy-settings { min-height: 0; padding: 0; border: 0; background: transparent; text-decoration: underline; }

@media (max-width: 1080px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .termination-panel { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .termination-panel .assumption-note { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid > div:nth-child(2n) { border-right: 0; }
  .metric-grid > div:nth-last-child(-n + 4) { border-bottom: 1px solid var(--line); }
  .metric-grid > div:nth-last-child(-n + 2) { border-bottom: 0; }
}

@media (max-width: 760px) {
  .page { padding: 8px; }
  .topbar { min-height: 58px; padding: 7px 8px; }
  .brand img { width: 38px; height: 38px; }
  .brand-sub { display: none; }
  .nav-link { max-width: 120px; white-space: normal; text-align: center; }
  .tool-intro { grid-template-columns: 1fr; gap: 18px; padding: 22px 18px; }
  h1 { font-size: 34px; }
  .lead { font-size: 15px; }
  .trust { grid-template-columns: 1fr; }
  .trust span { white-space: normal; }
  .workspace { padding: 18px 14px; }
  .workspace-heading { grid-template-columns: 1fr; gap: 10px; }
  .workspace-heading h2, .content-section h2 { font-size: 24px; }
  .tool-toolbar { margin-inline: -14px; padding-inline: 14px; align-items: stretch; }
  .preset-control { width: 100%; min-width: 0; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .save-status { width: 100%; margin-left: 0; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-panel, .termination-panel { grid-column: auto; grid-template-columns: 1fr; }
  .field-wide, .assumption-note, .termination-panel .assumption-note { grid-column: auto; }
  .termination-row { grid-template-columns: 1fr; }
  .section-heading, .results-heading { align-items: stretch; flex-direction: column; gap: 10px; }
  .result-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .status-badge { min-width: 0; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-grid > div { border-right: 0; border-bottom: 1px solid var(--line) !important; }
  .metric-grid > div:last-child { border-bottom: 0 !important; }
  .worked-example, .content-split { grid-template-columns: 1fr; }
  .faq-list { grid-template-columns: 1fr; }
  .content-section > section { padding: 21px 17px; }
  .footer { align-items: flex-start; flex-direction: column; }
  .footer nav { justify-content: flex-start; }
}

@media (max-width: 430px) {
  .brand-name { max-width: 130px; white-space: normal; font-size: 13px; line-height: 1.1; }
  .nav-link { max-width: 92px; padding-inline: 8px; font-size: 11px; }
  .toolbar-actions { grid-template-columns: 1fr; }
  .result-actions { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .page { width: 100%; padding: 0; }
  .topbar, .tool-toolbar, .editor-section button, .language-menu, .nav-link, .footer, .content-section { display: none !important; }
  .tool-intro, .workspace { margin: 0; padding: 12px; box-shadow: none; }
  .tool-intro { color: #000; background: #fff; border-bottom: 2px solid #000; }
  .lead { color: #333; }
  .trust { display: none; }
  .settings-grid { grid-template-columns: repeat(3, 1fr); }
  .table-wrap, .diagram-scroll { overflow: visible; }
  #networkDiagram { width: 100%; min-width: 0; }
  .results-section, .bom-section, .diagram-section { break-inside: avoid; }
}
