:root {
  --bg: #e9f1f8;
  --card: #ffffff;
  --ink: #17334f;
  --line: #cedfed;
  --accent: #0e4f95;
  --accent-2: #2f8dd4;
  --brand-dark: #083b83;
  --brand-dark-2: #0a4b9f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #f6fbff 0%, #edf5ff 40%, #f8fafd 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand-dark-2) 100%);
  color: #fff;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 46px;
  height: 46px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  display: grid;
  place-items: center;
}

.logo-mark svg {
  width: 36px;
  height: 36px;
}

.logo-mark circle,
.logo-mark path {
  fill: none;
  stroke: #ffffff;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text {
  display: grid;
  line-height: 1.05;
}

.brand-text strong {
  font-size: 2rem;
  font-weight: 800;
}

.brand-text span {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  opacity: 0.92;
}

.menu {
  display: flex;
  gap: 10px;
}

.menu a {
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.45);
  padding: 6px 10px;
  border-radius: 8px;
}

.menu a:hover {
  background: rgba(255, 255, 255, 0.15);
}

.container {
  max-width: 1400px;
  margin: 14px auto 28px;
  padding: 0 14px;
  display: grid;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 20px rgba(8, 53, 90, 0.08);
  padding: 14px;
}

h1, h2 {
  margin: 0 0 12px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

select[multiple] {
  min-height: 220px;
}

.channels-toolbar {
  display: grid;
  gap: 8px;
}

.channels-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.channels-actions button {
  padding: 8px;
  font-size: 12px;
}

.channels-picker {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7fbff;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #d5e4f2;
  border-radius: 8px;
  background: #ffffff;
  padding: 6px 8px;
  margin: 0;
  font-weight: 500;
}

.channel-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
}

.channel-item:has(input:checked) {
  border-color: #8ab5da;
  background: #eaf4ff;
}

.channel-item.hidden {
  display: none;
}

.actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}

button {
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

button:hover {
  background: var(--accent-2);
}

button.primary {
  margin-top: 10px;
}

.analysis-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
  min-height: calc(100vh - 150px);
}

.controls form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 0;
}

.controls {
  font-size: 13px;
  height: calc(100vh - 160px);
  min-height: calc(100vh - 160px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.controls h2 {
  font-size: 18px;
}

.controls-summary {
  margin: -4px 0 8px;
  font-size: 12px;
  color: #426482;
  font-weight: 600;
}

.controls label {
  font-size: 12px;
  margin-bottom: 4px;
}

.controls input[type="text"],
.controls input[type="number"],
.controls select,
.controls button,
.controls .button-link {
  font-size: 12px;
}

.controls input[type="text"],
.controls input[type="number"],
.controls select {
  padding: 6px 8px;
}

.controls .channels-picker {
  max-height: none;
}

.controls .channel-item {
  font-size: 12px;
}

.controls-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.controls-tab {
  background: #edf4fc;
  color: #1f4f7f;
  border: 1px solid #d0e2f4;
  padding: 8px;
}

.controls-tab:hover {
  background: #e5f0fb;
}

.controls-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.controls-tab-pane {
  display: none;
  gap: 8px;
  min-height: 0;
}

.controls-tab-pane.active {
  display: grid;
}

.controls-tab-pane[data-controls-pane="channels"].active {
  grid-template-rows: auto 1fr;
  flex: 1;
  min-height: 0;
}

.controls-tab-pane[data-controls-pane="channels"] .channels-picker {
  height: 100%;
  min-height: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

.filter-inline-row {
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr);
  gap: 8px;
  align-items: center;
}

.nav-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.plot-card {
  overflow: hidden;
  position: relative;
  min-height: calc(100vh - 160px);
}

.plot-playbar {
  margin-top: 0;
  margin-bottom: 10px;
  border: 1px solid #d7e2ee;
  border-radius: 10px;
  background: #f7fbff;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.nav-toolbar-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid #b8ccdf;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.nav-seg-btn {
  border: 0;
  border-right: 1px solid #cddceb;
  border-radius: 0;
  min-width: 42px;
  height: 34px;
  padding: 0 12px;
  margin: 0;
  background: #ffffff;
  color: #1f4f7f;
  font-weight: 800;
  font-size: 16px;
  line-height: 1;
}

.nav-seg-btn:last-child {
  border-right: 0;
}

.nav-seg-btn:hover {
  background: #e9f3fe;
  color: #0f3e6d;
}

.nav-seg-btn:active {
  background: #dbeeff;
}

.plot-nav-btn {
  padding: 8px 12px;
  font-size: 12px;
  white-space: nowrap;
  margin: 0;
}

.nav-refresh-btn {
  height: 34px;
  padding: 0 12px;
}

.playbar-field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #4a6784;
  margin: 0;
}

.playbar-field input,
.playbar-field select {
  width: 150px;
}

.playbar-slider {
  width: 100%;
  display: grid;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: #385b79;
}

.playbar-slider input[type="range"] {
  width: 100%;
  accent-color: #1f5fa3;
}

.playbar-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #274967;
  margin: 0;
}

.playbar-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.plot-loading {
  position: absolute;
  inset: 56px 14px 14px 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 30;
  font-weight: 600;
  color: #1d4d7c;
}

.plot-loading.active {
  display: flex;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #cfe0f3;
  border-top-color: #1e6db6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.plot-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 11px;
  font-size: 12px;
}

