:root {
  --bg: #080c12;
  --bg-soft: #0b111a;
  --panel: #101823;
  --panel-2: #151f2d;
  --panel-3: #1b2838;
  --border: #223247;
  --border-soft: #192536;
  --text: #e7eef8;
  --muted: #8ea1ba;
  --faint: #637690;
  --accent: #4c9aff;
  --accent-strong: #6bb0ff;
  --accent-soft: rgba(76, 154, 255, 0.13);
  --good: #46d16a;
  --good-soft: rgba(70, 209, 106, 0.12);
  --warn: #e8b85a;
  --warn-soft: rgba(232, 184, 90, 0.11);
  --bad: #ff7b7b;
  --bad-soft: rgba(255, 123, 123, 0.11);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(76, 154, 255, 0.13), transparent 62%),
    radial-gradient(800px 500px at 96% 2%, rgba(105, 84, 220, 0.09), transparent 60%),
    linear-gradient(180deg, #090e15 0%, #080c12 55%, #070b10 100%);
  background-attachment: fixed;
}

::selection {
  background: rgba(76, 154, 255, 0.32);
  color: #fff;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  line-height: 1.22;
}

h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.01em;
}

h3 {
  margin: 0;
  font-size: 0.9rem;
}

button,
input,
select,
textarea {
  font: inherit;
}

code,
pre,
textarea {
  font-family: var(--mono);
}

a {
  color: var(--accent);
}

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

.small {
  font-size: 0.8rem;
}

