:root {
  color-scheme: dark;
  --bg: #07090b;
  --surface: #0d1114;
  --surface-2: #10161a;
  --ink: #f2efe7;
  --soft: #d3d0c8;
  --muted: #8e969b;
  --faint: #5f686d;
  --line: rgba(242, 239, 231, 0.1);
  --line-strong: rgba(242, 239, 231, 0.18);
  --green: #35d07f;
  --green-soft: #9df2bf;
  --amber: #ffb04a;
  --red: #ff6f61;
  --blue: #8aa8ff;
  --display: "Space Grotesk", "Pretendard Variable", Pretendard, "Segoe UI", sans-serif;
  --sans: "Pretendard Variable", Pretendard, "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(242, 239, 231, 0.028) 1px, transparent 1px),
    linear-gradient(rgba(242, 239, 231, 0.028) 1px, transparent 1px),
    linear-gradient(135deg, rgba(53, 208, 127, 0.12), transparent 460px),
    linear-gradient(230deg, rgba(138, 168, 255, 0.075), transparent 520px),
    #07090b;
  background-size: 64px 64px, 64px 64px, auto, auto, auto;
}

a {
  color: inherit;
  text-decoration: none;
}

.terminal-shell {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 18px;
  width: min(1500px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0;
}

.side-rail {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  background: rgba(13, 17, 20, 0.72);
}

.side-rail span,
.mark,
.kicker,
.session-state span,
.metric span,
.metric em,
.panel-head span,
.range-tabs,
.table-head,
.table-note,
.row b,
.log-stream time,
.log-stream span,
.rationale-list span {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
}

.side-rail span,
.mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  color: var(--faint);
}

.mark {
  color: var(--green-soft);
  font-weight: 700;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 58px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--green);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: var(--display);
  font-size: 34px;
  font-weight: 650;
  line-height: 1;
}

.session-state {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.session-state span {
  color: var(--faint);
}

.session-state strong {
  color: var(--amber);
  font-family: var(--display);
  font-size: 18px;
}

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

.metric,
.panel {
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(242, 239, 231, 0.035), transparent 52%),
    rgba(13, 17, 20, 0.82);
  box-shadow: 0 20px 58px rgba(0, 0, 0, 0.26);
}

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

.metric span,
.metric em,
.panel-head span,
.table-note,
.table-head,
.log-stream time,
.rationale-list span {
  color: var(--faint);
}

.metric strong {
  display: block;
  margin: 14px 0 7px;
  color: var(--soft);
  font-family: var(--display);
  font-size: 28px;
  line-height: 1;
}

.metric:first-child strong {
  color: var(--green-soft);
}

.metric.danger strong {
  color: var(--red);
}

.metric em {
  font-style: normal;
}

