:root {
  color-scheme: dark;
  --bg: #071014;
  --panel: #0d171b;
  --panel-soft: #101f24;
  --line: #1d343c;
  --text: #e6f4ef;
  --muted: #8ea6a0;
  --green: #30e39b;
  --cyan: #35c7e8;
  --red: #ff5d73;
  --amber: #f3bf4c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 20, 0.92);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(48, 227, 155, 0.45);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--red);
  box-shadow: 0 0 12px currentColor;
}

.status.live .dot {
  background: var(--green);
}

.status.demo .dot {
  background: var(--amber);
}

main {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}

.controls {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.field {
  display: grid;
  gap: 7px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select,
button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 12px;
}

button {
  cursor: pointer;
  font-weight: 800;
}

button.primary {
  background: var(--green);
  color: #06120e;
  border-color: var(--green);
}

button.danger {
  border-color: rgba(255, 93, 115, 0.5);
  color: #ffd9df;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
  cursor: pointer;
}

#thresholdValue {
  color: var(--green);
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  padding: 14px;
  min-height: 98px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
}

.metric small {
  display: block;
  color: var(--muted);
  margin-top: 8px;
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
  font-size: 12px;
}

.dashboard {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.chart-panel {
  padding: 14px;
  min-height: 390px;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr);
  gap: 12px;
  position: relative; /* Setup relative bounds for overlays */
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

canvas {
  width: 100%;
  height: 100%;
  min-height: 260px;
  display: block;
  border-radius: 8px;
  background: #061014;
  border: 1px solid rgba(53, 199, 232, 0.12);
}

.readouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
  font-size: 13px;
}

td {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

td:first-child {
  color: var(--muted);
}

td:last-child {
  text-align: right;
  color: var(--text);
}

.log {
  height: 180px;
  overflow: auto;
  padding: 12px;
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
}

@media (max-width: 920px) {
  main {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .readouts {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .readouts {
    grid-template-columns: 1fr;
  }
}

/* Cloud Sync & Settings Styles */
.header-status-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.status.clickable {
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.status.clickable:hover {
  background: var(--panel-soft);
  border-color: var(--cyan);
}

.status.sync-local .dot {
  background: var(--muted);
}

.status.sync-offline .dot {
  background: var(--red);
}

.status.sync-syncing .dot {
  background: var(--cyan);
  animation: pulse-sync 1.5s infinite ease-in-out;
}

.status.sync-cloud .dot {
  background: var(--green);
}

.status.sync-error .dot {
  background: var(--red);
}

@keyframes pulse-sync {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* Modal Overlay and Content */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.25s ease;
}

.modal-content {
  width: min(440px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  animation: modal-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes modal-enter {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.modal-header h3 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
}

.close-btn:hover {
  color: var(--text);
}

.modal-body {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.modal-body input {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 12px;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-body input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(53, 199, 232, 0.15);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 10px;
}

.modal-actions button {
  min-height: 38px;
  padding: 0 16px;
}

/* Tabs Panel, Navigation Buttons, Content Containers */
.tabs-panel {
  display: flex;
  flex-direction: column;
  height: 250px;
  overflow: hidden;
}

.tabs-header {
  display: flex;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  min-height: 40px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.tab-btn:hover {
  background: rgba(29, 52, 60, 0.15);
  color: var(--text);
}

.tab-btn.active {
  background: var(--panel);
  color: var(--cyan);
  border-bottom-color: var(--cyan);
}

.tab-content {
  flex: 1;
  overflow-y: auto;
}

.history-list-wrapper {
  padding: 10px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.history-item:hover {
  border-color: var(--cyan);
  background: rgba(53, 199, 232, 0.05);
}

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.history-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-subtitle {
  font-size: 10.5px;
  color: var(--muted);
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-metrics {
  display: flex;
  gap: 14px;
  flex-shrink: 0;
}

.history-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.history-stat-label {
  font-size: 9px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.03em;
}

.history-stat-val {
  font-size: 12.5px;
  font-weight: 700;
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
}

.history-stat-val.stability {
  color: var(--green);
}

.history-stat-val.peak {
  color: var(--amber);
}

/* Trace Review Mode Overlay Banner */
.review-overlay {
  position: absolute;
  top: 55px;
  left: 14px;
  right: 14px;
  background: rgba(13, 23, 27, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--cyan);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 5;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  animation: banner-enter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes banner-enter {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.review-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.review-details strong {
  font-size: 12px;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.review-details span {
  font-size: 11px;
  color: var(--text);
  font-family: "JetBrains Mono", Consolas, ui-monospace, monospace;
}

/* Chart View Toggles */
.chart-toggles {
  display: flex;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  padding: 2px;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 0 12px;
  min-height: 26px;
  height: 26px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.toggle-btn:hover {
  color: var(--text);
}

.toggle-btn.active {
  background: var(--cyan);
  color: #071014;
}


