:root {
  --bg: #f4f7f6;
  --ink: #18211f;
  --muted: #5d6965;
  --line: #cdd8d4;
  --panel: #ffffff;
  --accent: #0a6c74;
  --accent-2: #835b15;
  --warn: #9a3412;
  --soft: #e6f2f1;
  --section-plain: #ffffff;
  --section-mint: #edf6f2;
  --section-sky: #edf4fb;
  --section-gold: #fbf5e8;
  --section-lavender: #f3f1f8;
  --section-rose: #fbefee;
  --section-graphite: #f2f4f4;
  --shadow: 0 18px 50px rgba(18, 41, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #edf6f2 0, var(--bg) 280px),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.app {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.workspace {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(10, 108, 116, 0.12), rgba(47, 111, 159, 0.08)),
    var(--soft);
}

.app-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(18, 41, 38, 0.14);
  flex: 0 0 auto;
}

.header > div:first-of-type {
  min-width: 0;
  flex: 1 1 auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  font-weight: 700;
}

h2 {
  font-size: 17px;
  margin-bottom: 10px;
}

.header p,
.note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  min-height: 720px;
}

.panel {
  border-right: 1px solid var(--line);
  background: #f7faf9;
}

.inputs {
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.inputs > fieldset,
.advanced-settings {
  padding: 14px 14px 15px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--section-plain);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.inputs > fieldset:hover,
.advanced-settings:hover {
  border-color: #b8c8c3;
}

.section-mode {
  background: var(--section-mint);
  border-left-color: #0a6c74;
}

.section-device,
.section-endpoint {
  background: var(--section-sky);
  border-left-color: #2f6f9f;
}

.section-antenna,
.section-link {
  background: var(--section-gold);
  border-left-color: #9a6b12;
}

.section-channel {
  background: var(--section-lavender);
  border-left-color: #6d5e9b;
}

.section-estimate {
  background: var(--section-rose);
  border-left-color: #9b524d;
}

.section-advanced {
  background: var(--section-graphite);
  border-left-color: #68726f;
}

legend {
  grid-column: 1 / -1;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

legend::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.45;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  min-width: 0;
}

select,
input {
  width: 100%;
  min-height: 36px;
  border: 1px solid #b9c7c3;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
  font: inherit;
  font-weight: 500;
}

select:focus,
input:focus {
  outline: 2px solid rgba(10, 108, 116, 0.22);
  border-color: var(--accent);
}

select:disabled {
  color: var(--muted);
  background: #edf2f0;
  opacity: 1;
}

.toggle {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
  min-height: 36px;
}

.mode-choice {
  grid-template-columns: auto 1fr;
  padding: 9px 10px;
  border: 1px solid rgba(10, 108, 116, 0.18);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
}

.mode-choice:has(input:checked) {
  border-color: rgba(10, 108, 116, 0.58);
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(10, 108, 116, 0.16);
}

.toggle input {
  width: 18px;
  min-height: 18px;
}

#apNote {
  grid-column: 1 / -1;
}

.full-span {
  grid-column: 1 / -1;
}

.manual-regulatory {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf9;
}

.manual-regulatory[hidden] {
  display: none;
}

.manual-regulatory .note {
  grid-column: 1 / -1;
}

.note-link {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.note-link:hover {
  text-decoration: underline;
}

.advanced-settings {
  color: var(--ink);
}

.advanced-settings summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  list-style-position: outside;
  margin-bottom: 12px;
}

.advanced-settings summary::marker {
  color: var(--muted);
}

.advanced-settings fieldset {
  margin-top: 0;
}

.results {
  padding: 22px 24px 24px;
  display: grid;
  gap: 14px;
  align-content: start;
  background: #ffffff;
}

.results > * {
  min-width: 0;
}

.result-hero {
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--line);
}

.result-hero span,
.grid span,
.summary-grid span,
.speed-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.result-hero strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(44px, 8vw, 76px);
  line-height: 1;
  color: var(--accent);
}

