:root {
  --brand-dark: #1F3864;
  --brand-teal: #00B0A0;
  --brand-teal-hover: #009488;
  --bg: #f4f6f9;
  --sidebar-bg: #1F3864;
  --sidebar-text: #cdd8e8;
  --sidebar-active: #00B0A0;
  --card-bg: #ffffff;
  --border: #dde3ea;
  --text: #1a202c;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --input-bg: #f9fafb;
  --input-border: #d1d5db;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --sidebar-w: 220px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo h1 {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .3px;
}

.sidebar-logo p {
  font-size: 11px;
  color: rgba(255,255,255,.45);
  margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-section {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 14px 20px 4px;
}

.nav-link {
  display: block;
  padding: 7px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: all .15s;
}

.nav-link:hover { color: #fff; background: rgba(255,255,255,.13); }

.nav-link.active {
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-active);
  background: rgba(0,176,160,.18);
  font-weight: 600;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: rgba(255,255,255,.4);
}

.sidebar-footer a {
  color: rgba(255,255,255,.55);
  text-decoration: none;
}

.sidebar-footer a:hover { color: #fff; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { font-size: 16px; font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.content { padding: 28px; max-width: 900px; }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.card-header h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--brand-dark);
}

.card-body { padding: 20px; }

.card-header-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0 0;
  font-weight: 400;
}

/* ── Card header with Test button ────────────────────────────────────── */
.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.card-header-left { flex: 1; }

.card-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-test {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--brand-teal);
  background: transparent;
  color: var(--brand-teal);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.btn-test:hover { background: var(--brand-teal); color: #fff; }
.btn-test:disabled { opacity: .5; cursor: not-allowed; }

.test-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 100px;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.test-badge-ok   { background: #dcfce7; color: #16a34a; }
.test-badge-fail { background: #fee2e2; color: #dc2626; }
.test-badge-pending { background: #fef9c3; color: #92400e; }

/* ── Form ────────────────────────────────────────────────────────────── */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

/* Full-width field (e.g. textarea) spans all grid columns */
.field--full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 4px; }

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  padding: 7px 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  font-size: 13px;
  color: var(--text);
  transition: border-color .15s;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand-teal);
  box-shadow: 0 0 0 3px rgba(0,176,160,.12);
}

.field textarea { resize: vertical; min-height: 72px; }

.field .hint {
  font-size: 11px;
  color: var(--text-muted);
}

.secret-wrap { position: relative; }

.secret-wrap input { padding-right: 36px; }

.secret-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  padding: 0;
  line-height: 1;
}

.secret-toggle:hover { color: var(--brand-teal); }

.secret-clear {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--danger);
  padding: 0;
  margin-top: 3px;
  line-height: 1.4;
}
.secret-clear:hover { text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}

.btn-primary { background: var(--brand-teal); color: #fff; }
.btn-primary:hover { background: var(--brand-teal-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d1d8e0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  z-index: 9999;
}

#toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
#toast.success { background: var(--success); }
#toast.error { background: var(--danger); }

/* ── Logo ────────────────────────────────────────────────────────────── */
.sidebar-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  display: block;
  margin-bottom: 8px;
}

.auth-logo-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  display: block;
  margin: 0 auto 20px;
}

/* ── Login page ──────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--brand-dark);
}

.login-logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-form .field { margin-bottom: 14px; }

.login-form .field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}

.login-form .field input {
  font-size: 14px;
  padding: 9px 12px;
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: var(--danger);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}

.login-notice {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #15803d;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}

.login-btn { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue  { background: #dbeafe; color: #1d4ed8; }
.badge-warn  { background: #fef9c3; color: #854d0e; }
.badge-muted { background: #f3f4f6; color: #6b7280; }

/* ── Alerts ──────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 20px;
}

.alert-success {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #15803d;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: var(--danger);
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1d4ed8;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-warn {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}

/* Admin edit banner — shown at top of settings page when admin edits another user */
.admin-edit-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #1d4ed8;
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 24px;
}
.admin-edit-banner-icon { font-size: 28px; line-height: 1; }
.admin-edit-banner-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .75; }
.admin-edit-banner-name  { font-size: 20px; font-weight: 700; line-height: 1.2; }
.admin-edit-banner-email { font-size: 12px; opacity: .7; margin-top: 2px; }