.main-grid {
  display: block;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.log-panel {
  display: grid;
  grid-template-rows: auto 1fr;
}

.panel-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact {
  min-height: 56px;
}

h2 {
  margin-bottom: 0;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 620;
  line-height: 1;
}

.range-tabs {
  display: flex;
  gap: 6px;
  color: var(--faint);
}

.range-tabs span,
.range-tabs strong {
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 24px;
  border: 1px solid var(--line);
  font-weight: 600;
}

.range-tabs strong {
  color: var(--green-soft);
  background: rgba(53, 208, 127, 0.08);
}

.chart-stage {
  min-height: 256px;
  padding: 14px 18px 10px;
  background:
    linear-gradient(rgba(242, 239, 231, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(242, 239, 231, 0.055) 1px, transparent 1px);
  background-size: 48px 48px;
}

.chart-stage svg {
  display: block;
  width: 100%;
  height: 220px;
}

.area {
  fill: url("#signalFill");
}

.line {
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
  filter: drop-shadow(0 0 10px rgba(53, 208, 127, 0.18));
}

.health-list {
  display: grid;
  padding: 12px 16px 16px;
}

.health-list p {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 38px;
  margin: 0;
  border-bottom: 1px solid var(--line);
  color: var(--soft);
  font-size: 14px;
}

.health-list p:last-child {
  border-bottom: 0;
}

.health-list p span {
  width: 7px;
  height: 7px;
  background: var(--green);
  box-shadow: 0 0 16px rgba(53, 208, 127, 0.4);
}

.health-list strong {
  color: var(--green-soft);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
}

.positions-table {
  display: grid;
}

.table-head,
.row {
  display: grid;
  grid-template-columns: 140px 70px minmax(0, 1fr) 130px 100px 90px;
  gap: 14px;
  align-items: center;
  min-height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.table-head {
  min-height: 34px;
}

.row:last-child {
  border-bottom: 0;
}

.row strong {
  color: var(--green);
  font-family: var(--mono);
  font-size: 14px;
}

.row span,
.row em {
  color: var(--soft);
  font-size: 14px;
  font-style: normal;
  overflow-wrap: anywhere;
}

.row em {
  color: var(--muted);
}

.row b {
  justify-self: end;
  color: var(--green-soft);
}

.positive {
  color: var(--green-soft) !important;
}

.warning,
.row.blocked strong,
.row.blocked b {
  color: var(--amber) !important;
}

.rationale-list {
  display: grid;
}

.rationale-list article {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.rationale-list article:last-child {
  border-bottom: 0;
}

.rationale-list p {
  margin-bottom: 0;
  color: var(--soft);
  font-size: 14px;
  line-height: 1.55;
  word-break: keep-all;
}

.log-stream {
  display: grid;
  align-content: start;
  min-height: 100%;
  padding: 10px 14px;
  background:
    linear-gradient(rgba(53, 208, 127, 0.075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(53, 208, 127, 0.075) 1px, transparent 1px),
    rgba(7, 9, 11, 0.5);
  background-size: 18px 18px;
}

.log-stream p {
  display: grid;
  grid-template-columns: 72px 52px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  margin: 0;
  padding: 11px 0;
  border-bottom: 1px solid rgba(242, 239, 231, 0.075);
  color: var(--soft);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.log-stream span {
  color: var(--muted);
  font-weight: 700;
}

.log-stream .ok {
  color: var(--green);
}

.log-stream .warn {
  color: var(--amber);
}

@media (max-width: 1120px) {
  .terminal-shell {
    grid-template-columns: 1fr;
  }

  .side-rail {
    display: none;
  }
}

@media (max-width: 760px) {
  .terminal-shell {
    width: min(100% - 22px, 1500px);
  }

  .topbar,
  .metrics {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 12px;
  }

  .session-state {
    justify-items: start;
  }

  .metrics {
    display: grid;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .table-head {
    display: none;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 6px;
    min-height: auto;
    padding: 14px 16px;
  }

  .row b {
    justify-self: start;
  }

  .log-stream p {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* --- Added Widget Styling (CORS API, Tabs & Settings Modal) --- */

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.tab-selector {
  display: flex;
  border: 1px solid var(--line);
  background: rgba(13, 17, 20, 0.4);
  padding: 2px;
  border-radius: 3px;
}

.tab-btn {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
  padding: 6px 12px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  border-radius: 2px;
}

.tab-btn:hover {
  color: var(--soft);
}

.tab-btn.active {
  color: var(--bg);
  background: var(--green);
  box-shadow: 0 0 12px rgba(53, 208, 127, 0.25);
}

.settings-trigger-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s ease;
}

.settings-trigger-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(242, 239, 231, 0.05);
}

/* Status Dot indicator */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 10px var(--red);
}

#api-status-badge {
  font-family: var(--mono);
  font-size: 10px;
  margin-right: 10px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* Display and hide tabs content */
.metrics {
  display: none !important;
}

.metrics.active {
  display: grid !important;
}

.left-column.hidden {
  display: none !important;
}

/* Parameters Panel Styling */
.params-panel {
  grid-area: auto;
}

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

.param-card {
  border: 1px solid var(--line);
  background: rgba(7, 9, 11, 0.3);
  padding: 10px 12px;
  border-radius: 3px;
}

.param-card span {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}

.param-card strong {
  display: block;
  font-family: var(--display);
  font-size: 18px;
  color: var(--ink);
  line-height: 1.1;
  margin-bottom: 4px;
}

.param-card em {
  display: block;
  font-size: 11px;
  font-style: normal;
  color: var(--muted);
}

/* Modal Overlay and Window */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(7, 9, 11, 0.85);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

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

.modal-header h2 {
  font-family: var(--display);
  font-size: 18px;
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

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

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
  background: rgba(7, 9, 11, 0.5);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 3px;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--green);
}

.form-help {
  font-size: 11px;
  color: var(--faint);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  background: rgba(7, 9, 11, 0.2);
  border-top: 1px solid var(--line);
}

.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 3px;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: none;
  border: 1px solid var(--line);
  color: var(--soft);
}

.btn-secondary:hover {
  background: rgba(242, 239, 231, 0.05);
  color: var(--ink);
}

.btn-primary {
  background: var(--green);
  color: var(--bg);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--green-soft);
  box-shadow: 0 0 12px rgba(53, 208, 127, 0.3);
}

/* Beautiful dark scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--faint);
}

/* Responsive adjustment for params and controls */
@media (max-width: 760px) {
  .topbar-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 10px;
    margin-top: 12px;
  }
  
  .tab-selector {
    justify-content: center;
  }
  
  .params-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Stale data visual indicators */
.main-grid.stale-active,
.metrics.stale-active {
  opacity: 0.55;
  pointer-events: none;
  filter: grayscale(0.2);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

@keyframes staleBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.stale-blink {
  animation: staleBlink 1.5s infinite;
}

