/* ES Substation Grounding Calculator — scoped to .es-sgd */
.es-sgd {
	--sgd-navy: #1F3864;
	--sgd-navy-2: #2c4a7e;
	--sgd-amber: #C9A21A;
	--sgd-ink: #1c2330;
	--sgd-muted: #5b6577;
	--sgd-line: #dfe3ea;
	--sgd-bg: #f5f7fa;
	--sgd-card: #ffffff;
	--sgd-ok: #1e7b4f;
	--sgd-ok-bg: #e7f4ed;
	--sgd-bad: #b3261e;
	--sgd-bad-bg: #fbeceb;
	--es-sgd-sticky-top: 0px;
	font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
	color: var(--sgd-ink);
	font-size: 15px;
	line-height: 1.5;
	max-width: 1220px;
	margin: 0 auto;
}
.es-sgd *, .es-sgd *::before, .es-sgd *::after { box-sizing: border-box; }

.es-sgd-head { margin: 0 0 14px; }
.es-sgd-kicker { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--sgd-amber); font-weight: 600; }
.es-sgd-title { margin: 4px 0 6px; font-size: 26px; line-height: 1.2; color: var(--sgd-navy); font-weight: 700; }
.es-sgd-lede { margin: 0; color: var(--sgd-muted); }

/* Toolbar */
.es-sgd-toolbar {
	position: sticky; top: var(--es-sgd-sticky-top); z-index: 20;
	display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
	padding: 10px 12px; margin: 0 0 16px;
	background: var(--sgd-navy); border-radius: 10px;
	box-shadow: 0 4px 14px rgba(31,56,100,.18);
}
.es-sgd-btn {
	font: 600 14px/1 "IBM Plex Sans", system-ui, sans-serif;
	padding: 10px 14px; border-radius: 7px; cursor: pointer;
	border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
}
.es-sgd-btn:hover { background: rgba(255,255,255,.1); }
.es-sgd-btn:focus-visible { outline: 2px solid var(--sgd-amber); outline-offset: 2px; }
.es-sgd-btn[disabled] { opacity: .45; cursor: not-allowed; }
.es-sgd-btn-primary { background: var(--sgd-amber); border-color: var(--sgd-amber); color: #1a1a1a; }
.es-sgd-btn-primary:hover { background: #d8b12a; }
.es-sgd-sel select {
	font: 500 14px/1 "IBM Plex Sans", system-ui, sans-serif; color: #fff; background: transparent;
	border: 1px solid rgba(255,255,255,.35); border-radius: 7px; padding: 9px 30px 9px 12px; height: auto; margin: 0;
	appearance: none; -webkit-appearance: none; cursor: pointer; max-width: 210px;
	background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
	background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.es-sgd-sel select option { color: #1c2330; background: #fff; }
.es-sgd-guide-btn { display: none; }
.es-sgd-switch { display: inline-flex; align-items: center; gap: 6px; color: #fff; font-size: 14px; cursor: pointer; padding: 0 4px; }
.es-sgd-switch input { accent-color: var(--sgd-amber); width: 16px; height: 16px; }
.es-sgd-loading { visibility: hidden; min-height: 20px; color: #fff; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.es-sgd.is-busy .es-sgd-loading { visibility: visible; }
.es-sgd-spin { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: var(--sgd-amber); border-radius: 50%; animation: es-sgd-spin .8s linear infinite; }
@keyframes es-sgd-spin { to { transform: rotate(360deg); } }

/* Cards */
.es-sgd-card { background: var(--sgd-card); border: 1px solid var(--sgd-line); border-radius: 10px; padding: 16px 18px 18px; margin: 0 0 14px; }
.es-sgd-h { margin: 0 0 14px; font-size: 16px; font-weight: 600; color: var(--sgd-navy); display: inline-block; padding-bottom: 4px; border-bottom: 2px solid var(--sgd-amber); }
.es-sgd-h small { font-weight: 400; color: var(--sgd-muted); font-size: 12px; }
.es-sgd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.es-sgd-grid[hidden] { display: none; }
.es-sgd-field { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.es-sgd-lab { font-size: 13px; font-weight: 500; color: var(--sgd-ink); }
.es-sgd-in { display: flex; align-items: stretch; border: 1px solid #c9cfd9; border-radius: 7px; background: #fff; overflow: hidden; }
.es-sgd-in:focus-within { border-color: var(--sgd-navy); box-shadow: 0 0 0 3px rgba(31,56,100,.12); }
.es-sgd-in input, .es-sgd-in select {
	flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; margin: 0;
	padding: 9px 10px; font: 400 15px/1.2 "JetBrains Mono", ui-monospace, monospace; color: var(--sgd-ink);
	font-variant-numeric: tabular-nums; box-shadow: none; height: auto;
}
.es-sgd-in input[type="text"] { font-family: "IBM Plex Sans", system-ui, sans-serif; }
.es-sgd-in em { font-style: normal; font-size: 13px; color: var(--sgd-muted); background: var(--sgd-bg); padding: 9px 10px; border-left: 1px solid var(--sgd-line); white-space: nowrap; display: flex; align-items: center; }
.es-sgd-field small { font-size: 12px; color: var(--sgd-muted); line-height: 1.35; }
.es-sgd-field.has-err .es-sgd-in { border-color: var(--sgd-bad); }
.es-sgd-field .es-sgd-err { color: var(--sgd-bad); font-size: 12px; }

.es-sgd-seg { border: 0; padding: 0; margin: 14px 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.es-sgd-seg:first-of-type { margin-top: 2px; }
.es-sgd-seg legend { font-size: 13px; font-weight: 500; padding: 0; margin-bottom: 6px; width: 100%; }
.es-sgd-seg label { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid #c9cfd9; border-radius: 999px; font-size: 13px; cursor: pointer; background: #fff; }
.es-sgd-seg label:has(input:checked) { border-color: var(--sgd-navy); background: #eef2f9; color: var(--sgd-navy); font-weight: 500; }
.es-sgd-seg input { accent-color: var(--sgd-navy); margin: 0; }

.es-sgd-msg { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; background: var(--sgd-bad-bg); color: var(--sgd-bad); font-size: 14px; }
.es-sgd-msg[hidden] { display: none; }

/* Results */
.es-sgd-results[hidden] { display: none; }
.es-sgd-verdict { border-left: 5px solid var(--sgd-ok); }
.es-sgd-verdict.is-bad { border-left-color: var(--sgd-bad); }
.es-sgd-verdict-text { margin: 0 0 12px; font-weight: 600; font-size: 16px; }
.es-sgd-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.es-sgd-checks li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 8px 10px; border-radius: 7px; background: var(--sgd-ok-bg); font-size: 14px; }
.es-sgd-checks li.is-bad { background: var(--sgd-bad-bg); }
.es-sgd-checks li.is-info { background: #eef2f9; }
.es-sgd-checks b { min-width: 170px; }
.es-sgd-tag { font: 600 11px/1 "IBM Plex Sans", sans-serif; letter-spacing: .05em; padding: 4px 7px; border-radius: 4px; background: var(--sgd-ok); color: #fff; }
.is-bad > .es-sgd-tag { background: var(--sgd-bad); }
.is-info > .es-sgd-tag { background: var(--sgd-navy-2); }

.es-sgd-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.es-sgd-kpi { background: var(--sgd-bg); border-radius: 8px; padding: 10px 12px; }
.es-sgd-kpi span { display: block; font-size: 12px; color: var(--sgd-muted); }
.es-sgd-kpi strong { display: block; font: 600 20px/1.25 "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; color: var(--sgd-navy); }
.es-sgd-kpi strong small { font-size: 12px; font-weight: 400; color: var(--sgd-muted); margin-left: 3px; }

.es-sgd-bars { display: grid; gap: 14px; }
.es-sgd-bar-row { display: grid; gap: 4px; }
.es-sgd-bar-lab { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.es-sgd-bar-lab code { font: 500 13px "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; background: none; padding: 0; color: var(--sgd-ink); }
.es-sgd-bar-track { position: relative; height: 12px; background: var(--sgd-bg); border-radius: 6px; }
.es-sgd-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: var(--sgd-ok); }
.es-sgd-bar-fill.is-bad { background: var(--sgd-bad); }
.es-sgd-bar-fill.is-info { background: var(--sgd-navy-2); }
.es-sgd-bar-limit { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--sgd-navy); }

.es-sgd-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 0; }
.es-sgd-table th, .es-sgd-table td { padding: 7px 8px; border: 0; border-bottom: 1px solid var(--sgd-line); text-align: left; vertical-align: top; background: none; }
.es-sgd-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--sgd-muted); font-weight: 600; }
.es-sgd-table td.num { text-align: right; font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.es-sgd-table td.sym { font-family: "JetBrains Mono", monospace; color: var(--sgd-navy); white-space: nowrap; }
.es-sgd-table tr.is-sel td { background: #fbf6e3; }
.es-sgd-table .grp td { background: var(--sgd-bg); font-weight: 600; color: var(--sgd-navy); font-size: 13px; }

.es-sgd-canvas-wrap { width: 100%; }
.es-sgd-canvas { width: 100%; height: auto; display: block; border-radius: 8px; background: #fbfcfe; border: 1px solid var(--sgd-line); }

.es-sgd-steps { display: none; }
.es-sgd.es-sgd-show-steps .es-sgd-steps { display: block; }
.es-sgd-step { margin: 0 0 14px; }
.es-sgd-step h4 { margin: 0 0 6px; font-size: 14px; color: var(--sgd-navy); }
.es-sgd-step ol { margin: 0; padding: 0; list-style: none; }
.es-sgd-step li { font: 13px/1.6 "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; padding: 2px 0 2px 10px; border-left: 2px solid var(--sgd-amber); overflow-wrap: anywhere; }

.es-sgd-notes ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--sgd-muted); }
.es-sgd-notes li { margin: 0 0 4px; }
.es-sgd-disclaimer { font-size: 12px; color: var(--sgd-muted); border-top: 1px solid var(--sgd-line); padding-top: 10px; margin: 6px 0 0; }

/* Modal */
.es-sgd-modal { position: fixed; inset: 0; z-index: 99999; background: rgba(15,23,40,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.es-sgd-modal[hidden] { display: none; }
.es-sgd-modal-box { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 420px; display: grid; gap: 10px; font-family: "IBM Plex Sans", system-ui, sans-serif; color: var(--sgd-ink); }
.es-sgd-modal-p { margin: 0; font-size: 13px; color: var(--sgd-muted); }
.es-sgd-modal-act { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.es-sgd-modal .es-sgd-btn { color: var(--sgd-navy); border-color: #c9cfd9; }
.es-sgd-modal .es-sgd-btn-primary { color: #1a1a1a; border-color: var(--sgd-amber); }

@media (max-width: 560px) {
	.es-sgd-title { font-size: 22px; }
	.es-sgd-card { padding: 14px; }
	.es-sgd-toolbar { padding: 8px; gap: 6px; }
	.es-sgd-btn { padding: 9px 11px; font-size: 13px; }
	.es-sgd-loading { position: absolute; right: 8px; top: calc(100% + 6px); margin: 0; padding: 5px 10px; border-radius: 999px; background: var(--sgd-navy); box-shadow: 0 4px 10px rgba(15,23,40,.2); }
	.es-sgd-checks b { min-width: 0; }
	.es-sgd-table { font-size: 13px; }
}

/* ===== v1.1 — main + guide panel layout ===== */
.es-sgd-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.es-sgd-main { min-width: 0; }
.es-sgd-aside { position: sticky; top: calc(var(--es-sgd-sticky-top) + 76px); min-width: 0; }
.es-sgd-aside-in {
	background: var(--sgd-card); border: 1px solid var(--sgd-line); border-top: 4px solid var(--sgd-amber);
	border-radius: 10px; padding: 14px 16px 16px;
	max-height: calc(100vh - var(--es-sgd-sticky-top) - 96px); overflow-y: auto; overscroll-behavior: contain;
}
.es-sgd-aside-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; min-height: 26px; }
.es-sgd-aside-kicker { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--sgd-muted); font-weight: 600; margin-left: auto; }
.es-sgd-x { display: none; border: 0; background: var(--sgd-bg); color: var(--sgd-ink); width: 30px; height: 30px; border-radius: 50%; font-size: 20px; line-height: 1; cursor: pointer; padding: 0; }
.es-sgd-link { border: 0; background: none; padding: 0; color: var(--sgd-navy); font: 600 13px "IBM Plex Sans", system-ui, sans-serif; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.es-sgd-link[hidden] { display: none; }
.es-sgd-topic[hidden] { display: none; }
.es-sgd-topic-t { margin: 0 0 4px; font-size: 17px; line-height: 1.3; color: var(--sgd-navy); font-weight: 700; }
.es-sgd-ref { display: inline-block; font-size: 11px; font-weight: 600; color: #7a6210; background: #fbf6e3; border-radius: 4px; padding: 3px 7px; margin: 0 0 10px; }
.es-sgd-topic-body { font-size: 14px; line-height: 1.55; }
.es-sgd-topic-body p { margin: 0 0 10px; }
.es-sgd-topic-body ul, .es-sgd-topic-body ol { margin: 0 0 10px; padding-left: 20px; }
.es-sgd-topic-body li { margin: 0 0 5px; }
.es-sgd-topic-body h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--sgd-muted); margin: 16px 0 8px; }
.es-sgd-topic-body .es-sgd-procedure { font-size: 13px; }
.es-sgd-topic-body .es-sgd-procedure li::marker { color: var(--sgd-amber); font-weight: 700; }
.es-sgd-tip { background: #eef2f9; border-left: 3px solid var(--sgd-navy); padding: 8px 10px; border-radius: 0 6px 6px 0; font-size: 13px; }
.es-sgd-htable { width: 100%; border-collapse: collapse; font-size: 13px; margin: 0 0 10px; }
.es-sgd-htable th, .es-sgd-htable td { border: 0; border-bottom: 1px solid var(--sgd-line); padding: 5px 6px; text-align: left; background: none; }
.es-sgd-htable th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--sgd-muted); }
.es-sgd-htable .n { text-align: right; font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.es-sgd-htable-sm { font-size: 12px; }
.es-sgd-htable-sm th, .es-sgd-htable-sm td { padding: 4px 4px; }

.es-sgd-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--sgd-line); }
.es-sgd-chips-l { width: 100%; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--sgd-muted); font-weight: 600; }
.es-sgd-chip { font: 500 13px "IBM Plex Sans", system-ui, sans-serif; border: 1px solid var(--sgd-navy); color: var(--sgd-navy); background: #fff; border-radius: 999px; padding: 6px 11px; cursor: pointer; }
.es-sgd-chip:hover { background: var(--sgd-navy); color: #fff; }
.es-sgd-chip[disabled] { opacity: .4; cursor: not-allowed; background: #fff; color: var(--sgd-navy); }

/* "?" buttons */
.es-sgd-labrow { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.es-sgd-q {
	flex: none; width: 22px; height: 22px; border-radius: 50%; padding: 0; margin: 0; cursor: pointer;
	border: 1px solid #b9c1ce; background: #fff; color: var(--sgd-navy); font: 700 12px/1 "IBM Plex Sans", sans-serif;
	display: inline-flex; align-items: center; justify-content: center;
}
.es-sgd-q:hover, .es-sgd-q.is-on { background: var(--sgd-amber); border-color: var(--sgd-amber); color: #1a1a1a; }
.es-sgd-q:focus-visible { outline: 2px solid var(--sgd-navy); outline-offset: 2px; }
.es-sgd-qi { display: inline-flex; width: 18px; height: 18px; border-radius: 50%; background: var(--sgd-amber); color: #1a1a1a; font-size: 11px; align-items: center; justify-content: center; }
.es-sgd-seg legend { display: flex; align-items: center; gap: 8px; }
.es-sgd-field.is-active .es-sgd-in { border-color: var(--sgd-amber); box-shadow: 0 0 0 3px rgba(201,162,26,.18); }
.es-sgd-field.is-filled .es-sgd-in { animation: es-sgd-flash .9s ease; }
@keyframes es-sgd-flash { 0% { background: #fbf0c6; } 100% { background: #fff; } }
.es-sgd-in input::placeholder { color: #a3abb8; }
.es-sgd-stepno { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--sgd-navy); color: #fff; font-size: 12px; align-items: center; justify-content: center; margin-right: 6px; vertical-align: 1px; }
.es-sgd-err::before { content: "▲ "; font-size: 9px; }

.es-sgd-warns { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.es-sgd-warns[hidden] { display: none; }
.es-sgd-warns li { font-size: 13px; padding: 8px 10px; border-radius: 7px; background: #fbf6e3; border-left: 3px solid var(--sgd-amber); }
.es-sgd-verdict .es-sgd-link { margin-top: 12px; display: inline-block; }

/* Portal (mobile sheet + modal live under <body> to escape transformed theme wrappers) */
.es-sgd.es-sgd-portal { max-width: none; margin: 0; }
.es-sgd-scrim { display: none; }

@media (max-width: 960px) {
	.es-sgd-layout { grid-template-columns: minmax(0, 1fr); }
	.es-sgd-guide-btn { display: inline-block; }
	.es-sgd-aside { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 99998; transform: translateY(105%); transition: transform .25s ease; visibility: hidden; }
	.es-sgd-aside.is-open { transform: none; visibility: visible; }
	.es-sgd-aside-in { border-radius: 14px 14px 0 0; max-height: 78vh; border-left: 0; border-right: 0; border-bottom: 0; box-shadow: 0 -10px 30px rgba(15,23,40,.25); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
	.es-sgd-x { display: inline-flex; align-items: center; justify-content: center; }
	.es-sgd-scrim { display: block; position: fixed; inset: 0; z-index: 99997; background: rgba(15,23,40,.4); opacity: 0; visibility: hidden; transition: opacity .2s; }
	.es-sgd-scrim.is-open { opacity: 1; visibility: visible; }
}
@media (prefers-reduced-motion: reduce) { .es-sgd-aside { transition: none; } }
