:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --text: #c9d1d9;
  --muted: #8b949e;
  --border: #30363d;
  --brand: #58a6ff;
  --green: #3fb950;
  --yellow: #ffa657;
  --red: #f85149;
  --blue: #58a6ff;
  --shadow: rgba(0, 0, 0, 0.3);
}

body.light-theme {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #edf2f9;
  --text: #132238;
  --muted: #5c6b7d;
  --border: #d4dce8;
  --brand: #1463d5;
  --green: #198c3f;
  --yellow: #a66505;
  --red: #c0291f;
  --blue: #1463d5;
  --shadow: rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans", sans-serif;
}

a {
  color: var(--brand);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-container {
  width: min(92vw, 420px);
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 50px var(--shadow);
  padding: 28px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.auth-subtitle {
  color: var(--muted);
  margin: 0 0 20px;
}

label {
  display: block;
  margin: 12px 0 6px;
  font-size: 0.92rem;
}

input,
select,
button {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
}

button {
  cursor: pointer;
  background: var(--brand);
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
  margin-top: 16px;
}

button:hover {
  filter: brightness(1.06);
}

.auth-error {
  min-height: 20px;
  color: var(--red);
  margin: 12px 0 0;
}

.shake {
  animation: shake 0.35s linear;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-7px); }
  100% { transform: translateX(0); }
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.top-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 700;
}

.top-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.small-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.input-compact {
  width: auto;
  min-width: 150px;
  padding: 8px 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.running {
  background: var(--green);
}

.status-dot.idle {
  background: var(--yellow);
}

.status-dot.stopped {
  background: var(--red);
}

.status-text,
.last-active {
  font-size: 0.86rem;
  color: var(--muted);
}

.ghost-button,
.danger-button {
  width: auto;
  margin-top: 0;
}

.ghost-button {
  background: transparent;
  border: 1px solid var(--border);
}

.danger-button {
  background: #8b1f1f;
}

.dashboard-main {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.stat-card h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.stat-value {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
}

.stat-green { color: var(--green); }
.stat-blue { color: var(--blue); }
.stat-yellow { color: var(--yellow); }

.main-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
}

.left-column,
.right-column {
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.02rem;
}

.panel h3 {
  margin: 10px 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.panel-header {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
}

canvas {
  width: 100% !important;
  min-height: 260px;
  max-height: 420px;
}

#reward-chart,
#score-hist-chart {
  min-height: 150px;
  max-height: 180px;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.health-grid div {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.health-grid span {
  color: var(--muted);
  font-size: 0.85rem;
}

.health-grid strong {
  font-size: 1rem;
}

.json-box {
  margin-top: 12px;
}

.json-box pre {
  margin: 0;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 180px;
  overflow: auto;
  font-size: 0.8rem;
}

.table-wrap {
  overflow: auto;
  max-height: 480px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover {
  background: var(--panel-2);
}

.full-width {
  width: 100%;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  padding: 3px 8px;
  font-weight: 600;
}

.badge-high {
  background: #1a4731;
  color: #3fb950;
}

.badge-mid {
  background: #3d2e00;
  color: #ffa657;
}

.badge-low {
  background: #21262d;
  color: #8b949e;
}

.expr-code {
  font-family: Consolas, Monaco, monospace;
  font-size: 0.8rem;
}

.description-text {
  font-style: italic;
  color: var(--muted);
}

.filters-grid {
  margin-top: 10px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.filters-grid button {
  margin-top: 0;
}

.export-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.export-actions button {
  width: auto;
  margin-top: 0;
}

#last-export {
  color: var(--muted);
  font-size: 0.85rem;
}

.command-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.command-tab {
  width: auto;
  margin-top: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.command-tab.active {
  border-color: var(--brand);
  color: #ffffff;
  background: var(--brand);
}

.command-list {
  display: grid;
  gap: 10px;
}

.command-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px;
}

.command-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.command-head h4 {
  margin: 0;
}

.command-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.copy-button {
  width: auto;
  margin-top: 0;
  padding: 6px 10px;
  font-size: 0.82rem;
  background: #29426a;
}

.command-card pre {
  margin: 8px 0 0;
  background: #161b22;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  overflow: auto;
  color: #c9d1d9;
}

.page-footer {
  margin: 20px 16px 24px;
  color: var(--muted);
  text-align: center;
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  padding: 10px 12px;
  border-radius: 8px;
  box-shadow: 0 10px 30px var(--shadow);
  z-index: 70;
}

.hidden {
  display: none;
}

@media (max-width: 1200px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .top-bar {
    align-items: flex-start;
  }

  .top-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .top-right {
    width: 100%;
    justify-content: flex-start;
  }

  .input-compact {
    width: 100%;
  }
}