.result-band {
  padding: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.grid div,
.summary-grid div,
.speed-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.summary-grid div,
.grid div,
.speed-card {
  border-top: 3px solid rgba(10, 108, 116, 0.2);
}

.summary-grid div:nth-child(2n),
.grid div:nth-child(2n) {
  border-top-color: rgba(47, 111, 159, 0.24);
}

.summary-grid div:nth-child(3n),
.grid div:nth-child(3n) {
  border-top-color: rgba(131, 91, 21, 0.24);
}

.grid strong,
.summary-grid strong,
.speed-card strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.speed-card {
  display: grid;
  gap: 10px;
  background: #f7fbfb;
}

.speed-card strong {
  font-size: 26px;
}

.bar {
  height: 8px;
  background: #ecefeb;
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: #2f80ed;
  border-radius: inherit;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.summary-grid small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  font-size: 12px;
}

.summary-grid b {
  font: inherit;
}

.details-grid {
  opacity: 0.92;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
}

.soft-input input {
  background: #f6f8f7;
}

input.readonly {
  background: #f6f8f7;
  color: var(--muted);
}

.muted-row {
  opacity: 0.65;
}

.pill {
  flex: 0 0 auto;
  border: 1px solid #9ac1bd;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.pill.warn {
  border-color: #f4a261;
  color: var(--warn);
}

.warning {
  min-height: 18px;
  color: var(--warn);
  font-size: 13px;
  line-height: 1.45;
}

.compare {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  overflow-x: auto;
}

.compare.result-band {
  margin-top: 2px;
  padding: 16px 0 0;
}

.calculation-detail {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.calc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.calc-grid div {
  border: 1px solid var(--line);
  border-top: 3px solid rgba(109, 94, 155, 0.28);
  border-radius: 8px;
  padding: 12px;
  background: #fbfbfe;
  min-width: 0;
}

.calc-grid span,
.calc-grid small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.calc-grid strong {
  display: block;
  margin-top: 6px;
  margin-bottom: 4px;
  font-size: 18px;
}

.calc-grid small {
  overflow-wrap: anywhere;
}

.calc-table-wrap {
  margin-top: 8px;
  overflow-x: auto;
}

.calc-table {
  min-width: 560px;
  font-size: 13px;
}

.calc-table th,
.calc-table td {
  white-space: nowrap;
}

.calc-table td:first-child,
.calc-table th:first-child {
  white-space: normal;
}

.calc-table .limiting td {
  background: #f1f8f7;
  font-weight: 700;
}

.math-note,
.math {
  display: block;
}

.math {
  margin-top: 4px;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.math sup {
  font-size: 0.78em;
  line-height: 0;
}

.math sub {
  font-size: 0.75em;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title h2 {
  margin-bottom: 0;
}

.tag {
  display: inline-block;
  margin-left: 6px;
  border: 1px solid #d9c59c;
  border-radius: 999px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  vertical-align: middle;
}

.doc-app {
  max-width: 980px;
}

.doc-page {
  overflow: visible;
}

.doc-content {
  display: grid;
  gap: 22px;
  padding: 24px;
}

.doc-content section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.doc-content section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.doc-content h2 {
  color: var(--accent);
}

.doc-content p,
.doc-content li {
  color: var(--ink);
  line-height: 1.7;
  font-size: 15px;
}

.doc-content p + p {
  margin-top: 8px;
}

pre {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  padding: 12px;
  margin: 12px 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8faf9;
}

tr.selected-model td {
  background: #f1f8f7;
  font-weight: 700;
}

td:nth-child(2),
td:nth-child(3) {
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .app {
    width: min(100vw - 18px, 760px);
    padding: 9px 0;
  }

  .layout {
    display: block;
  }

  .header {
    padding: 16px;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .header-actions {
    margin-top: 10px;
    justify-content: space-between;
    width: 100%;
  }

  .app-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
  }

  .pill {
    display: inline-block;
    margin-top: 10px;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  fieldset,
  .grid,
  .summary-grid,
  .calc-grid {
    grid-template-columns: 1fr;
  }

  .results,
  .inputs {
    padding: 16px;
  }

  .result-hero strong {
    font-size: 48px;
  }
}