/* ── Run-as info strip (agents page) ─────────────────────────────────── */
.run-as-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.run-as-strip-label { font-weight: 600; color: var(--text); }
.run-as-strip-user  { font-weight: 700; color: var(--text); }
.run-as-strip-email { opacity: .65; }

/* ── Admin table ─────────────────────────────────────────────────────── */
.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 16px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

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

.admin-table tr:hover td { background: #f9fafb; }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── Extra button variants ───────────────────────────────────────────── */
.btn-teal  { background: #e0faf8; color: #007a72; border: 1px solid #b2ece8; }
.btn-teal:hover { background: #b2ece8; }

/* ── Misc ────────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.mt-4 { margin-top: 16px; }
.save-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}

/* ── Create user form ────────────────────────────────────────────────── */
.create-user-form .field label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

/* ── Pricing page ────────────────────────────────────────────────────────── */
.pricing-nav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
}
.pricing-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pricing-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  color: var(--brand-dark);
}
.pricing-nav-links { display: flex; gap: 10px; align-items: center; }

.pricing-hero {
  background: var(--brand-dark);
  color: #fff;
  padding: 64px 28px 56px;
  text-align: center;
}
.pricing-hero-inner { max-width: 640px; margin: 0 auto; }
.pricing-badge {
  display: inline-block;
  background: rgba(0,176,160,.18);
  color: var(--brand-teal);
  border: 1px solid rgba(0,176,160,.35);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 14px;
  margin-bottom: 20px;
  letter-spacing: .3px;
}
.pricing-hero h1 { font-size: 40px; font-weight: 800; color: #fff; margin-bottom: 14px; line-height: 1.2; }
.pricing-hero p { font-size: 16px; color: rgba(255,255,255,.65); line-height: 1.6; }

.pricing-section { max-width: 1200px; margin: 0 auto; padding: 48px 28px; }

.plan-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  align-items: start;
}

.plan-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.plan-card-highlight {
  border-color: var(--brand-teal);
  box-shadow: 0 0 0 2px rgba(0,176,160,.18), var(--shadow);
}
.plan-popular-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand-teal);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 14px;
  border-radius: 99px;
  white-space: nowrap;
  letter-spacing: .4px;
}

