:root {
  --bg: #0b1020;
  --shell: #0f172a;
  --surface: #111827;
  --surface-soft: #162033;
  --field: #0b1220;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --subtle: #64748b;
  --accent: #2f80ed;
  --accent-soft: rgba(47, 128, 237, 0.18);
  --cyan: #38bdf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #273244;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

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

a {
  color: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--shell);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
  color: white;
}

.brand h1,
.brand p,
.page-header h2,
.page-header p,
.panel h3,
.panel h4 {
  margin: 0;
}

.brand h1 {
  font-size: 1rem;
}

.brand p,
.subtitle,
.panel-header p,
.muted {
  color: var(--muted);
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
  background: var(--accent-soft);
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 1.45rem;
}

.header-actions,
.button-group,
.inline-form,
.small-form,
.actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge,
.tag,
.job-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.badge {
  color: #bfdbfe;
  background: var(--accent-soft);
}

.tag-archived {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.16);
}

.btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-soft);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn:hover {
  border-color: rgba(229, 231, 235, 0.18);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-secondary {
  background: #263348;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-ghost {
  background: transparent;
  border-color: rgba(229, 231, 235, 0.18);
}

.link-inline {
  color: #93c5fd;
  text-decoration: none;
}

.link-inline:hover {
  text-decoration: underline;
}

.alerts {
  margin-bottom: 16px;
}

.alert {
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.18);
}

.panel,
.hero-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.8fr);
  gap: 20px;
  align-items: start;
}

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

.stats-grid,
.grid-2,
.grid-3,
.button-grid,
.metric-strip {
  display: grid;
  gap: 12px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

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

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

.metric-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.hero-panel .metric-strip {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card,
.stat-card,
.metric {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
}

.stat-card h3,
.metric span {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.stat-card p,
.metric strong {
  margin: 0;
  font-size: 1.35rem;
  color: var(--text);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 110px;
  gap: 10px;
  margin-bottom: 16px;
}

.stacked-form,
.form-grid {
  display: grid;
  gap: 12px;
}

label {
  color: var(--muted);
  font-size: 0.92rem;
}

.log-box,
textarea,
input,
select {
  width: 100%;
  min-width: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select {
  height: 42px;
}

.small-form input {
  width: auto;
  min-width: 180px;
}

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

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.item-list,
.kv-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.item-list li,
.kv-list li {
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.item-list li:last-child,
.kv-list li:last-child {
  border-bottom: none;
}

.kv-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.kv-list span {
  color: var(--muted);
}

.job-status {
  min-width: 76px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.job-running,
.job-queued {
  color: #bae6fd;
  background: rgba(56, 189, 248, 0.14);
}

.job-paused {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.16);
}

.job-done {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.14);
}

.job-error,
.job-canceled {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.14);
}

span.job-error {
  margin-left: 6px;
}

.progress-bar {
  width: min(220px, 100%);
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  margin: 8px 0 2px;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.job-events {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.86rem;
}

.job-events li {
  margin-bottom: 4px;
}

.job-events span {
  display: block;
  color: var(--subtle);
  font-size: 0.78rem;
}

.log-box {
  overflow: auto;
  max-height: 420px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

.agent-md {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin: 0;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card,
.status-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 26px;
  border-radius: 8px;
}

.status-card {
  width: min(780px, calc(100% - 48px));
  margin: 60px auto;
}

.login-card h1,
.status-card h1 {
  margin-top: 0;
}

.login-note {
  color: var(--muted);
  margin-bottom: 0;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    width: auto;
    height: auto;
  }
  .sidebar nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .sidebar-footer {
    display: none;
  }
  .hero-panel,
  .grid-2,
  .grid-3,
  .stats-grid,
  .metric-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main-content {
    padding: 16px;
  }
  .page-header,
  .panel-header {
    display: grid;
  }
  .sidebar nav,
  .search-form,
  .button-grid {
    grid-template-columns: 1fr;
  }
  .btn,
  .inline-form,
  .small-form,
  .small-form input {
    width: 100%;
  }
}