.btn-icon {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.button-link:hover {
  background: var(--accent-2);
}

.marker-form {
  display: grid;
  gap: 8px;
}

.markers-list {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.marker-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #f9fcff;
}

.marker-item span {
  display: block;
  font-size: 12px;
  opacity: 0.85;
}

.danger-btn {
  background: #b65252;
  padding: 8px 10px;
}

.danger-btn:hover {
  background: #d06b6b;
}

.muted {
  font-size: 13px;
  opacity: 0.75;
}

.marker-modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 24, 47, 0.48);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.marker-modal.open {
  display: flex;
}

.marker-modal-card {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.22);
}

.marker-modal-card h3 {
  margin: 0 0 10px;
}

.marker-modal-form {
  display: grid;
  gap: 8px;
}

.modal-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 1px solid #d0d7e2;
}

.modal-tab {
  background: #f2f4f7;
  color: #324255;
  border: 1px solid #d0d7e2;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 12px;
  margin-right: 4px;
}

.modal-tab:hover {
  background: #e8edf3;
}

.modal-tab.active {
  background: #ffffff;
  color: #1f2d3d;
  border-color: #d0d7e2;
  position: relative;
  top: 1px;
}

.modal-tab-pane {
  display: none;
  border: 1px solid #d0d7e2;
  border-top: none;
  padding: 10px;
  border-radius: 0 0 8px 8px;
  background: #ffffff;
}

.modal-tab-pane.active {
  display: block;
}

.info-tabs-card {
  padding-top: 12px;
}

.info-tabs {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  margin-bottom: 0;
  border-bottom: 1px solid #d0d7e2;
}

.info-tab {
  background: #f2f4f7;
  color: #324255;
  border: 1px solid #d0d7e2;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 12px;
  margin-right: 4px;
}

.info-tab:hover {
  background: #e8edf3;
}

.info-tab.active {
  background: #ffffff;
  color: #1f2d3d;
  border-color: #d0d7e2;
  position: relative;
  top: 1px;
}

.info-tab-pane {
  display: none;
  border: 1px solid #d0d7e2;
  border-top: none;
  padding: 10px;
  border-radius: 0 0 8px 8px;
  background: #ffffff;
}

.info-tab-pane.active {
  display: block;
}

.info-tab-pane .markers-list {
  margin-top: 0;
  max-height: 360px;
}

.png-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.png-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fcff;
  padding: 8px;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px;
  align-items: start;
}

.png-thumb-link {
  display: block;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #d8e6f4;
  background: #fff;
}

.png-thumb {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}

.png-meta {
  display: grid;
  gap: 6px;
}

.png-meta span {
  font-size: 13px;
  opacity: 0.88;
}

.png-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.png-actions form {
  margin: 0;
}

.marker-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 1fr));
  gap: 10px;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.stat span {
  display: block;
  font-size: 12px;
  opacity: 0.75;
}

.stat strong {
  font-size: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  border: 1px solid var(--line);
  padding: 6px;
  text-align: left;
  vertical-align: top;
}

thead {
  background: #eef4fb;
}

.flash-wrap {
  max-width: 1400px;
  margin: 12px auto 0;
  padding: 0 14px;
  display: grid;
  gap: 8px;
}

.flash {
  border-radius: 8px;
  padding: 10px;
  border: 1px solid;
  font-weight: 600;
}

.flash.success {
  background: #e9f7ef;
  border-color: #7cc69f;
  color: #155b37;
}

.flash.error {
  background: #fdeced;
  border-color: #e3a0a6;
  color: #7f1d2a;
}

.plot-empty {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  text-align: center;
}

.inline-code-form {
  display: grid;
  grid-template-columns: auto minmax(220px, 320px) auto;
  gap: 10px;
  align-items: end;
}

.code-center-wrap {
  min-height: calc(100vh - 220px);
  display: grid;
  align-items: center;
}

.code-prompt-card {
  width: 66%;
  margin: 0 auto;
}

.inline-code-form label {
  margin: 0;
}

.code-stack-form {
  grid-template-columns: 1fr;
  justify-items: center;
  align-items: center;
  max-width: 420px;
  margin: 0 auto;
}

.code-stack-form label {
  width: 100%;
  text-align: center;
  margin-bottom: 4px;
}

.code-stack-form input[type="text"] {
  width: 100%;
}

.inline-code-form .compact-btn {
  width: auto;
  min-width: 108px;
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
  line-height: 1;
}

.inline-code-form input[type="text"] {
  height: 38px;
  padding: 0 10px;
}

@media (max-width: 1100px) {
  .code-prompt-card {
    width: 100%;
  }

  .code-center-wrap {
    min-height: auto;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-text strong {
    font-size: 1.6rem;
  }

  .analysis-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .controls,
  .plot-card {
    height: auto;
    min-height: auto;
  }

  .filter-inline-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .plot-playbar {
    justify-content: stretch;
  }

  .nav-toolbar-group {
    width: 100%;
  }

  .nav-seg-btn {
    flex: 1;
  }

  .playbar-field input,
  .playbar-field select {
    width: 100%;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .grid-form {
    grid-template-columns: 1fr;
  }

  .info-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    border-bottom: none;
    margin-bottom: 8px;
  }

  .info-tab {
    margin-right: 0;
    border-bottom: 1px solid #d0d7e2;
    border-radius: 8px;
  }

  .info-tab.active {
    top: 0;
  }

  .png-item {
    grid-template-columns: 1fr;
  }

  .png-thumb {
    height: 180px;
  }
}
