* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #f5f6f8; --bg-card: #ffffff; --bg-input: #f0f1f4; --bg-hover: #eaebef;
    --accent: #2563eb; --accent-light: #3b82f6; --accent-bg: #eff4ff; --accent-border: #bfdbfe;
    --warn: #d97706; --warn-bg: #fffbeb; --warn-border: #fde68a;
    --fail: #dc2626; --pass: #16a34a;
    --text: #1e293b; --text-dim: #64748b; --text-muted: #94a3b8;
    --border: #e2e8f0; --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
    --mono: 'JetBrains Mono', monospace; --sans: 'Inter', -apple-system, sans-serif;
}
body { font-family: var(--sans); background: var(--bg); color: var(--text); min-height: 100vh; padding: 20px; font-size: 14px; }
.container { max-width: 1500px; margin: 0 auto; }
h1 { text-align: center; font-size: 1.75em; font-weight: 700; margin-bottom: 4px; }
.subtitle { text-align: center; color: var(--text-dim); font-size: 0.88em; margin-bottom: 20px; }
.tab-nav { display: flex; background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0; border: 1px solid var(--border); border-bottom: none; overflow-x: auto; box-shadow: var(--shadow); }
.tab-button { flex: 1; padding: 12px 14px; background: transparent; color: var(--text-dim); border: none; cursor: pointer; font-size: 0.88em; font-weight: 600; font-family: var(--sans); transition: all 0.15s; white-space: nowrap; border-right: 1px solid var(--border); position: relative; }
.tab-button:last-child { border-right: none; }
.tab-button:hover { color: var(--text); background: var(--bg); }
.tab-button.active { color: var(--accent); background: var(--bg); }
.tab-button.active::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: var(--accent); }
.tab-content { background: var(--bg); padding: 24px; border-radius: 0 0 var(--radius) var(--radius); border: 1px solid var(--border); border-top: none; min-height: 500px; }
.tab-pane { display: none; } .tab-pane.active { display: block; }
.section-title { color: var(--text); margin-bottom: 20px; font-size: 1.35em; font-weight: 700; text-align: center; }
.calculator-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; }
.calc-card { background: var(--bg-card); border-radius: var(--radius); padding: 22px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.calc-card:hover { box-shadow: var(--shadow-md); }
.calc-card h2 { color: var(--accent); margin-bottom: 4px; font-size: 1.05em; font-weight: 700; }
.card-desc { color: var(--text-dim); font-size: 0.82em; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); line-height: 1.5; }
.formula-box { margin-bottom: 16px; padding: 10px 14px; background: var(--accent-bg); border: 1px solid var(--accent-border); border-radius: 6px; font-family: var(--mono); font-size: 0.8em; color: var(--text); line-height: 1.7; }
.formula-box .f-label { font-family: var(--sans); font-weight: 600; color: var(--accent); font-size: 0.85em; margin-bottom: 4px; }
.formula-box .f-note { font-family: var(--sans); color: var(--text-dim); font-size: 0.92em; font-style: italic; margin-top: 4px; }
.formula-box code { background: rgba(37,99,235,0.08); padding: 1px 5px; border-radius: 3px; font-weight: 500; }
.input-group { margin-bottom: 12px; }
label { display: block; margin-bottom: 4px; color: var(--text-dim); font-weight: 500; font-size: 0.84em; }
input[type="number"] { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.92em; font-family: var(--mono); background: var(--bg-input); color: var(--text); transition: border-color 0.15s; }
input[type="number"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
button { width: 100%; padding: 9px; background: var(--accent); color: white; border: none; border-radius: 6px; font-size: 0.88em; font-weight: 600; font-family: var(--sans); cursor: pointer; transition: all 0.12s; margin-top: 6px; }
button:hover { background: var(--accent-light); } button:active { transform: scale(0.98); }
button.btn-secondary { background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border); }
button.btn-secondary:hover { background: var(--bg-hover); color: var(--text); }
.result { margin-top: 14px; padding: 12px 14px; background: var(--bg-input); border-radius: 6px; border-left: 3px solid var(--accent); min-height: 44px; font-family: var(--mono); font-size: 0.84em; line-height: 1.7; }
.result h3 { color: var(--accent); margin-bottom: 6px; font-family: var(--sans); font-size: 0.9em; }
.result p { color: var(--text-dim); margin: 2px 0; }
.result .value { font-weight: 600; color: var(--text); }
.result .pass { color: var(--pass); font-weight: 700; }
.result .fail { color: var(--fail); font-weight: 700; }
.result .warn { color: var(--warn); font-weight: 600; }
.result hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.complex-input { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mode-toggle { display: flex; gap: 4px; margin-bottom: 12px; }
.mode-toggle button { flex: 1; padding: 6px 4px; margin-top: 0; font-size: 0.8em; background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border); border-radius: 5px; }
.mode-toggle button.active { background: var(--accent); color: white; border-color: var(--accent); }
.mode-toggle button:hover:not(.active) { background: var(--bg-hover); color: var(--text); }
@media (max-width: 900px) { .tab-nav { flex-wrap: wrap; } .tab-button { flex: 1 0 50%; } .calculator-grid { grid-template-columns: 1fr; } .tab-content { padding: 14px; } }

