:root {
  color-scheme: dark;
  --bg: #071019;
  --bg-deep: #040a10;
  --panel: #0d1924;
  --panel-2: #111f2b;
  --panel-3: #142634;
  --line: #203443;
  --line-soft: rgba(125, 157, 177, 0.16);
  --text: #edf5f7;
  --muted: #8fa7b5;
  --faint: #607888;
  --cyan: #35d7e3;
  --cyan-soft: rgba(53, 215, 227, 0.14);
  --blue: #4f8cff;
  --orange: #ff9e43;
  --green: #58d493;
  --red: #ff6b68;
  --yellow: #f5c45e;
  --radius: 18px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 76% -12%, rgba(38, 115, 150, 0.17), transparent 34rem),
    linear-gradient(145deg, var(--bg) 0%, var(--bg-deep) 72%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; }
button { color: inherit; }

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.topbar {
  height: 76px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(5, 13, 20, 0.83);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-content: center;
  gap: 3px;
  border: 1px solid rgba(53, 215, 227, 0.45);
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(53, 215, 227, 0.16), rgba(79, 140, 255, 0.04));
  box-shadow: inset 0 0 18px rgba(53, 215, 227, 0.08);
}

.brand-mark span {
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: var(--cyan);
  transform: skewX(-28deg);
}

.brand-mark span:nth-child(2) { width: 12px; margin-left: 5px; background: var(--orange); }
.brand strong { display: block; font-size: 1.03rem; letter-spacing: 0.02em; }
.brand small { display: block; margin-top: -2px; color: var(--faint); font: 0.68rem/1.1 var(--mono); text-transform: uppercase; letter-spacing: 0.12em; }

.top-actions { display: flex; align-items: center; gap: 12px; }
.local-badge, .flow-pill, .engine-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #b9ccd5;
  background: rgba(14, 29, 39, 0.75);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
}

.engine-badge {
  font-family: var(--mono);
  font-size: 0.74rem;
  border-color: rgba(53, 215, 227, 0.45);
  background: rgba(53, 215, 227, 0.12);
  color: var(--cyan);
  font-weight: 600;
}

.engine-badge.py-mode {
  border-color: rgba(245, 196, 94, 0.45);
  background: rgba(245, 196, 94, 0.12);
  color: var(--yellow);
}

.local-badge i, .flow-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(88, 212, 147, 0.1), 0 0 12px rgba(88, 212, 147, 0.55);
}

.ghost-button, .small-button, .icon-button, .preset, .segmented-control button {
  border: 1px solid var(--line);
  background: rgba(14, 29, 39, 0.72);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.ghost-button { min-height: 36px; padding: 0 14px; color: #bed0d9; font-size: 0.83rem; }
.ghost-button:hover, .small-button:hover, .icon-button:hover { border-color: #426172; color: white; background: #142633; }

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(0, 1fr);
  max-width: 1700px;
  margin: 0 auto;
}

.controls-panel {
  padding: 28px 24px 80px;
  border-right: 1px solid var(--line-soft);
  background: rgba(7, 16, 25, 0.72);
}

.controls-heading, .panel-heading, .section-title-row, .geometry-card-head, .dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font: 0.69rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.35rem; line-height: 1.25; letter-spacing: -0.025em; }
h2 { margin-bottom: 0; font-size: 1.15rem; line-height: 1.3; letter-spacing: -0.02em; }
h3 { font-size: 0.94rem; }

.icon-button {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-content: center;
  color: var(--muted);
  font-size: 1.2rem;
}

.preset-row { display: flex; gap: 7px; margin: 22px 0 14px; }
.preset { padding: 7px 10px; color: var(--muted); font-size: 0.75rem; }
.preset:hover { color: var(--text); }
.preset.active { color: var(--cyan); border-color: rgba(53, 215, 227, 0.42); background: var(--cyan-soft); }

.control-section {
  margin-top: 10px;
  padding: 15px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(15, 29, 40, 0.72);
}

.primary-control { padding: 16px 16px 12px; }
.primary-control label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: #d4e3e9; font-size: 0.86rem; }
.primary-control output { color: var(--cyan); font: 0.79rem var(--mono); }
input[type="range"] { width: 100%; margin: 16px 0 4px; accent-color: var(--cyan); }
.range-scale { display: flex; justify-content: space-between; color: var(--faint); font: 0.66rem var(--mono); }

details summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: #c9d9df;
  font-size: 0.85rem;
  font-weight: 650;
}