.plan-header { margin-bottom: 20px; }
.plan-name { font-size: 17px; font-weight: 700; color: var(--brand-dark); margin-bottom: 4px; }
.plan-tagline { font-size: 12px; color: var(--text-muted); line-height: 1.4; margin-bottom: 16px; }
.plan-price { font-size: 36px; font-weight: 800; color: var(--brand-dark); line-height: 1; }
.plan-price span { font-size: 15px; font-weight: 400; color: var(--text-muted); }
.plan-price-custom { font-size: 28px; font-weight: 800; color: var(--brand-dark); }
.plan-price-note { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.plan-features { flex: 1; margin-bottom: 20px; display: flex; flex-direction: column; gap: 10px; }
.plan-feature-row { display: flex; flex-direction: column; gap: 1px; }
.feat-top { display: flex; align-items: center; gap: 6px; }
.feat-icon { font-size: 11px; font-weight: 700; flex-shrink: 0; width: 14px; text-align: center; }
.feat-yes { color: var(--brand-teal); }
.feat-no  { color: #d1d5db; }
.feat-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.feat-value { font-size: 11px; font-weight: 600; color: var(--text); padding-left: 20px; white-space: nowrap; }

.plan-btn { font-size: 14px; padding: 10px 16px; border-radius: 6px; font-weight: 600; cursor: pointer; border: none; transition: background .15s; }
.plan-btn-primary { background: var(--brand-teal); color: #fff; }
.plan-btn-primary:hover { background: var(--brand-teal-hover); }
.plan-btn-outline { background: transparent; color: var(--brand-dark); border: 1.5px solid var(--border); }
.plan-btn-outline:hover { background: var(--bg); }
.plan-current-badge {
  text-align: center;
  padding: 9px;
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #15803d;
}

/* ── Pricing comparison table ─────────────────────────────────────────────── */
.pricing-table-section { padding-top: 0; }
.pricing-table-title { font-size: 22px; font-weight: 700; color: var(--brand-dark); margin-bottom: 20px; text-align: center; }
.pricing-table-wrap { overflow-x: auto; }
.pricing-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pricing-table th { background: var(--brand-dark); color: #fff; padding: 12px 16px; text-align: center; font-size: 13px; font-weight: 600; }
.pricing-table th:first-child { text-align: left; border-radius: 8px 0 0 0; }
.pricing-table th:last-child { border-radius: 0 8px 0 0; }
.pricing-table th.col-highlight { background: var(--brand-teal); }
.pricing-table td { padding: 11px 16px; border-bottom: 1px solid var(--border); text-align: center; color: var(--text); }
.pricing-table td.feature-name { text-align: left; color: var(--text-muted); font-weight: 500; }
.pricing-table td.col-highlight { background: rgba(0,176,160,.05); }
.pricing-table tr:last-child td { border-bottom: none; font-weight: 600; }
.tbl-yes { color: var(--brand-teal); font-weight: 700; }
.tbl-no  { color: #d1d5db; }
.pricing-table-note { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 14px; }

/* ── Enterprise callout ───────────────────────────────────────────────────── */
.enterprise-callout {
  background: var(--brand-dark);
  border-radius: 10px;
  padding: 28px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.enterprise-callout-title { font-size: 18px; font-weight: 700; color: #fff; margin-bottom: 6px; }
.enterprise-callout-sub { font-size: 14px; color: rgba(255,255,255,.6); }
.pricing-footer { text-align: center; padding: 24px; font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border); }
.pricing-footer a { color: var(--brand-teal); text-decoration: none; }

/* ── Subscription management page ────────────────────────────────────────── */
.sub-current-card {
  background: var(--brand-dark);
  border-radius: 10px;
  padding: 24px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  color: #fff;
}
.sub-current-label { font-size: 11px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; color: rgba(255,255,255,.45); margin-bottom: 4px; }
.sub-current-name { font-size: 22px; font-weight: 700; }
.sub-current-tagline { font-size: 13px; color: rgba(255,255,255,.55); margin-top: 4px; }
.sub-current-price { font-size: 32px; font-weight: 800; color: var(--brand-teal); text-align: right; }
.sub-current-price span { font-size: 15px; font-weight: 400; color: rgba(255,255,255,.45); }
.sub-current-note { font-size: 11px; color: rgba(255,255,255,.35); text-align: right; margin-top: 3px; }
.limits-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
.limit-item { text-align: center; padding: 16px 8px; }
.limit-value { font-size: 28px; font-weight: 800; color: var(--brand-dark); }
.limit-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Usage Monitor page ───────────────────────────────────────────────────── */
.usage-filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.usage-filter-group { display: flex; flex-direction: column; gap: 6px; }
.usage-filter-label { font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--text-muted); }
.usage-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary);
  background: #fff;
  min-width: 160px;
  cursor: pointer;
}
.usage-period-tabs { display: flex; gap: 4px; }
.usage-period-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  background: #fff;
  transition: all .15s;
}
.usage-period-tab:hover { border-color: var(--brand-dark); color: var(--brand-dark); }
.usage-period-tab.active { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }

.usage-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.usage-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
}
.usage-card-highlight { border-color: var(--brand-teal); }
.usage-card-value { font-size: 30px; font-weight: 800; color: var(--brand-dark); line-height: 1.1; }
.usage-card-highlight .usage-card-value { color: var(--brand-teal); }
.usage-card-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.usage-card-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.agent-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  letter-spacing: .3px;
}
.badge-red { background: #EF4444; color: #fff; }

.usage-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  gap: 10px;
  text-align: center;
}
.usage-empty-icon { font-size: 36px; }
.usage-empty-title { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.usage-empty-desc { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

/* ── Agents page ──────────────────────────────────────────────────────────── */
.agents-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 820px;
}

.agent-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s;
}