.hint {
  color: var(--faint);
  font-size: 0.76rem;
  line-height: 1.4;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 38px;
  padding: 0.52rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.15;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn:hover:not(:disabled) {
  border-color: #334960;
  background: var(--panel-3);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:focus-visible,
.tab:focus-visible,
.agent-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #04101e;
}

.btn.primary:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.btn.danger {
  border-color: rgba(255, 123, 123, 0.45);
  background: rgba(255, 123, 123, 0.08);
  color: #ff9c9c;
}

.btn.danger:hover:not(:disabled) {
  border-color: var(--bad);
  background: rgba(255, 123, 123, 0.16);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.btn.small {
  min-height: 32px;
  padding: 0.36rem 0.62rem;
  font-size: 0.78rem;
}

.btn.block {
  width: 100%;
}

.button-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.button-row.wrap {
  flex-wrap: wrap;
  margin-top: 0.2rem;
}

/* Form controls */

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 0.52rem 0.68rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #090f17;
  color: var(--text);
  font-size: 0.86rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 120px;
  line-height: 1.55;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #4d5e74;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(76, 154, 255, 0.14);
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select {
  cursor: pointer;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  min-width: 0;
}

.field > span,
.field .label-row > span:first-child {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.field em {
  color: var(--faint);
  font-style: normal;
  font-weight: 400;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.84rem;
  cursor: pointer;
  user-select: none;
}

.check input {
  width: auto;
  min-height: auto;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-error {
  margin: 0;
  color: #ff9e9e;
  font-size: 0.8rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.dirty-flag {
  color: var(--warn);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.code-input {
  min-height: 170px;
  background: #060a10;
  font-size: 0.8rem;
  tab-size: 2;
}

.code-input.dirty {
  border-color: rgba(232, 184, 90, 0.62);
}

/* Login */

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.4rem;
}

.login-card {
  position: relative;
  width: min(430px, 100%);
  padding: clamp(1.35rem, 4vw, 2.1rem);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(22, 32, 46, 0.97), rgba(12, 19, 29, 0.98));
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.8;
}

.login-card h1 {
  margin: 0.95rem 0 0.35rem;
  font-size: 1.55rem;
  letter-spacing: -0.025em;
}

.login-card > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.stack {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.4rem;
}

.stack .btn {
  margin-top: 0.2rem;
}

.api-hint {
  margin-top: 1.25rem !important;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--faint);
  overflow-wrap: anywhere;
}

.api-hint code {
  color: #9fb4ce;
}

.api-hint.subtle {
  margin-top: 0.65rem !important;
}

/* Brand */

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent-strong), #2d6fce);
  color: #03101f;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: 0 5px 18px rgba(76, 154, 255, 0.24);
}

.brand-mark.large {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 0.95rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.12;
  min-width: 0;
}

.brand-text strong {
  font-size: 0.88rem;
  letter-spacing: 0.1em;
}

.brand-text span {
  color: var(--faint);
  font-size: 0.63rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

/* App shell */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.62rem clamp(0.8rem, 2.4vw, 1.8rem);
  border-bottom: 1px solid rgba(34, 50, 71, 0.85);
  background: rgba(8, 12, 18, 0.86);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.api-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  max-width: 46vw;
  margin-left: auto;
  padding: 0.28rem 0.65rem;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: rgba(16, 24, 35, 0.7);
  color: var(--faint);
  font-size: 0.68rem;
}

.api-chip span {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.api-chip code {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.topbar .api-chip + .topbar-actions {
  margin-left: 0;
}

.layout {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 1rem clamp(0.8rem, 2.4vw, 1.8rem) 2.5rem;
  flex: 1;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

#agentDashboard {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.card {
  min-width: 0;
  padding: clamp(0.85rem, 1.5vw, 1.2rem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(20, 30, 44, 0.92), rgba(13, 20, 30, 0.94));
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.17), inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.panel-head p {
  margin: 0.2rem 0 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 0.08rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

/* Sidebar */

.sidebar {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 96px);
}

.create-row {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.create-row input {
  min-width: 0;
  flex: 1;
}

.create-row .btn {
  flex: 0 0 auto;
}

.inline-error {
  margin-top: 0.55rem;
  padding: 0.52rem 0.6rem;
  border: 1px solid rgba(255, 123, 123, 0.25);
  border-radius: 8px;
  background: var(--bad-soft);
  color: #ffadad;
  font-size: 0.76rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.agent-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
  padding-right: 0.15rem;
  overflow-y: auto;
  min-height: 0;
}

.agent-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  width: 100%;
  padding: 0.58rem 0.62rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.agent-item:hover {
  border-color: var(--border-soft);
  background: rgba(255, 255, 255, 0.025);
}

.agent-item.selected {
  border-color: rgba(76, 154, 255, 0.42);
  background: var(--accent-soft);
}

.agent-item.selected::before {
  content: "";
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: -1px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.agent-item-top {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  min-width: 0;
}

.agent-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #526176;
}

.agent-dot.online {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(70, 209, 106, 0.1), 0 0 9px rgba(70, 209, 106, 0.55);
}

.agent-dot.offline {
  background: #5e6d81;
}

.agent-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-meta {
  overflow: hidden;
  padding-left: 1.02rem;
  color: var(--faint);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-mini {
  padding: 1.1rem 0.4rem;
  color: var(--faint);
  font-size: 0.79rem;
  text-align: center;
}

/* Empty state */

.empty-state {
  padding: clamp(2.2rem, 8vw, 4rem) 1.4rem;
  text-align: center;
}

.empty-state h2 {
  font-size: 1.1rem;
}

.empty-state p {
  max-width: 440px;
  margin: 0.5rem auto 0;
  color: var(--muted);
  font-size: 0.86rem;
}

/* Agent header */

.agent-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.2rem;
  flex-wrap: wrap;
}

.agent-head-main {
  min-width: 0;
  flex: 1 1 320px;
}

.eyebrow {
  color: var(--faint);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.2rem;
}

.title-row h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 1.65rem);
  letter-spacing: -0.025em;
}

.meta-line {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.agent-side-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, auto));
  gap: 0.65rem 1.2rem;
  margin: 0;
  align-self: center;
}