/* ── L-Network schematic container ────────────────────────────────────────── */
.schematic-wrap {
    background: #f8faff;
    border: 1px solid var(--accent-border);
    border-radius: 6px;
    padding: 12px 6px 10px;
    margin-top: 14px;
    overflow: hidden;
}
.schematic-wrap svg {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}
.schematic-legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: .75em;
    color: var(--text-dim);
    font-family: var(--sans);
}
.schematic-legend span {
    display: flex;
    align-items: center;
    gap: 5px;
}
.schematic-legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* LoRaWAN locked parameter fields */
.lorawan-locked { pointer-events:none; opacity:0.52; }
.lorawan-locked select,
.lorawan-locked input[type="number"],
.lorawan-locked input[type="checkbox"] {
    background:var(--bg-hover) !important;
    border-color:var(--border) !important;
    cursor:not-allowed !important;
    color:var(--text-dim) !important;
}
.locked-badge {
    display:inline-flex; align-items:center; gap:3px;
    font-size:0.7em; font-family:var(--sans);
    color:var(--warn); background:var(--warn-bg);
    border:1px solid var(--warn-border); border-radius:4px;
    padding:1px 5px; margin-left:6px; vertical-align:middle; cursor:help;
}
.lorawan-fixed-banner {
    display:none; margin-bottom:12px; padding:7px 10px;
    background:var(--warn-bg); border:1px solid var(--warn-border);
    border-radius:6px; font-size:0.78em; font-family:var(--sans);
    color:var(--warn); line-height:1.5;
}
.lorawan-fixed-banner.visible { display:block; }

/* ── Packet diagram rich tooltip — JS-positioned, appended to body ── */
.pkt-block { position:relative; }

/* The tooltip div inside each block is hidden; JS reads its content
    and shows #pkt-global-tooltip positioned via fixed coords.          */
.pkt-tooltip { display:none; }

#pkt-global-tooltip {
    display:none;
    position:fixed;
    z-index:9999;
    width:330px;
    max-width:90vw;
    background:#1e293b;
    color:#e2e8f0;
    border-radius:8px;
    padding:12px 14px;
    box-shadow:0 8px 28px rgba(0,0,0,0.4);
    font-family:var(--sans);
    font-size:0.78em;
    line-height:1.55;
    pointer-events:none;
    white-space:normal;
    text-align:left;
}
#pkt-global-tooltip::after {
    content:'';
    position:absolute;
    top:100%;
    left:var(--arrow-left, 50%);
    transform:translateX(-50%);
    border:6px solid transparent;
    border-top-color:#1e293b;
}
/* Tooltip internals */
.pkt-tt-title {
    font-weight:700;
    font-size:1.05em;
    color:#f1f5f9;
    margin-bottom:8px;
    padding-bottom:6px;
    border-bottom:1px solid rgba(255,255,255,0.15);
}
.pkt-tt-table {
    border-collapse:collapse;
    width:100%;
    margin-bottom:8px;
    font-family:var(--mono);
    font-size:0.9em;
}
.pkt-tt-table td {
    padding:2px 6px 2px 0;
    vertical-align:top;
    color:#94a3b8;
}
.pkt-tt-table td:first-child { white-space:nowrap; min-width:80px; }
.pkt-tt-table td:last-child  { color:#e2e8f0; }
.pkt-tt-sep {
    border-top:1px solid rgba(255,255,255,0.12);
    margin:8px 0;
}
.pkt-tt-body { color:#cbd5e1; font-size:0.95em; }
.pkt-tt-body strong { color:#f1f5f9; }
.pkt-tt-body em { color:#94a3b8; font-style:italic; }

/* ── IQ Viewer ─────────────────────────────────────────────────────── */
.iq-toolbar { display:flex; align-items:center; gap:8px; flex-wrap:wrap; padding:10px 14px; background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius); margin-bottom:12px; box-shadow:var(--shadow); }
.iq-toolbar-sep { width:1px; height:22px; background:var(--border); flex-shrink:0; }
.iq-drop-zone { display:flex; align-items:center; gap:8px; padding:6px 14px; border:1.5px dashed var(--border); border-radius:6px; cursor:pointer; font-size:0.82em; font-family:var(--mono); color:var(--text-dim); transition:border-color 0.15s, background 0.15s; min-width:190px; max-width:320px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.iq-drop-zone:hover, .iq-drop-zone.drag-over { border-color:var(--accent); background:var(--accent-bg); color:var(--accent); }
.iq-drop-zone.has-file { border-style:solid; border-color:var(--accent); color:var(--text); }
.iq-stats { display:flex; gap:14px; flex-wrap:wrap; font-family:var(--mono); font-size:0.78em; color:var(--text-dim); }
.iq-stats span { white-space:nowrap; }
.iq-panel-wrap { background:#161b22; border:1px solid var(--border); border-radius:var(--radius); overflow:hidden; position:relative; }
.iq-panel-wrap canvas { display:block; width:100%; height:100%; }
.iq-statusbar { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px; padding:6px 10px; background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius); font-size:0.78em; font-family:var(--mono); color:var(--text-dim); margin-top:4px; }
/* IQ tab: override the tab-content padding so canvases sit flush */
#iq-tab { min-height: 0; }