/* ── Theme tokens (matches comtrade/shell.css) ── */
:root {
  color-scheme: light dark;
  --bg: #0b0c10;
  --panel: #111318;
  --text: #e9eef5;
  --muted: #a8b2c1;
  --border: #232734;
  --accent: #7aa2ff;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
}
[data-theme="light"] {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #586377;
  --border: #e6e9f2;
  --accent: #245bff;
  --shadow: 0 10px 26px rgba(16,24,40,.08);
}

/* ── App header (matches comtrade shell) ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: auto minmax(0,1fr);
  align-items: center;
  column-gap: 14px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.app-logo-area { display: flex; align-items: center; }
.app-logo-area > a,
.app-logo-area > a:visited { color: inherit; text-decoration: none; }
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand__title { font-size: 1.6rem; font-weight: 650; line-height: 1.1; color: var(--text); }
.brand__subtitle { font-size: 0.85rem; color: var(--muted); }
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-self: end;
  justify-content: flex-end;
}
.btn {
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 88%, transparent);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
}
.btn:hover { border-color: color-mix(in oklab, var(--border) 70%, var(--accent)); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--ghost { box-shadow: none; background: transparent; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn--icon { padding: 8px; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; }
.btn--theme .icon { width: 18px; height: 18px; display: none; fill: currentColor; stroke: currentColor; }
html:not([data-theme="light"]) .btn--theme .icon--sun { display: block; }
html[data-theme="light"] .btn--theme .icon--moon { display: block; }
html:not([data-theme="light"]) .btn { border-color: rgba(255,255,255,0.14); }
html:not([data-theme="light"]) .btn--ghost { background: rgba(255,255,255,0.04); }
html:not([data-theme="light"]) .btn--ghost:hover { background: rgba(255,255,255,0.08); }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            min-height: 100vh;
            display: flex;
            align-items: stretch;
            background-color: var(--bg);
            color: var(--text);
            flex-direction: column;
            padding: 0;
        }

        p {
            font-size: 1rem !important;
            margin: 0 !important;
            color: var(--text);
            text-wrap: wrap;
        }

        a {
            color: rgb(255, 255, 11);
        }

        #a1:visited {
            color: rgb(0, 255, 255);
            /* Change to the desired color */
        }

        #a2:visited {
            color: rgb(0, 255, 255);
            /* Change to the desired color */
        }

        .container {
            width: 100%;
            max-width: 1600px;
            margin: 0 auto;
            display: flex;
            justify-content: center;
            padding: 1rem;
            align-items: flex-start;
            flex-wrap: wrap;
            gap: 1rem;
        }

        #svg {
            background-color: #1a1a1a;
            width: 100%;
            height: auto;
            display: block;
        }

        .control-panel {
            width: 100%;
            max-width: 365px;
            flex: 1 1 320px;
            min-width: 0;
        }

        .chart-panel {
            width: 100%;
            min-width: 280px;
            flex: 2 1 650px;
            display: flex;
            justify-content: center;
        }

        .side-panel {
            width: 100%;
            max-width: 380px;
            flex: 1 1 320px;
            display: flex;
            flex-direction: column;
            padding-top: 0.5rem;
            min-width: 0;
        }

        @media (min-width: 1200px) {
            .container {
                flex-wrap: nowrap;
            }
        }

        .divMVA,
        .divHvV,
        .divLvV,
        .divZ,
        .divCThv,
        .pickupMarginDiv,
        .coordinationMarginDiv,
        .divTripHV,
        .divTripMV {
            flex-wrap: wrap;
            gap: 0.35rem;
            align-items: center;
        }

        .divMVA label,
        .divHvV label,
        .divLvV label,
        .divZ label,
        .divCThv label,
        .divTripHV label,
        .divTripMV label,
        .pickupMarginDiv .tooltip,
        .coordinationMarginDiv .tooltip,
        .coordinationMarginDiv label {
            flex: 1 1 180px;
            min-width: 0;
        }

        .ctRatioInputs {
            display: flex;
            align-items: center;
            gap: 0.35rem;
        }

        .ctRatioInputs input {
            width: 60px;
        }

        .axis text {
            fill: white;
        }

        .axis path,
        .axis line {
            stroke: white;
        }

        .grid path,
        .subgrid path {
            display: none;
        }

        .grid line {
            stroke: #fff;
            stroke-opacity: 0.2;
        }

        .subgrid line {
            stroke: #fff;
            stroke-opacity: 0.1;
        }

        .curve-label {
            font-size: 1rem;
            fill: white;
        }

        .legend {
            font-size: 1rem;
            fill: white;
        }

        .table {
            display: flex;
            flex-direction: column;
            gap: 1rem;
            padding-right: 5px;
            font-family: Arial, sans-serif;
        }

        .table table {
            border-collapse: collapse;
            width: 100%;
        }

        .table th,
        .table td {
            border: none;
            padding: 8px;
            text-align: left;
            color: var(--text);
            font-size: 1rem;
        }

        .table th {
            background-color: var(--panel);
            color: var(--text);
        }

        input,
        select {
            width: 75px;
            background: none;
            color: var(--text);
        }

        option,
        label {
            background-color: var(--bg);
            color: var(--text);
        }

        .axis-label {
            font-size: 1rem;
            fill: white;
        }

        .title {
            font-size: 2.5rem;
            fill: white;
            font-weight: bold;
        }

        p>.katex {
            font-size: 1rem !important;
        }

        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
        }

        .modal-content {
            background: var(--panel);
            display: flex;
            flex-direction: column;
            justify-content: start;
            margin: 1% auto;
            padding: 7px 14px;
            border: 1px solid #888;
            width: 80%;
        }

        .close {
            color: var(--text);
            float: right;
            font-size: 28px;
            font-weight: bold;
        }

        .close:hover,
        .close:focus {
            color: rgb(84, 83, 83);
            text-decoration: none;
            cursor: pointer;
        }

        .tooltip {
            position: relative;
            cursor: help;
        }

        .tooltip span {
            display: none;
            /* Hidden by default */
            position: absolute;
            background: #333;
            color: #fff;
            padding: 8px 12px;
            border-radius: 5px;
            max-width: 750px;
            /* Define max width for wrapping */
            white-space: normal;
            /* Allow text to wrap */
            z-index: 10;
            top: -100%;
            /* Position below the icon */
            left: -10%;
            transform: translateX(-150%);
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            /* Add a subtle shadow */
        }

        .tooltip:hover span {
            display: block;
            /* Show tooltip on hover */
        }

        /* Prevent overflow near screen edges */
        .tooltip span::after {
            content: '';
            /* Optional arrow for tooltip */
            position: absolute;
            bottom: 100%;
            /* Position arrow above the tooltip */
            left: 50%;
            transform: translateX(-50%);
            border-width: 5px;
            border-style: solid;
            border-color: transparent transparent #333 transparent;
        }

        .tick {
            font-size: 0.75rem;
        }

        .hidden-output {
            display: none;
            /* Hides the element completely */
        }

        /* Editable SVG diagram labels */
        #MVA, #HV-Bus, #MV-Bus, #Impedance, #HV1-CT, #HV-CT, #MV-CT {
            cursor: pointer;
            text-decoration: underline;
            text-decoration-style: dotted;
            text-decoration-color: rgba(255,255,255,0.45);
            text-decoration-thickness: 1px;
        }
        #MVA:hover, #HV-Bus:hover, #MV-Bus:hover,
        #Impedance:hover, #HV1-CT:hover, #HV-CT:hover, #MV-CT:hover {
            fill: #93c5fd !important;
        }
        #dragTooltip {
            position: fixed;
            padding: 4px 9px;
            background: rgba(10, 15, 25, 0.88);
            color: #e2e8f0;
            font-size: 0.75rem;
            font-family: system-ui, sans-serif;
            border: 1px solid rgba(255,255,255,0.12);
            border-radius: 4px;
            white-space: nowrap;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.12s ease;
            z-index: 9999;
        }
        #dragTooltip.visible { opacity: 1; }
        #diagramModal {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.72);
            backdrop-filter: blur(3px);
            z-index: 800;
            align-items: center;
            justify-content: center;
            cursor: pointer;
        }
        #diagramModal.open { display: flex; }
        #diagramModalInner {
            background: #1a1a1a;
            border-radius: 8px;
            padding: 16px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.6);
            cursor: default;
        }
        #diagramModalSvg {
            display: block;
            width: 80vmin;
            height: 80vmin;
            max-width: 90vw;
            max-height: 90vh;
        }

.btn--theme .icon { background: none !important; }