.agent-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.09); }

/* ── Card header ─────────────────────────────────────────────────── */
.agent-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.agent-header-left {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.agent-icon {
  font-size: 26px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.agent-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-dark);
  line-height: 1.3;
}

.agent-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 4px;
  max-width: 500px;
}

.agent-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
  padding-top: 1px;
}

/* ── Card body ───────────────────────────────────────────────────── */
.agent-card-body {
  padding: 16px 24px 20px;
}

.config-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 0;
}

/* ── Toggle switch ───────────────────────────────────────────────── */
.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  padding: 7px 20px 7px 0;
  margin-right: 8px;
}

.toggle-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--input-border);
  border-radius: 10px;
  transition: background .18s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle-row input[type="checkbox"]:checked ~ .toggle-track,
.toggle-row input[type="checkbox"]:checked + .toggle-track {
  background: var(--brand-teal);
}

.toggle-row input[type="checkbox"]:checked ~ .toggle-track::after,
.toggle-row input[type="checkbox"]:checked + .toggle-track::after {
  transform: translateX(16px);
}

.toggle-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* ── Content type chips ──────────────────────────────────────────── */
.type-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.type-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  background: #f9fafb;
  transition: all .15s;
  user-select: none;
}

.type-chip:hover { border-color: var(--brand-teal); color: var(--brand-dark); }

.type-chip input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: var(--brand-teal);
  cursor: pointer;
}

/* ── Content extras ──────────────────────────────────────────────── */
.content-extras {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.content-extras .field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
}

/* ── Card footer ─────────────────────────────────────────────────── */
.agent-card-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  border-radius: 0 0 10px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.footer-actions { display: flex; align-items: center; gap: 10px; }
.footer-usage   { display: flex; align-items: center; }

