:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --line: #d9e2ec;
  --text: #1d2939;
  --muted: #64748b;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #d97706;
  --green: #16a34a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}

body.booting {
  overflow: hidden;
}

body.booting .app-shell {
  visibility: hidden;
}

body:not(.booting) .app-shell {
  visibility: visible;
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: #eef3f8;
  color: #475569;
  font-weight: 800;
  letter-spacing: 0;
}

body:not(.booting) .boot-screen {
  display: none;
}

button, input, select {
  font: inherit;
  border-radius: 8px;
}

button {
  border: 0;
  background: var(--blue);
  color: white;
  padding: 10px 16px;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

a { color: inherit; text-decoration: none; }
button.ghost, .public-link { background: #e9eef5; color: #334155; }
button.danger { background: var(--red); }
button.warn { background: var(--amber); }
button.ok { background: var(--green); }

input, select {
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: white;
  min-width: 0;
}

.hidden { display: none !important; }

.login-panel {
  width: min(410px, calc(100vw - 48px));
  margin: 14vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 14px 35px rgba(15, 23, 42, .1);
  display: grid;
  gap: 14px;
}

.login-panel h1 { margin: 0 0 8px; }

.dashboard {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #132033;
  color: #e2e8f0;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand strong { display: block; font-size: 22px; }
.brand span { display: block; margin-top: 4px; color: #94a3b8; font-weight: 700; }

nav {
  display: grid;
  gap: 8px;
}

.nav {
  text-align: left;
  background: transparent;
  color: #cbd5e1;
  padding: 11px 12px;
}

.nav.active {
  background: #2563eb;
  color: #fff;
}

.sidebar .ghost {
  margin-top: auto;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 10px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.topbar h1, .panel h2 { margin: 0; }
.topbar p, .panel p { margin: 4px 0 0; color: var(--muted); font-weight: 700; }
.public-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.public-link { display: inline-block; padding: 10px 14px; border-radius: 8px; font-weight: 800; }

.view { display: none; }
.view.active { display: block; animation: fadeIn .18s ease-out; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.metrics article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .04);
}

.metrics article { padding: 16px; }
.metrics span { display: block; color: var(--muted); font-weight: 800; }
.metrics strong { display: block; font-size: 28px; margin-top: 4px; }

.panel { padding: 18px; margin-bottom: 14px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tab {
  background: #edf2f7;
  color: #334155;
}

.tab.active {
  background: var(--blue);
  color: white;
}

.chart-summary {
  color: #475569;
  font-weight: 800;
  margin: 12px 0;
}

.chart-box {
  position: relative;
}

#trendCanvas {
  width: 100%;
  height: 360px;
  display: block;
  cursor: pointer;
}

.chart-tip {
  position: absolute;
  min-width: 150px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 9px 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .18);
  pointer-events: none;
}

.chart-tip strong,
.chart-tip span {
  display: block;
}

.chart-tip span {
  color: #cbd5e1;
  margin-top: 2px;
}

.create-panel {
  max-width: 980px;
}

.create-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

label span {
  display: block;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 6px;
}

label input, label select {
  width: 100%;
}

.wide { grid-column: span 2; }

.latest-batch {
  margin-top: 16px;
  border: 1px solid #dbe3ec;
  border-radius: 8px;
  background: #f8fafc;
  overflow: hidden;
}

.latest-batch > div {
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.latest-batch span { color: var(--muted); font-weight: 700; }
.latest-batch pre {
  margin: 0;
  padding: 14px;
  max-height: 240px;
  overflow: auto;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.table-wrap { overflow-x: auto; }
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.bulk-check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.bulk-count {
  margin-left: auto;
  color: var(--muted);
  font-weight: 800;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
}
th, td {
  border-top: 1px solid #edf2f7;
  padding: 11px 8px;
  text-align: left;
  vertical-align: middle;
}
th { color: #475569; }
td code {
  background: #f1f5f9;
  padding: 4px 6px;
  border-radius: 6px;
}

.copyable {
  cursor: pointer;
  user-select: all;
}

.copyable:hover {
  background: #dbeafe;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  font-weight: 900;
}

.unused { background: #e0f2fe; color: #0369a1; }
.used { background: #dcfce7; color: #15803d; }
.frozen { background: #fef3c7; color: #b45309; }
.blacklisted { background: #fee2e2; color: #b91c1c; }

.row-actions,
.agent-edit,
.download-edit,
.agent-form,
.stack {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions button {
  padding: 7px 10px;
  font-size: 12px;
}

.agent-form {
  margin-bottom: 14px;
}

.agent-row {
  border-top: 1px solid #edf2f7;
  padding: 12px 0;
  display: grid;
  grid-template-columns: 1fr minmax(420px, auto);
  gap: 12px;
  align-items: center;
}

.agent-row input {
  width: 130px;
}

.download-edit input:nth-child(2) {
  width: 280px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stack {
  margin-top: 12px;
  flex-direction: column;
}

@media (max-width: 1100px) {
  .dashboard { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .agent-row { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .menu-toggle { display: inline-grid; place-items: center; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 82vw);
    z-index: 1000;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 18px 0 40px rgba(15, 23, 42, .24);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  body.sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .34);
    z-index: 999;
  }
  .workspace { padding: 14px; }
  .topbar, .panel-head { display: block; }
  .public-link, .tabs { margin-top: 10px; }
  nav {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .nav {
    width: 100%;
  }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .create-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  #trendCanvas { height: 300px; }
  .public-actions {
    justify-content: flex-start;
    margin-top: 10px;
  }
  .bulk-bar {
    align-items: flex-start;
  }
  .bulk-count {
    margin-left: 0;
    width: 100%;
  }
}
