.vcalc-page {
  padding-bottom: 2rem;
}

.dark .vcalc-page {
  color: var(--color-zinc-200);
}

.vcalc-container {
  max-width: 120ch;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.25rem;
}

.vcalc-section {
  min-width: 0;
  background: color-mix(in oklab, var(--color-zinc-50) 92%, white);
  border: 1px solid color-mix(in oklab, var(--color-zinc-300) 65%, transparent);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: 0 2px 10px color-mix(in oklab, var(--color-zinc-400) 10%, transparent);
}

.dark .vcalc-section {
  background: color-mix(in oklab, var(--color-zinc-900) 92%, black);
  border-color: color-mix(in oklab, var(--color-zinc-700) 70%, transparent);
  box-shadow: none;
}

.vcalc-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.vcalc-section h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1.1rem 0 0.6rem;
}

.vcalc-rich-text p + p,
.vcalc-section p + p {
  margin-top: 0.6rem;
}

.vcalc-note {
  border-left: 4px solid var(--color-primary-500);
  padding-left: 0.75rem;
  font-weight: 500;
}

.vcalc-muted {
  color: color-mix(in oklab, var(--color-zinc-700) 82%, transparent);
  font-size: 0.95rem;
}

.dark .vcalc-muted {
  color: color-mix(in oklab, var(--color-zinc-300) 75%, transparent);
}

.vcalc-formula {
  overflow-x: auto;
  padding: 0.35rem 0;
}

/* KaTeX visibility override: prefer MathML rendering over HTML rendering in calculator scope. */
.vcalc-page .katex {
  position: relative;
}

.vcalc-page .katex .katex-html {
  display: none !important;
}

