:root {
  color-scheme: light;
  font-family: "Segoe UI", sans-serif;
  background: #f6f7fb;
  color: #1b1f23;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: #f6f7fb;
}

.version-badge {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  color: #f8fafc;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  z-index: 10;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.25);
}

.page {
  max-width: 100%;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  background: white;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.title-group h1 {
  margin: 0;
  font-size: 1.6rem;
}

.title-group p {
  margin: 0.4rem 0 0;
  color: #64748b;
}

.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

#solve-button {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

#solve-button:active {
  transform: translateY(1px);
}

#solve-button.is-loading {
  opacity: 0.8;
}

#solve-button .spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white;
  animation: spin 0.8s linear infinite;
  display: none;
}

#solve-button.is-loading .spinner {
  display: inline-block;
}

#reset-button {
  background: #e2e8f0;
  color: #1f2937;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
}

#reset-button:active {
  transform: translateY(1px);
}

#status {
  padding: 0.6rem 1rem;
  background: #fff5cc;
  border-radius: 999px;
  border: 1px solid #f0d98a;
  font-size: 0.95rem;
}

#status[data-state="error"] {
  background: #ffe4e6;
  border-color: #fda4af;
  color: #9f1239;
}

#status[data-state="success"] {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#status[data-state="warning"] {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 900px) {
  .content-grid {
    grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
    align-items: start;
  }
}

aside {
  background: white;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

aside h2 {
  margin: 0;
  font-size: 1.2rem;
}

#config-form {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.form-section {
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 1rem;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.form-section h3 {
  margin: 0;
  font-size: 1rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #475569;
}

label input,
label select {
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  border: 1px solid #cbd5f5;
  background: white;
  font-size: 0.9rem;
}

label.has-error input,
label.has-error select {
  border-color: #fda4af;
  background: #fff1f2;
}

.field-error {
  min-height: 1em;
  color: #be123c;
  font-size: 0.75rem;
}

.field-error[data-error-for="segments"] {
  margin: 0;
}

label.toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

label.toggle .toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

label.toggle .toggle-hint {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.3;
}

label.toggle input {
  width: auto;
}

.segments-table-wrapper {
  border-radius: 14px;
  border: 1px solid #dbe2f1;
  background: white;
  overflow: auto;
  max-width: 100%;
}

.segments-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.segments-table th,
.segments-table td {
  border: 1px solid #e2e8f0;
  padding: 0.5rem 0.6rem;
  vertical-align: top;
  background: white;
}

.segments-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 2;
}

.segments-table .sticky-col {
  position: sticky;
  left: 0;
  background: #f8fafc;
  z-index: 1;
}

.segments-table .corner-cell {
  z-index: 3;
  min-width: 140px;
  text-align: left;
}

.segments-table .row-label {
  font-weight: 600;
  color: #1e293b;
  min-width: 140px;
}

.segments-table td.is-inactive {
  background: #f1f5f9;
  color: #94a3b8;
}

.segments-table td.is-selected {
  background: #dbeafe;
  box-shadow: inset 0 0 0 2px #2563eb;
}

.segments-table td.is-inactive input,
.segments-table td.is-inactive select {
  background: #e2e8f0;
  color: #94a3b8;
}

.segments-table input,
.segments-table select {
  width: 100%;
  min-width: 6.5rem;
}

.segment-header {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.segment-name-input {
  font-weight: 600;
}

.segment-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

#add-segment,
.segment-action {
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

#add-segment {
  background: #0f766e;
  color: white;
}

.segment-action.insert-segment {
  background: #e2e8f0;
  color: #334155;
}

.segment-action.remove-segment {
  background: #fee2e2;
  color: #b91c1c;
}

.segments-table .toggle {
  justify-content: center;
}

.case-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.case-button {
  background: #e2e8f0;
  border: none;
  border-radius: 999px;
  color: #1f2937;
  cursor: pointer;
  font-weight: 600;
  padding: 0.45rem 1rem;
}

.helper-text {
  margin: 0.5rem 0 0;
  color: #64748b;
  font-size: 0.9rem;
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

main {
  background: white;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.plot-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 700px) {
  .plot-controls {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tab-button {
  border: 1px solid #cbd5f5;
  background: white;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: #334155;
  cursor: pointer;
}

.tab-button.is-active {
  background: #2563eb;
  border-color: #2563eb;
  color: white;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.2);
}

.plot-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.plot-panels {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.plot {
  background: white;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  min-height: 320px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  position: relative;
}

.plot-panel {
  display: none;
  margin-bottom: 0;
  width: 100%;
}

.plot-panel.is-active {
  display: block;
}

.plot-resizer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  cursor: row-resize;
  background: linear-gradient(to bottom, rgba(15, 23, 42, 0), rgba(15, 23, 42, 0.08));
}

.plot-panel.is-resizing {
  user-select: none;
}

#summary {
  background: white;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

#summary .summary-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

#summary .summary-metrics {
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

#summary .summary-metrics div {
  background: #f8fafc;
  border-radius: 12px;
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#summary .summary-metrics dt {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

#summary .summary-metrics dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
}

#summary .summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

#summary .summary-actions button {
  background: #1d4ed8;
  color: white;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
}

#summary .summary-actions button:disabled {
  background: #cbd5f5;
  color: #475569;
}

#summary h2 {
  margin-top: 0;
}

#summary p {
  margin: 0;
  color: #64748b;
}

@media (min-width: 700px) {
  #summary .summary-panel {
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
  }

  #summary .summary-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 1;
  }

  #summary .summary-actions {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