details summary::-webkit-details-marker { display: none; }
details summary::before { content: "+"; margin-right: 9px; color: var(--faint); font: 0.9rem var(--mono); }
details[open] summary::before { content: "−"; color: var(--cyan); }
.summary-hint { margin-left: auto; color: var(--faint); font: 0.7rem var(--mono); letter-spacing: 0.08em; }
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.field { display: block; }
.field span, .geometry-mini-grid span { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 5px; color: var(--muted); font-size: 0.72rem; }
.field b { color: var(--faint); font: 0.65rem var(--mono); }

input[type="number"], input[type="text"], .section-name {
  width: 100%;
  min-height: 37px;
  border: 1px solid #263d4c;
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
  background: #09151e;
  font-family: var(--mono);
  font-size: 0.78rem;
}

input:hover { border-color: #3b596a; }
input:focus { border-color: var(--cyan); }

.geometry-section { padding: 15px 10px 10px; }
.section-title-row { padding: 0 5px 10px; }
.section-title-row p { margin: 2px 0 0; color: var(--faint); font-size: 0.68rem; }
.small-button { min-height: 32px; padding: 0 10px; color: var(--muted); font-size: 0.73rem; }
.geometry-rows { display: grid; gap: 8px; }
.geometry-card { padding: 10px; border: 1px solid var(--line-soft); border-radius: 11px; background: rgba(5, 15, 22, 0.7); }
.geometry-card-head { gap: 8px; margin-bottom: 9px; }
.section-index { color: var(--cyan); font: 0.63rem var(--mono); }
.section-name { flex: 1; min-height: 30px; border: 0; padding: 4px 7px; background: transparent; font-family: var(--sans); font-weight: 650; }
.remove-section { width: 26px; height: 26px; border: 0; border-radius: 7px; color: var(--faint); background: transparent; cursor: pointer; }
.remove-section:hover { color: var(--red); background: rgba(255, 107, 104, 0.09); }
.geometry-mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.geometry-mini-grid input { min-height: 32px; padding: 5px 7px; font-size: 0.7rem; }
.geometry-mini-grid span { font-size: 0.62rem; }

.calculate-dock { position: sticky; bottom: 0; z-index: 5; margin: 12px -8px 0; padding: 12px 8px 4px; background: linear-gradient(transparent, var(--bg) 24%); }
.calculate-button {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 12px;
  padding: 0 17px;
  color: #021014;
  background: linear-gradient(120deg, var(--cyan), #69e9d2);
  box-shadow: 0 12px 30px rgba(53, 215, 227, 0.14);
  cursor: pointer;
  font-weight: 800;
}
.calculate-button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.calculate-button:disabled { cursor: wait; filter: saturate(0.3); }
.button-arrow { font-size: 1.35rem; }
#calculationStatus { margin: 7px 2px 0; color: var(--faint); font-size: 0.68rem; text-align: center; }

.results-panel { min-width: 0; padding: 28px clamp(18px, 2.5vw, 38px) 60px; }
.alert-rail { min-height: 42px; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.alert-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 35px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: rgba(13, 25, 35, 0.78); font-size: 0.73rem; }
.alert-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.alert-chip.warning::before { background: var(--yellow); }
.alert-chip.danger::before { background: var(--red); }
.alert-chip.info::before { background: var(--blue); }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.metric-card, .panel { border: 1px solid var(--line-soft); background: linear-gradient(145deg, rgba(17, 32, 44, 0.92), rgba(10, 22, 31, 0.9)); }
.metric-card { position: relative; min-height: 133px; padding: 17px; border-radius: 15px; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; inset: auto -30px -50px auto; width: 100px; height: 100px; border-radius: 50%; background: rgba(53, 215, 227, 0.035); }
.metric-card.featured { border-color: rgba(53, 215, 227, 0.3); }
.metric-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 0.75rem; }
.metric-label i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.metric-card strong { display: block; margin-top: 13px; font: 700 clamp(1.45rem, 2.2vw, 2.15rem)/1 var(--mono); letter-spacing: -0.06em; }
.metric-card small { display: block; margin-top: 9px; color: var(--faint); font-size: 0.66rem; }

.analysis-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(260px, 0.72fr); gap: 12px; margin-top: 12px; }
.panel { border-radius: var(--radius); padding: 19px; }
.panel-heading { min-height: 45px; }
.panel-heading.compact { min-height: auto; }
.segmented-control { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: rgba(5, 14, 21, 0.75); }
.segmented-control button { min-height: 30px; padding: 0 10px; border: 0; color: var(--faint); background: transparent; font-size: 0.7rem; }
.segmented-control button.active { color: var(--text); background: var(--panel-3); }
.chart-legend { min-height: 28px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 8px; color: var(--muted); font-size: 0.65rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 13px; height: 2px; border-radius: 2px; }
.chart { width: 100%; min-height: 360px; overflow: hidden; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.axis-text { fill: var(--faint); font: 10px var(--mono); }
.axis-label { fill: var(--muted); font: 10px var(--sans); }
.grid-line { stroke: rgba(116, 149, 169, 0.13); stroke-width: 1; }

.well-panel { display: flex; flex-direction: column; }
.flow-pill { min-height: 28px; padding: 0 9px; font: 0.66rem var(--mono); }
.well-schematic { min-height: 340px; flex: 1; display: grid; place-items: center; margin-top: 8px; border-radius: 13px; background: radial-gradient(circle at 50% 42%, rgba(53, 215, 227, 0.06), transparent 60%); }
.well-schematic svg { width: 100%; height: 340px; }
.well-path-base { fill: none; stroke: #233d4c; stroke-width: 18; stroke-linecap: round; stroke-linejoin: round; }
.well-path-inner { fill: none; stroke: #07131c; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }
.flow-down, .flow-up { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 4 15; animation: flow 1.25s linear infinite; }
.flow-down { stroke: var(--cyan); stroke-width: 3; }
.flow-up { stroke: var(--orange); stroke-width: 3; animation-direction: reverse; animation-duration: 1.65s; }
@keyframes flow { to { stroke-dashoffset: -38; } }
.well-label { fill: var(--muted); font: 10px var(--mono); }
.well-footer { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.well-footer span { display: block; color: var(--faint); font: 0.62rem var(--mono); }
.well-footer strong { display: block; margin-top: 3px; font: 0.8rem var(--mono); }

.pressure-stack-panel { margin-top: 12px; }
.power-value { color: var(--cyan); font: 0.78rem var(--mono); }
.pressure-stack { display: flex; width: 100%; height: 13px; margin: 18px 0 13px; overflow: hidden; border-radius: 999px; background: #07121a; }
.stack-segment { min-width: 2px; height: 100%; }
.pressure-breakdown { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.breakdown-item { padding-left: 10px; border-left: 2px solid var(--item-color); }
.breakdown-item span { display: block; color: var(--faint); font-size: 0.65rem; }
.breakdown-item strong { display: block; margin-top: 3px; font: 0.8rem var(--mono); }

.table-panel { margin-top: 12px; padding-bottom: 8px; }
.export-actions { display: flex; gap: 7px; }
.table-scroll { margin: 14px -19px 0; overflow-x: auto; }
table { width: 100%; min-width: 850px; border-collapse: collapse; }
th, td { padding: 11px 14px; border-top: 1px solid var(--line-soft); text-align: right; white-space: nowrap; font-size: 0.72rem; }
th { color: var(--faint); font: 0.62rem var(--mono); text-transform: uppercase; letter-spacing: 0.04em; }
td { color: #b7c9d2; font-family: var(--mono); }
th:first-child, td:first-child { text-align: left; }
td:first-child { color: var(--text); font-family: var(--sans); font-weight: 650; }
.regime { display: inline-flex; min-height: 25px; align-items: center; padding: 0 8px; border-radius: 7px; background: rgba(79, 140, 255, 0.1); color: #91b4ff; font-family: var(--sans); }
.transport.good { color: var(--green); }
.transport.warn { color: var(--yellow); }
.transport.bad { color: var(--red); }
.model-note { max-width: 960px; margin: 15px auto 0; color: var(--faint); font-size: 0.69rem; text-align: center; }

dialog {
  width: min(760px, calc(100vw - 30px));
  border: 1px solid #2a4656;
  border-radius: 20px;
  padding: 24px;
  color: var(--text);
  background: #0b1720;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.58);
}
dialog::backdrop { background: rgba(0, 7, 12, 0.75); backdrop-filter: blur(5px); }
.dialog-heading { margin-bottom: 20px; }
.method-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.method-grid article { padding: 15px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel); }
.method-grid article > span { color: var(--cyan); font: 0.66rem var(--mono); }
.method-grid h3 { margin: 7px 0 5px; }
.method-grid p, .limitations p { margin: 0; color: var(--muted); font-size: 0.78rem; }
.limitations { margin-top: 12px; padding: 16px; border-left: 3px solid var(--orange); background: rgba(255, 158, 67, 0.06); }
.limitations h3 { margin-bottom: 5px; }

.loading .calculate-button .button-label::after { content: "…"; }
.loading .results-panel { opacity: 0.62; }
.error-banner { width: 100%; padding: 12px 14px; border: 1px solid rgba(255, 107, 104, 0.35); border-radius: 10px; color: #ffd0ce; background: rgba(255, 107, 104, 0.08); font-size: 0.78rem; }

.git-dialog { max-width: 680px; width: min(680px, calc(100vw - 30px)); max-height: 85vh; overflow-y: auto; }
.git-dialog-body { display: flex; flex-direction: column; gap: 16px; }
.git-status-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-radius: 8px; background: rgba(30, 166, 114, 0.1); border: 1px solid rgba(30, 166, 114, 0.3); font-size: 0.8rem; color: #7fe6ba; }
.git-changes-section h3, .git-history-section h3 { margin: 0 0 8px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.git-file-list { margin: 0; padding-left: 18px; max-height: 100px; overflow-y: auto; font-family: var(--mono); font-size: 0.75rem; color: #ffca64; }
.git-clean { margin: 0; font-size: 0.8rem; color: var(--green); }
.git-commit-form { display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel); }
.git-form-actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.git-submit-button { width: auto; padding: 0 20px; height: 40px; font-size: 0.82rem; }
.git-feedback { font-size: 0.8rem; font-weight: 500; }
.git-feedback.success { color: var(--green); }
.git-feedback.error { color: var(--red); }
.git-history-list { display: flex; flex-direction: column; gap: 8px; max-height: 150px; overflow-y: auto; }
.git-history-item { padding: 8px 12px; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--bg-soft); }
.git-hist-header { display: flex; gap: 10px; font-size: 0.72rem; color: var(--faint); font-family: var(--mono); margin-bottom: 3px; }
.git-hash { color: var(--cyan); font-weight: 600; }
.git-author { color: var(--text); }
.git-hist-msg { margin: 0; font-size: 0.78rem; color: #d0e0ec; }
.git-user-badge { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-radius: 10px; background: rgba(56, 189, 248, 0.08); border: 1px solid rgba(56, 189, 248, 0.25); }
.git-user-badge .user-meta { display: flex; align-items: center; gap: 10px; }
.git-user-badge .user-icon { font-size: 1.2rem; }
.git-user-badge strong { display: block; font-size: 0.85rem; color: #bae6fd; }
.git-user-badge small { color: var(--faint); font-family: var(--mono); font-size: 0.72rem; }
.small-link-btn { background: none; border: 0; color: var(--cyan); font-size: 0.75rem; text-decoration: underline; cursor: pointer; padding: 4px 8px; }
.small-link-btn:hover { color: #fff; }
.git-checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--muted); cursor: pointer; user-select: none; }
.git-checkbox-row input { accent-color: var(--blue); cursor: pointer; }
/* Адаптивные медиа-запросы и жесты вынесены в responsive.css */