.vcalc-page .katex .katex-mathml {
  position: static !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

.vcalc-figure {
  margin: 1rem 0;
  padding: 0.9rem;
  border: 1px solid color-mix(in oklab, var(--color-zinc-300) 65%, transparent);
  border-radius: 0.7rem;
  background: color-mix(in oklab, white 80%, var(--color-primary-50));
}

.dark .vcalc-figure {
  border-color: color-mix(in oklab, var(--color-zinc-300) 65%, transparent);
  background: #ffffff;
  color: var(--color-zinc-800);
}

.vcalc-figure-image {
  width: 100%;
  height: auto;
  display: block;
  background: #ffffff;
  color-scheme: light;
}

.vcalc-figure figcaption {
  margin-top: 0.65rem;
  font-size: 0.9rem;
  color: color-mix(in oklab, var(--color-zinc-700) 82%, transparent);
}

.dark .vcalc-figure figcaption {
  color: color-mix(in oklab, var(--color-zinc-700) 82%, transparent);
}

.vcalc-sketch-placeholder {
  border: 2px dashed color-mix(in oklab, var(--color-primary-500) 40%, var(--color-zinc-500));
  border-radius: 0.7rem;
  min-height: 10rem;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  background: linear-gradient(135deg, color-mix(in oklab, var(--color-primary-100) 55%, transparent), transparent);
}

.dark .vcalc-sketch-placeholder {
  background: #ffffff;
  color: var(--color-zinc-800);
}

.vcalc-inline-form,
.vcalc-settings-grid {
  display: grid;
  gap: 0.75rem;
}

.vcalc-inline-form {
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  align-items: end;
  margin-bottom: 0.8rem;
}

.vcalc-settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.vcalc-inline-form label,
.vcalc-settings-grid label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.vcalc-label-text {
  display: block;
}

.vcalc-input {
  border: 1px solid color-mix(in oklab, var(--color-zinc-400) 55%, transparent);
  border-radius: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: white;
  color: var(--color-zinc-900);
}

.dark .vcalc-input {
  background: color-mix(in oklab, var(--color-zinc-900) 85%, black);
  color: var(--color-zinc-100);
  border-color: color-mix(in oklab, var(--color-zinc-600) 65%, transparent);
}

.vcalc-input:focus {
  outline: 2px solid color-mix(in oklab, var(--color-primary-500) 60%, transparent);
  outline-offset: 1px;
}

.vcalc-input-select {
  width: 100%;
}

.vcalc-input--compact {
  min-width: 0;
  width: 4rem;
  padding: 0.32rem 0.45rem;
}

.vcalc-line-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.vcalc-unit-field {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  flex: 0 0 auto;
  border: 1px solid color-mix(in oklab, var(--color-zinc-400) 55%, transparent);
  border-radius: 0.5rem;
  overflow: hidden;
  background: white;
}

.dark .vcalc-unit-field {
  background: color-mix(in oklab, var(--color-zinc-900) 85%, black);
  border-color: color-mix(in oklab, var(--color-zinc-600) 65%, transparent);
}

.vcalc-unit-field .vcalc-input {
  border: 0;
  border-radius: 0;
  width: 4rem;
  min-height: 2rem;
}

.vcalc-unit-field .vcalc-input:focus {
  outline: none;
}

.vcalc-unit-field:focus-within {
  outline: 2px solid color-mix(in oklab, var(--color-primary-500) 60%, transparent);
  outline-offset: 1px;
}

.vcalc-unit-suffix {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  min-width: 1.75rem;
  padding: 0 0.3rem;
  border-left: 1px solid color-mix(in oklab, var(--color-zinc-300) 75%, transparent);
  background: transparent;
  color: color-mix(in oklab, var(--color-zinc-700) 85%, transparent);
  font-size: 0.8rem;
  white-space: nowrap;
}

.dark .vcalc-unit-suffix {
  border-left-color: color-mix(in oklab, var(--color-zinc-700) 75%, transparent);
  background: transparent;
  color: color-mix(in oklab, var(--color-zinc-300) 80%, transparent);
}

.vcalc-icon-btn {
  min-width: 2rem;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.vcalc-input:disabled {
  background: #e5e7eb;
  color: color-mix(in oklab, var(--color-zinc-700) 85%, transparent);
  border-color: color-mix(in oklab, var(--color-zinc-400) 80%, transparent);
  cursor: not-allowed;
}

.dark .vcalc-input:disabled {
  background: color-mix(in oklab, var(--color-zinc-800) 92%, black);
  color: color-mix(in oklab, var(--color-zinc-300) 80%, transparent);
  border-color: color-mix(in oklab, var(--color-zinc-600) 80%, transparent);
}

@media (max-width: 1024px) {
  .vcalc-settings-grid {
    grid-template-columns: 1fr;
  }

  .vcalc-table-wrap {
    overflow-x: hidden;
  }

  .vcalc-results-wrap {
    overflow: visible;
  }

  .vcalc-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    display: block;
  }

  .vcalc-table thead {
    display: none;
  }

  .vcalc-table tbody {
    display: block;
    width: 100%;
  }

  .vcalc-table tr {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0.5rem 0;
    border-bottom: 1px solid color-mix(in oklab, var(--color-zinc-300) 65%, transparent);
  }

  .dark .vcalc-table tr {
    border-bottom-color: color-mix(in oklab, var(--color-zinc-700) 75%, transparent);
  }

  .vcalc-table tr:last-child {
    border-bottom: 0;
  }

  .vcalc-table td {
    display: grid;
    grid-template-columns: fit-content(8rem) minmax(0, 1fr);
    gap: 0.3rem;
    align-items: start;
    padding: 0.18rem 0;
    border-bottom: 0;
    width: 100%;
    min-width: 0;
  }

  .vcalc-table td[data-label='Aktion'],
  .vcalc-table td[data-label='Verschieben'],
  .vcalc-table td[data-label='Löschen'],
  .vcalc-table td[data-label='Status'] {
    grid-template-columns: fit-content(8rem) minmax(0, 1fr);
  }

  .vcalc-table td::before {
    content: attr(data-label);
    font-size: 0.78rem;
    font-weight: 700;
    color: color-mix(in oklab, var(--color-zinc-700) 85%, transparent);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: 0.2rem;
  }

  .dark .vcalc-table td::before {
    color: color-mix(in oklab, var(--color-zinc-300) 80%, transparent);
  }

  .vcalc-table td > .vcalc-btn {
    justify-self: start;
    width: fit-content;
    max-width: 100%;
  }

  .vcalc-table td > * {
    min-width: 0;
  }

  .vcalc-table .vcalc-input-select {
    min-width: 0;
    width: 100%;
  }

  .vcalc-table .vcalc-line-fields {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.2rem;
  }

  .vcalc-table .vcalc-input--compact {
    width: 3.4rem;
  }

  .vcalc-table .vcalc-unit-field .vcalc-input {
    width: 3.4rem;
  }

  .vcalc-table .vcalc-unit-suffix {
    min-width: 0;
    padding: 0 0.2rem;
  }

  .vcalc-table .vcalc-move-buttons {
    gap: 0.2rem;
  }

  .vcalc-table .vcalc-icon-btn {
    min-width: 0;
    min-height: 1.7rem;
    padding: 0.15rem 0.3rem;
  }

  [data-topology-form] .vcalc-topology-row {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr) auto auto;
    grid-template-areas:
      "position device device device"
      ". line move delete";
    gap: 0.3rem;
    align-items: center;
    border-bottom: 1px solid color-mix(in oklab, var(--color-zinc-300) 65%, transparent);
    padding: 0.5rem 0;
  }

  .dark [data-topology-form] .vcalc-topology-row {
    border-bottom-color: color-mix(in oklab, var(--color-zinc-700) 75%, transparent);
  }

  [data-topology-form] .vcalc-topology-row:last-child {
    border-bottom: 0;
  }

  [data-topology-form] .vcalc-topology-row > td {
    display: block;
    width: auto;
    padding: 0;
    border-bottom: 0;
  }

  [data-topology-form] .vcalc-topology-row td::before {
    content: none;
  }

  [data-topology-form] .vcalc-topology-position-cell {
    grid-area: position;
  }

  [data-topology-form] .vcalc-topology-device-cell {
    grid-area: device;
    min-width: 0;
  }

  [data-topology-form] .vcalc-topology-move-cell {
    grid-area: move;
    justify-self: end;
  }

  [data-topology-form] .vcalc-topology-delete-cell {
    grid-area: delete;
    justify-self: end;
  }

  [data-topology-form] .vcalc-topology-line-cell {
    grid-area: line;
    min-width: 0;
  }

  [data-topology-form] .vcalc-topology-row .vcalc-icon-btn {
    min-width: 2rem;
    min-height: 2rem;
    padding: 0.25rem 0.45rem;
  }

  [data-device-table-body] tr.vcalc-device-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "name power action";
    align-items: center;
    gap: 0.3rem 0.5rem;
  }

  [data-device-table-body] tr.vcalc-device-row td {
    display: block;
    width: auto;
    padding: 0;
    min-width: 0;
    border-bottom: 0;
  }

  [data-device-table-body] tr.vcalc-device-row td::before {
    content: none;
  }

  [data-device-table-body] tr.vcalc-device-row td:nth-child(1) {
    grid-area: name;
  }

  [data-device-table-body] tr.vcalc-device-row td:nth-child(2) {
    grid-area: power;
    justify-self: end;
  }

  [data-device-table-body] tr.vcalc-device-row td:nth-child(3) {
    grid-area: action;
    justify-self: end;
  }

  [data-result-table-body] tr.vcalc-result-row {
    display: grid;
    grid-template-columns: 1.9rem minmax(0, 1fr) auto auto;
    grid-template-areas:
      "position consumer supply status"
      ". dropv droppercent .";
    align-items: start;
    gap: 0.3rem 0.5rem;
  }

  [data-result-table-body] tr.vcalc-result-row td {
    display: block;
    width: auto;
    padding: 0;
    min-width: 0;
    border-bottom: 0;
  }

  [data-result-table-body] tr.vcalc-result-row td::before {
    content: none;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(1) {
    grid-area: position;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(2) {
    grid-area: consumer;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(3) {
    grid-area: supply;
    font-size: 0.9rem;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(4) {
    grid-area: dropv;
    font-size: 0.9rem;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(5) {
    grid-area: droppercent;
    justify-self: start;
    font-size: 0.9rem;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(6) {
    grid-area: status;
    justify-self: end;
  }

  [data-result-table-body] tr.vcalc-result-row td:nth-child(3)::before,
  [data-result-table-body] tr.vcalc-result-row td:nth-child(4)::before,
  [data-result-table-body] tr.vcalc-result-row td:nth-child(5)::before {
    display: inline;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: color-mix(in oklab, var(--color-zinc-700) 85%, transparent);
    margin-right: 0.25rem;
  }

  .dark [data-result-table-body] tr.vcalc-result-row td:nth-child(3)::before,
  .dark [data-result-table-body] tr.vcalc-result-row td:nth-child(4)::before,
  .dark [data-result-table-body] tr.vcalc-result-row td:nth-child(5)::before {
    color: color-mix(in oklab, var(--color-zinc-300) 80%, transparent);
  }

  [data-result-table-body] tr.vcalc-result-row:first-child .vcalc-tooltip-anchor::after {
    top: calc(100% + 0.45rem);
    bottom: auto;
  }

  [data-result-table-body] tr.vcalc-result-row:first-child .vcalc-tooltip-anchor::before {
    top: calc(100% + 0.15rem);
    bottom: auto;
    border-width: 0 0.35rem 0.35rem;
    border-color: transparent transparent rgba(24, 24, 27, 0.96);
  }
}

.vcalc-actions {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.vcalc-btn {
  border: 1px solid var(--color-primary-600);
  background: var(--color-primary-600);
  color: white;
  border-radius: 0.5rem;
  padding: 0.45rem 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.vcalc-btn:hover {
  background: var(--color-primary-700);
}

.vcalc-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.vcalc-btn-ghost {
  background: transparent;
  color: var(--color-primary-700);
}

.dark .vcalc-btn-ghost {
  color: var(--color-primary-300);
}

.vcalc-btn-danger {
  border-color: #b91c1c;
  background: #b91c1c;
}

.vcalc-btn-danger:hover {
  background: #991b1b;
}

.vcalc-table-wrap {
  overflow-x: hidden;
}

.vcalc-results-wrap {
  overflow-x: hidden;
  overflow-y: visible;
}

.vcalc-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
}

.vcalc-results-table {
  min-width: 0;
}

.vcalc-table th,
.vcalc-table td {
  text-align: left;
  vertical-align: middle;
  padding: 0.55rem;
  border-bottom: 1px solid color-mix(in oklab, var(--color-zinc-300) 65%, transparent);
}

.dark .vcalc-table th,
.dark .vcalc-table td {
  border-bottom-color: color-mix(in oklab, var(--color-zinc-700) 75%, transparent);
}

.vcalc-table th {
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vcalc-result-row:hover,
.vcalc-result-row:focus-within {
  background: color-mix(in oklab, var(--color-primary-50) 60%, transparent);
}

.dark .vcalc-result-row:hover,
.dark .vcalc-result-row:focus-within {
  background: color-mix(in oklab, var(--color-primary-900) 35%, transparent);
}

.vcalc-tooltip-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.vcalc-tooltip-anchor::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.45rem);
  transform: translateX(-50%);
  min-width: 14rem;
  max-width: 20rem;
  padding: 0.45rem 0.6rem;
  border-radius: 0.5rem;
  background: rgba(24, 24, 27, 0.96);
  color: #fafafa;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
  text-align: left;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 20;
}

.vcalc-tooltip-anchor::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.15rem);
  transform: translateX(-50%);
  border-width: 0.35rem 0.35rem 0;
  border-style: solid;
  border-color: rgba(24, 24, 27, 0.96) transparent transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 20;
}

.vcalc-result-row:hover .vcalc-tooltip-anchor::after,
.vcalc-result-row:hover .vcalc-tooltip-anchor::before,
.vcalc-tooltip-anchor:focus-visible::after,
.vcalc-tooltip-anchor:focus-visible::before {
  opacity: 1;
}

.vcalc-tooltip-anchor:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--color-primary-500) 70%, transparent);
  outline-offset: 2px;
  border-radius: 0.35rem;
}