.agent-side-meta dt {
  color: var(--faint);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.agent-side-meta dd {
  margin: 0.14rem 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}

/* Alerts */

.alert {
  padding: 0.68rem 0.82rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.79rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.alert.info {
  border-color: rgba(76, 154, 255, 0.28);
  background: rgba(76, 154, 255, 0.07);
  color: #a9c7ed;
}

.alert.warn {
  border-color: rgba(232, 184, 90, 0.3);
  background: var(--warn-soft);
  color: #e7c98e;
}

.alert.error {
  border-color: rgba(255, 123, 123, 0.35);
  background: var(--bad-soft);
  color: #ffb1b1;
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.16rem 0.52rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.055em;
  line-height: 1.35;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge.good {
  border-color: rgba(70, 209, 106, 0.32);
  background: var(--good-soft);
  color: #75e394;
}

.badge.warn {
  border-color: rgba(232, 184, 90, 0.32);
  background: var(--warn-soft);
  color: #efca7b;
}

.badge.bad {
  border-color: rgba(255, 123, 123, 0.34);
  background: var(--bad-soft);
  color: #ff9c9c;
}

.badge.info {
  border-color: rgba(76, 154, 255, 0.32);
  background: var(--accent-soft);
  color: #9ec7ff;
}

.badge.neutral {
  border-color: var(--border);
  background: rgba(142, 161, 186, 0.07);
  color: var(--muted);
}

/* Job */

.job-head {
  margin-bottom: 0.85rem;
}

.job-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.6rem;
  padding: 0.72rem;
  border: 1px solid var(--border-soft);
  border-radius: 11px;
  background: rgba(7, 12, 18, 0.5);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 0;
}

.stat-label {
  color: var(--faint);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.stat-value {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-value.small-value {
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
}

.message-block {
  margin-top: 0.65rem;
}

.job-message {
  max-height: 190px;
  margin: 0.32rem 0 0;
  padding: 0.65rem 0.72rem;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: rgba(7, 12, 18, 0.55);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Start form */

.start-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem 0.7rem;
  margin-top: 0.9rem;
}

.span-2 {
  grid-column: span 2;
}

.checks {
  display: flex;
  align-items: center;
  gap: 1.3rem;
  flex-wrap: wrap;
  padding-top: 0.2rem;
}

.start-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.start-actions .form-error {
  flex: 1 1 240px;
}

/* Tabs */

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.28rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(16, 24, 35, 0.9);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  min-height: 38px;
  padding: 0.5rem 0.92rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
}

.tab.active {
  border-color: var(--border);
  background: var(--panel-3);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-height: 220px;
}

/* Console */

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  min-width: 0;
  padding: 0.24rem 0.58rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(7, 12, 18, 0.6);
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.3;
}

.connection .dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #5f6d80;
}

.connection.live {
  border-color: rgba(70, 209, 106, 0.25);
  color: #88dea0;
}

.connection.live .dot {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(70, 209, 106, 0.1), 0 0 8px rgba(70, 209, 106, 0.5);
}

.connection.error {
  max-width: 100%;
  border-color: rgba(255, 123, 123, 0.28);
  color: #ffabab;
}

.connection.error .dot {
  background: var(--bad);
}

.connection.offline {
  border-color: rgba(232, 184, 90, 0.25);
  color: #e4c27c;
}

.connection.offline .dot {
  background: var(--warn);
}

.connection.connecting .dot {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.connection.neutral .dot {
  background: #5f6d80;
}

#consoleStateText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-left: auto;
}

#autoScrollHint {
  color: var(--warn);
}

.console {
  height: clamp(300px, 46vh, 620px);
  padding: 0.45rem 0;
  overflow: auto;
  border: 1px solid #152131;
  border-radius: 10px;
  background: #05090e;
  font-family: var(--mono);
  font-size: 0.775rem;
  line-height: 1.52;
  overscroll-behavior: contain;
}

.console:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.console-line {
  display: grid;
  grid-template-columns: 72px 52px minmax(0, 1fr);
  gap: 0.48rem;
  align-items: start;
  padding: 0.05rem 0.8rem;
}

.console-line:hover {
  background: rgba(255, 255, 255, 0.025);
}

.console-time {
  color: #52647b;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.console-stream {
  display: inline-flex;
  justify-content: center;
  padding: 0 0.18rem;
  border: 1px solid #263548;
  border-radius: 4px;
  background: rgba(38, 53, 72, 0.25);
  color: #73859d;
  font-size: 0.58rem;
  letter-spacing: 0.035em;
  line-height: 1.6;
  text-transform: uppercase;
  white-space: nowrap;
}

.console-stream.stderr {
  border-color: rgba(255, 123, 123, 0.3);
  background: var(--bad-soft);
  color: #ff9e9e;
}

.console-text {
  min-width: 0;
  color: #c5d3e4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console-empty {
  padding: 0.55rem 0.85rem;
  color: #51637a;
  font-style: italic;
}

/* Counters */

.count-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.count-grid.compact {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 0.25rem;
}

.count-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  padding: 0.66rem 0.78rem;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: rgba(7, 12, 18, 0.55);
}

.count-card strong {
  color: var(--text);
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.count-card.good strong {
  color: var(--good);
}

.count-card.warn strong {
  color: var(--warn);
}

.count-card.bad strong {
  color: var(--bad);
}

.count-grid.compact .count-card strong {
  font-size: 1.02rem;
}

/* Tables */

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.77rem;
}

.inline-field select {
  width: auto;
  min-height: 34px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}

.table-title {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-wrap {
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: rgba(6, 10, 15, 0.6);
}

.table-wrap.tall {
  max-height: 360px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.77rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: #101925;
  color: var(--faint);
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.065em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid rgba(25, 37, 54, 0.8);
  color: #c3d1e2;
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.023);
}

td.mono {
  font-family: var(--mono);
  font-size: 0.73rem;
  word-break: break-all;
}

td.break {
  overflow-wrap: anywhere;
}

