:root {
  --bg: #07111f;
  --bg-2: #0c1b31;
  --card: rgba(18, 32, 56, 0.72);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eef4ff;
  --muted: #97a8c3;
  --accent: #68a0ff;
  --success: #23d18b;
  --warning: #ffb347;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(47, 109, 255, 0.25), transparent 30%),
    linear-gradient(145deg, var(--bg), var(--bg-2));
  min-height: 100vh;
}

#app {
  max-width: 1720px;
  margin: 0 auto;
}

.screen { display: none; min-height: 100vh; padding: 24px; }
.screen-active { display: block; }
.screen-hidden { display: none !important; }
.glass {
  background: var(--card);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

#loginScreen.screen-active {
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.detail-modal-hidden {
  display: none;
}
.detail-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 10, 18, 0.72);
  backdrop-filter: blur(6px);
}
.detail-modal-card {
  position: relative;
  z-index: 1;
  width: min(900px, 100%);
  max-height: 88vh;
  overflow: auto;
  border-radius: 24px;
  padding: 24px;
}
.detail-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.detail-modal-head h3 {
  margin: 0;
}
.detail-modal-body {
  display: grid;
  gap: 16px;
}
.detail-hero {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  align-items: center;
}
.detail-hero-image {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.08);
}
.detail-hero-info {
  display: grid;
  gap: 12px;
}
.detail-section {
  border-radius: 18px;
  padding: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.detail-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.detail-tab {
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.detail-tab.active {
  background: rgba(104,160,255,0.18);
  border-color: rgba(104,160,255,0.35);
}
.detail-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.detail-chart-card {
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.detail-chart-card h5 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}
.detail-chart-wrap {
  height: 180px;
}
.detail-summary-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.chart-tooltip {
  background: rgba(10, 18, 30, 0.92);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 12px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.28);
}
.detail-section h4 {
  margin: 0 0 10px;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.detail-grid .metric-pill {
  margin: 0;
}
.detail-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.login-card {
  width: min(460px, 100%);
  border-radius: 24px;
  padding: 32px;
}

.login-brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  font-size: 30px;
  border-radius: 18px;
  background: rgba(104, 160, 255, 0.18);
}

.login-brand h1, .topbar h2 { margin: 0; }
.login-brand p, .eyebrow, .bot-meta, .stat-card span, .login-error { color: var(--muted); }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  margin: 0 0 6px;
}

.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 8px; font-size: 14px; }
input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  padding: 14px 16px;
  font-size: 15px;
}
button {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 700;
  cursor: pointer;
  color: white;
  background: linear-gradient(135deg, #5d8dff, #3766ff);
}
.secondary-button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
}
.login-error { min-height: 20px; margin: 0; }

.topbar {
  border-radius: 24px;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.refresh-meta {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.control-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.control-inline span {
  min-width: 68px;
}
.controls-bar select,
.topbar-control select {
  width: 150px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.12);
  color: #ffffff;
  padding: 8px 10px;
}
.topbar-control select option {
  background: #14233c;
  color: #ffffff;
}
.topbar-control {
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.stats-row-bottom {
  margin-top: 22px;
  margin-bottom: 0;
}
.stat-card {
  border-radius: 20px;
  padding: 18px 20px;
}
.stat-card strong { display: block; font-size: 32px; margin-top: 10px; }

main {
  position: relative;
}
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(7, 17, 31, 0.42);
  backdrop-filter: blur(6px);
  border-radius: 24px;
  z-index: 20;
}
.loading-hidden {
  display: none;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #68a0ff;
  animation: spin 0.9s linear infinite;
}
.loading-text {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.bot-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  justify-content: start;
  align-items: start;
}

.bot-card {
  position: relative;
  border-radius: 24px;
  padding: 20px;
  overflow: hidden;
  width: 100%;
  min-width: 0;
}
.bot-card.active {
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: none;
}
.bot-card.active::after {
  content: none;
}
@keyframes pulse {
  0% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.01); }
  100% { opacity: 0.3; transform: scale(1); }
}

.bot-hero {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 22px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 3px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.04);
}
.bot-hero-active {
  border: 5px solid rgba(35, 209, 139, 1);
  box-shadow: 0 0 0 2px rgba(35, 209, 139, 0.45), 0 0 22px rgba(35, 209, 139, 0.7), 0 0 42px rgba(35, 209, 139, 0.45), inset 0 0 28px rgba(35, 209, 139, 0.22);
}
.bot-hero-active::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 26px;
  border: 6px solid rgba(35, 209, 139, 0.65);
  animation: pulseOuter 1s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}