.vcalc-tooltip-anchor-left::after {
  transform: translateX(-120%);
}

.vcalc-tooltip-anchor-left::before {
  transform: translateX(-120%);
}

.vcalc-move-buttons {
  display: flex;
  gap: 0.35rem;
}

.vcalc-details summary {
  cursor: pointer;
  font-weight: 700;
  margin-bottom: 0.85rem;
}

.vcalc-error {
  margin-top: 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #dc2626;
  background: #fef2f2;
  color: #991b1b;
  padding: 0.6rem 0.7rem;
  font-weight: 600;
}

.dark .vcalc-error {
  background: color-mix(in oklab, #7f1d1d 45%, black);
  color: #fecaca;
}

.vcalc-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.5rem;
}

.vcalc-overview-grid div {
  border: 1px solid color-mix(in oklab, var(--color-zinc-300) 70%, transparent);
  border-radius: 0.6rem;
  padding: 0.7rem;
  display: grid;
  gap: 0.3rem;
}

.dark .vcalc-overview-grid div {
  border-color: color-mix(in oklab, var(--color-zinc-700) 70%, transparent);
}

.vcalc-overview-grid span {
  font-size: 0.85rem;
  color: color-mix(in oklab, var(--color-zinc-700) 85%, transparent);
}

.dark .vcalc-overview-grid span {
  color: color-mix(in oklab, var(--color-zinc-300) 75%, transparent);
}

.vcalc-overview-grid strong {
  font-size: 1rem;
}

.vcalc-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.vcalc-status-ok {
  background: #dcfce7;
  color: #166534;
}

.vcalc-status-warning {
  background: #fef3c7;
  color: #92400e;
}

.vcalc-status-critical {
  background: #fee2e2;
  color: #991b1b;
}

.dark .vcalc-status-ok {
  background: color-mix(in oklab, #166534 55%, black);
  color: #bbf7d0;
}

.dark .vcalc-status-warning {
  background: color-mix(in oklab, #92400e 55%, black);
  color: #fde68a;
}

.dark .vcalc-status-critical {
  background: color-mix(in oklab, #991b1b 55%, black);
  color: #fecaca;
}

.vcalc-warnings {
  padding-left: 1.2rem;
  display: grid;
  gap: 0.35rem;
}

@media (max-width: 480px) {
  .vcalc-container {
    padding: 0.75rem;
  }

  .vcalc-section {
    padding: 0.8rem;
  }

  .vcalc-table td {
    grid-template-columns: fit-content(7rem) minmax(0, 1fr);
  }
}