/* ── Usage badge ──────────────────────────────────────────────── */
.usage-badge {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.usage-badge a { color: var(--brand-teal); text-decoration: none; }
.usage-badge a:hover { text-decoration: underline; }
.usage-badge.usage-warn  { color: #b45309; }
.usage-badge.usage-limit { color: #b91c1c; font-weight: 500; }
.usage-badge.usage-na    { color: var(--text-muted); font-style: italic; }

/* ── Run button ──────────────────────────────────────────────────── */
.run-btn-icon { font-size: 11px; }

.run-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.run-pulse { animation: pulse-badge 1.4s ease-in-out infinite; }

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ── Split page layout ───────────────────────────────────────────────── */
.run-page-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.run-page-layout .agents-stack {
  flex: 0 0 auto;
  width: clamp(320px, 48%, 500px);
  max-width: none;
}

/* ── Embedded run panel ──────────────────────────────────────────────── */
.run-panel {
  flex: 1;
  min-width: 260px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 90px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.run-panel-idle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 24px;
  text-align: center;
  min-height: 220px;
}

.run-panel-idle-icon { font-size: 36px; opacity: .18; }
.run-panel-idle-title { font-size: 14px; font-weight: 600; color: var(--text-muted); }
.run-panel-idle-hint  { font-size: 12px; color: var(--text-muted); line-height: 1.6; }

.run-panel-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* Panel header */
.run-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.run-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

.run-panel-title span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.run-panel-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.run-panel-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.log-status-badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.status-running   { background: rgba(0,176,160,.12);  color: #007a72; animation: pulse-badge 1.4s ease-in-out infinite; }
.status-ok        { background: rgba(22,163,74,.12);   color: #16a34a; }
.status-fail      { background: rgba(220,38,38,.12);   color: #dc2626; }
.status-cancelled { background: rgba(161,104,7,.12);   color: #a16207; }
.status-review    { background: rgba(234,179,8,.12);   color: #854d0e; }

.log-elapsed { font-size: 11px; color: var(--text-muted); }

@media (max-width: 860px) {
  .run-page-layout { flex-direction: column; }
  .run-page-layout .agents-stack { width: 100%; }
  .run-panel { position: static; max-height: none; }
}

/* Current-activity bar */
.run-activity-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: #f0fdfb;
  border-bottom: 1px solid #c7f0ec;
  flex-shrink: 0;
}

.run-activity-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--brand-teal);
  flex-shrink: 0;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.75); }
}

.run-activity-bar.is-done   { background: #f0fdf4; border-bottom-color: #bbf7d0; }
.run-activity-bar.is-failed { background: #fef2f2; border-bottom-color: #fecaca; }
.run-activity-bar.is-review { background: #fefce8; border-bottom-color: #fef08a; }
.run-activity-bar.is-done .run-activity-dot   { animation: none; background: var(--success); }
.run-activity-bar.is-failed .run-activity-dot { animation: none; background: var(--danger); }
.run-activity-bar.is-review .run-activity-dot { animation: pulse-badge 2s ease-in-out infinite; background: #ca8a04; }

.run-activity-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Events feed */
.run-events-feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.run-phase-section { margin-top: 14px; }
.run-phase-section:first-child { margin-top: 0; }

.run-phase-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--brand-dark);
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.run-phase-items { display: flex; flex-direction: column; gap: 2px; padding-left: 4px; }

.run-event {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 0;
  font-size: 13px;
  line-height: 1.55;
}

.run-event-icon {
  flex-shrink: 0;
  width: 16px;
  font-size: 11px;
  padding-top: 2px;
  text-align: center;
}

.run-event-success  .run-event-icon::before { content: '✓'; color: var(--success); }
.run-event-warning  .run-event-icon::before { content: '⚠'; color: #d97706; }
.run-event-error    .run-event-icon::before { content: '✕'; color: var(--danger); }
.run-event-activity .run-event-icon::before { content: '→'; color: var(--brand-teal); }
.run-event-info     .run-event-icon::before { content: '·'; color: var(--text-muted); }

.run-event-success  .run-event-text { color: var(--text); }
.run-event-warning  .run-event-text { color: #92400e; }
.run-event-error    .run-event-text { color: var(--danger); font-weight: 500; }
.run-event-activity .run-event-text { color: var(--text-muted); font-style: italic; }
.run-event-info     .run-event-text { color: var(--text-muted); }

/* Raw log toggle footer */
.run-log-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.btn-link {
  background: none; border: none; cursor: pointer;
  font-size: 12px; color: var(--brand-teal);
  padding: 0; font-family: inherit;
}
.btn-link:hover { text-decoration: underline; }
.run-log-count { font-size: 11px; color: var(--text-muted); }

/* Raw log (collapsible) */
.run-raw-log {
  border-top: 1px solid var(--border);
  background: #0d1117;
  max-height: 260px;
  overflow-y: auto;
  padding: 12px 20px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px; line-height: 1.7; color: #c9d1d9;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: #30363d #0d1117;
}

.run-raw-log::-webkit-scrollbar { width: 6px; }
.run-raw-log::-webkit-scrollbar-track { background: #0d1117; }
.run-raw-log::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }

.log-line { white-space: pre-wrap; word-break: break-all; min-height: 1em; }
.log-line:empty::before { content: '\00a0'; }

.log-cursor {
  display: inline-block;
  width: 7px; height: 13px;
  background: #3fb950;
  border-radius: 1px;
  animation: blink .9s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

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

.log-line-count { font-size: 11px; color: var(--text-muted); }

/* ── Badge overrides ─────────────────────────────────────────────── */
.badge-red { background: #fee2e2; color: #dc2626; }