.bot-hero-active::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18px;
  border: 4px solid rgba(120, 255, 190, 0.95);
  box-shadow: inset 0 0 24px rgba(35, 209, 139, 0.24);
  animation: pulseInner 1s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}
.bot-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 17, 31, 0.22);
  z-index: 3;
}
.bot-loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.18);
  border-top-color: #ffffff;
  animation: spin 0.9s linear infinite;
}
@keyframes pulseOuter {
  0% { opacity: 0.45; transform: scale(1); box-shadow: 0 0 10px rgba(35, 209, 139, 0.35); }
  50% { opacity: 1; transform: scale(1.025); box-shadow: 0 0 34px rgba(35, 209, 139, 0.9); }
  100% { opacity: 0.45; transform: scale(1); box-shadow: 0 0 10px rgba(35, 209, 139, 0.35); }
}
@keyframes pulseInner {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}
.bot-age-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(7, 17, 31, 0.72);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
}
.bot-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}
.bot-title-block {
  margin-bottom: 14px;
}
.bot-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.bot-title-block h3 {
  margin: 0 0 4px;
}
.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(255,255,255,0.08);
}
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.health-badge-ok {
  color: #23d18b;
  background: rgba(35,209,139,0.12);
}
.health-badge-idle {
  color: #97a8c3;
  background: rgba(151,168,195,0.12);
}
.health-badge-warn {
  color: #ff6b6b;
  background: rgba(255,107,107,0.12);
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.metric-pill {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
}
.metric-pill span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}
.metric-pill strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  word-break: break-word;
}
.context-bar {
  margin-top: 8px;
  height: 8px;
  width: 100%;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.context-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #23d18b, #4ef2a9);
}
.context-bar-fill-caution {
  background: linear-gradient(90deg, #ffb347, #ffd26a);
}
.context-bar-fill-warn {
  background: linear-gradient(90deg, #ff6b6b, #ff8a8a);
}
.metric-pill-warn {
  border-color: rgba(255,107,107,0.35);
  box-shadow: inset 0 0 0 1px rgba(255,107,107,0.1);
}
.metric-pill-caution {
  border-color: rgba(255,179,71,0.35);
  box-shadow: inset 0 0 0 1px rgba(255,179,71,0.1);
}
.bot-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.upload-button,
.details-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(104, 160, 255, 0.14);
  border: 1px solid rgba(104, 160, 255, 0.28);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.details-button {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
}
.upload-input {
  display: none;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}
.status-dot.active { background: var(--success); }
.status-dot.idle { background: var(--muted); }

.chart-wrap {
  margin-top: 14px;
  height: 120px;
}
.prompt-stats {
  margin-top: 14px;
}
.prompt-stats-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.prompt-stats-head strong {
  font-size: 15px;
}
.prompt-stats-head span {
  color: var(--muted);
  font-size: 12px;
}
.prompt-chart-wrap {
  height: 90px;
}
.per-bot-scale {
  margin-top: 10px;
}
.per-bot-scale span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}
.per-bot-scale input {
  width: 100%;
}
.per-bot-scale-values {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}
.token-stats {
  margin-top: 18px;
}
.token-chart-wrap {
  height: 70px;
}
.task-stats {
  margin-top: 18px;
}
.task-stats-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.task-stats-head strong {
  font-size: 15px;
}
.task-stats-head span {
  color: var(--muted);
  font-size: 12px;
}
.task-chart-wrap {
  height: 140px;
}
.event-panel {
  margin-top: 16px;
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.event-panel-head {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.event-list {
  display: grid;
  gap: 8px;
}
.event-item {
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 12px;
  background: rgba(255,255,255,0.04);
}
.event-info {
  border-left: 3px solid #68a0ff;
}
.event-warn {
  border-left: 3px solid #ffb347;
}
.event-error {
  border-left: 3px solid #ff6b6b;
}
.bot-footer {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

@media (min-width: 1100px) and (max-width: 1399px) {
  .bot-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 800px) and (max-width: 1099px) {
  .bot-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .stats-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 14px; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .topbar-actions button { flex: 1; }
  .refresh-meta { width: 100%; text-align: center; }
  .control-inline { justify-content: space-between; }
  .control-inline span { min-width: 0; }
  .topbar-control select { width: 100%; }
  .metric-grid { grid-template-columns: 1fr; }
  .bot-grid { grid-template-columns: 1fr; }
}