td.nowrap {
  white-space: nowrap;
}

.empty-row td {
  padding: 1.5rem 0.8rem;
  color: var(--faint);
  text-align: center;
}

.empty-row:hover {
  background: transparent;
}

/* Toast */

.toasts {
  position: fixed;
  top: 4.4rem;
  right: 0.9rem;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(370px, calc(100vw - 1.8rem));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.66rem 0.7rem 0.66rem 0.85rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: rgba(21, 31, 45, 0.98);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  font-size: 0.79rem;
  line-height: 1.45;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.success {
  border-left-color: var(--good);
}

.toast.error {
  border-left-color: var(--bad);
}

.toast.info {
  border-left-color: var(--accent);
}

.toast.leaving {
  opacity: 0;
  transform: translateX(14px);
}

.toast-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-close {
  flex: 0 0 auto;
  padding: 0 0.1rem;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

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

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
  background: rgba(2, 6, 11, 0.76);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal {
  width: min(560px, 100%);
  padding: clamp(1.1rem, 3vw, 1.5rem);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, #172232, #0d151f);
  box-shadow: 0 35px 100px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  animation: modal-in 0.16s ease-out;
}

.modal h2 {
  margin-bottom: 0.4rem;
  font-size: 1.18rem;
}

.modal > p {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.token-box {
  max-height: 200px;
  margin: 1rem 0;
  padding: 0.8rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #05090e;
}

.token-box code {
  color: #d9e8fa;
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  user-select: all;
}

.copy-status {
  margin: 0 0 0.75rem !important;
  font-size: 0.77rem !important;
}

.copy-status.good {
  color: var(--good) !important;
}

.copy-status.bad {
  color: var(--bad) !important;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.copy-helper {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* Scrollbars */

* {
  scrollbar-color: #2b3c52 transparent;
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #2b3c52;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: #3a4f69;
  background-clip: padding-box;
}

/* Responsive */

@media (max-width: 1180px) {
  .start-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .count-grid.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  input,
  select,
  textarea,
  .code-input {
    /* Avoid the automatic zoom-on-focus behavior in mobile Safari. */
    font-size: 16px;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 0.8rem;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .agent-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    max-height: 240px;
  }

  .agent-meta {
    padding-left: 1.02rem;
  }

  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  body {
    font-size: 14px;
  }

  .topbar {
    gap: 0.55rem;
  }

  .api-chip {
    display: none;
  }

  .topbar-actions,
  .topbar .api-chip + .topbar-actions {
    margin-left: auto;
  }

  .layout {
    padding: 0.7rem 0.65rem 2rem;
  }

  .card {
    padding: 0.85rem;
    border-radius: 12px;
  }

  .agent-side-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 0.55rem 0.9rem;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .start-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .span-2 {
    grid-column: auto;
  }

  .button-row {
    flex-wrap: wrap;
  }

  .job-head {
    align-items: flex-start;
  }

  .job-head .button-row {
    width: 100%;
  }

  .panel-toolbar {
    align-items: flex-start;
  }

  .toolbar-actions {
    margin-left: 0;
  }

  .console {
    height: 50vh;
    min-height: 250px;
  }

  .console-line {
    grid-template-columns: 58px 48px minmax(0, 1fr);
    gap: 0.35rem;
    padding: 0.06rem 0.5rem;
  }

  .console-stream {
    padding: 0 0.12rem;
    font-size: 0.52rem;
    letter-spacing: 0;
  }

  .count-grid {
    gap: 0.45rem;
  }

  .count-card {
    padding: 0.55rem 0.6rem;
  }

  .count-card strong {
    font-size: 1.1rem;
  }

  .count-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-wrap,
  .table-wrap.tall {
    max-height: 330px;
  }

  .empty-row td {
    text-align: left;
  }

  table {
    min-width: 600px;
  }

  .proxy-entries-table {
    min-width: 760px;
  }

  .toasts {
    top: 3.7rem;
    right: 0.6rem;
    width: calc(100vw - 1.2rem);
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .brand-text span {
    display: none;
  }

  .agent-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .title-row h1 {
    font-size: 1.2rem;
  }

  .job-head .button-row .btn {
    flex: 1 1 auto;
  }

  .count-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .count-grid .count-card:first-child {
    grid-column: span 2;
  }

  .count-grid.compact .count-card:first-child {
    grid-column: auto;
  }

  .console-line {
    grid-template-columns: 50px 44px minmax(0, 1fr);
    font-size: 0.72rem;
  }

  .console-time {
    font-size: 0.66rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}
