/* ============================================================
   Components — buttons, cards/panels, forms, tables, badges,
   alerts, tooltips, modal, toast (AGENTiX)
   ============================================================ */

/* Buttons -------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Primary: black, cyan glow on hover */
.btn-primary {
  background: var(--black);
  color: var(--white);
}
.btn-primary:not(:disabled):hover {
  box-shadow: 0 0 0 1px hsl(190 100% 50% / 0.6), 0 8px 24px hsl(190 100% 50% / 0.25);
  border-color: hsl(190 100% 50% / 0.6);
}

/* Secondary: white, cyan border on hover */
.btn-secondary {
  background: var(--white);
  color: var(--black);
  border-color: var(--gray-border);
}
.btn-secondary:not(:disabled):hover { border-color: hsl(190 100% 50% / 0.6); }

/* Accent: cyan (important actions only) */
.btn-accent {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-accent:not(:disabled):hover { filter: brightness(1.05); box-shadow: 0 8px 24px hsl(190 100% 50% / 0.35); }

.btn-danger {
  background: var(--white);
  color: var(--danger);
  border-color: var(--gray-border);
}
.btn-danger:not(:disabled):hover { border-color: var(--danger); background: #fef2f2; }

.btn-ghost { background: transparent; color: hsl(var(--muted-foreground)); padding: 10px 14px; }
.btn-ghost:not(:disabled):hover { color: var(--black); background: var(--gray-soft); }

.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 15px; }
.btn-block { width: 100%; }

/* On dark surfaces */
.dark-section .btn-secondary {
  background: transparent;
  color: var(--on-dark);
  border-color: var(--dark-border);
}
.dark-section .btn-secondary:hover { border-color: var(--cyan); }

/* Icon button ---------------------------------------------------- */
.icon-btn {
  width: 38px; height: 38px;
  display: inline-grid; place-items: center;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-border);
  background: var(--white);
  color: var(--black);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.icon-btn:hover { border-color: hsl(190 100% 50% / 0.5); }
.icon-btn svg { width: 18px; height: 18px; }

/* Cards / panels ------------------------------------------------- */
.card,
.panel {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  color: var(--black);
  min-width: 0;
}
.card-hover,
.panel-hover {
  transition: border-color var(--dur-slow) var(--ease),
              box-shadow var(--dur-slow) var(--ease),
              transform var(--dur-slow) var(--ease);
}
.card-hover:hover,
.panel-hover:hover {
  border-color: hsl(190 100% 50% / 0.3);
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}
.card-header { margin-bottom: var(--space-lg); }
.card-title { font-size: 18px; font-weight: 700; }
.card-subtitle { color: hsl(var(--muted-foreground)); font-size: 14px; margin-top: 4px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.panel-head h2,
.panel-head h3 {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.panel-label,
.eyebrow,
.brand-kicker,
.status-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
}
.panel-copy {
  color: hsl(var(--muted-foreground));
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: var(--space-md);
}
.panel-tag,
.hero-badges span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--black);
  background: var(--gray-soft);
  border: 1px solid var(--gray-border);
  white-space: nowrap;
}

/* Hero panel (dark AGENTiX section) ------------------------------ */
.hero-panel {
  grid-column: 1 / -1;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-lg);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  background: var(--dark-bg);
  color: var(--on-dark);
  border: 1px solid var(--dark-border);
}
.hero-panel h2,
.hero-copy h2 { color: var(--on-dark); font-size: clamp(1.8rem, 3vw, 2.6rem); font-weight: 800; letter-spacing: -0.025em; max-width: 16ch; margin: 8px 0 0; }
.hero-panel .panel-label { color: rgba(255, 255, 255, 0.5); }
.hero-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-panel .hero-badges span { background: rgba(255, 255, 255, 0.06); border-color: var(--dark-border); color: var(--on-dark); }

/* Stat / metric tiles ------------------------------------------- */
.stat-grid,
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-lg);
}
.metrics-strip { grid-column: 1 / -1; }
.metric-card {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}
.stat-label,
.metric-card span { font-size: 13px; font-weight: 600; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value,
.metric-card strong { display: block; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; margin-top: 8px; color: var(--black); }
.stat-value.accent { color: var(--cyan); }
.stat-meta,
.metric-card small { font-size: 13px; color: hsl(var(--muted-foreground)); margin-top: 8px; }
.metric-card small { margin-left: 6px; }
.metric-card em { font-style: normal; color: var(--success-ink); font-weight: 600; }

.trend-panel { min-height: 420px; }
.chart-stage {
  height: 320px;
  border-radius: var(--radius-md);
  padding: 10px;
  background: var(--gray-soft);
  border: 1px solid var(--gray-border);
}
.chart-stage canvas { width: 100%; height: 100%; }

.status-item,
.insight-card {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: var(--gray-soft);
  border: 1px solid var(--gray-border);
}
.insight-card h4 { margin: 6px 0 0; font-size: 16px; font-weight: 700; }
.insight-card p { color: hsl(var(--muted-foreground)); font-size: 14px; line-height: 1.6; }
.status-top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.status-top strong { font-weight: 700; }

.progress {
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--gray-border);
  overflow: hidden;
}
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--black); }
.progress.green i { background: var(--success); }
.progress.lime i { background: var(--cyan); }
.progress.red i { background: var(--danger); }
.progress.amber i { background: var(--warning); }

/* Forms ---------------------------------------------------------- */
.field { margin-bottom: var(--space-md); }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.field-hint { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 6px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 6px; min-height: 0; }

.input,
.select,
.textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  outline: none;
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(190 100% 50% / 0.15);
}
.input.has-error,
.select.has-error { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 96px; }

.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }

/* Kilken label-wrapped forms */
.auth-form,
.settings-form {
  display: grid;
  gap: var(--space-md);
}
.auth-form label,
.settings-form label {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.auth-form label > span,
.settings-form label > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--black);
}
.settings-form > .btn,
.auth-form > .btn { justify-self: start; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-md);
}
.form-response {
  min-height: 1.4em;
  margin: 0;
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  line-height: 1.5;
}
.form-response:empty { min-height: 0; }
.form-response.success { color: var(--success-ink); }
.form-response.error { color: var(--danger); }

/* Badges --------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--gray-border);
  background: var(--gray-soft);
  color: var(--black);
  white-space: nowrap;
}
.badge-dot::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.badge-active,
.badge-success { color: var(--success-ink); background: var(--success-tint); border-color: var(--success-edge); }
.badge-inactive,
.badge-warning { color: var(--warning-ink); background: var(--warning-tint); border-color: var(--warning-edge); }
.badge-suspended,
.badge-danger { color: var(--danger-ink); background: var(--danger-tint); border-color: var(--danger-edge); }
.badge-role { color: var(--black); background: var(--gray-soft); }
.badge-super,
.badge-info { color: var(--cyan-ink); background: var(--cyan-tint); border-color: var(--cyan-edge); }

/* Alerts / flash ------------------------------------------------- */
.flash-stack { display: grid; gap: 10px; margin-bottom: var(--space-lg); }
.flash,
.setup-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-border);
  border-left: 3px solid var(--cyan);
  background: var(--white);
  color: var(--black);
  font-size: 14px;
  line-height: 1.5;
  animation: fadeUp 0.3s var(--ease);
}
.flash-success { border-left-color: var(--success); background: var(--success-tint); border-color: var(--success-edge); border-left-color: var(--success); color: var(--success-ink); }
.flash-error,
.setup-alert { border-color: var(--danger-edge); border-left-color: var(--danger); background: var(--danger-tint); color: var(--danger-ink); }
.flash-warning { border-color: var(--warning-edge); border-left-color: var(--warning); background: var(--warning-tint); color: var(--warning-ink); }
.flash-info { border-left-color: var(--cyan); }
.setup-alert { display: block; }
.setup-alert h2 { font-size: 18px; color: inherit; margin-bottom: 6px; }
.setup-alert p { color: inherit; }

/* Console / code ------------------------------------------------- */
.update-console,
.code-block {
  background: var(--dark-card);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--dark-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}
.update-console {
  min-height: 74px;
  display: flex;
  align-items: center;
  white-space: pre-wrap;
  word-break: break-word;
}
.code-block {
  overflow-x: auto;
  white-space: pre;
  max-height: 420px;
  overflow-y: auto;
}

/* Tables --------------------------------------------------------- */
.table-wrap,
.user-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-md);
  background: var(--white);
}
.user-table-wrap { margin-top: var(--space-lg); }
.table,
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th,
.data-table th {
  background: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  padding: 10px 14px;
  white-space: nowrap;
  border-bottom: 1px solid var(--gray-border);
}
.table tbody td,
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-border);
  vertical-align: middle;
  color: var(--black);
  white-space: nowrap;
}
.table tbody tr:last-child td,
.data-table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover,
.data-table tbody tr:hover { background: var(--gray-hover); }
.data-table td input,
.data-table td select { min-width: 140px; padding: 8px 12px; }
.data-table td select { padding-right: 34px; background-position: right 12px center; }
.table .cell-muted,
.data-table .cell-muted { color: var(--gray-muted-text); }
.table .cell-actions,
.data-table .cell-actions { text-align: right; white-space: nowrap; }

/* Tabs ----------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--gray-border);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
}
.tab {
  padding: 12px 18px;
  font-weight: 600;
  font-size: 14px;
  color: hsl(var(--muted-foreground));
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  background: none;
  border-top: none; border-left: none; border-right: none;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--black); }
.tab.active { color: var(--black); border-bottom-color: var(--cyan); }

/* Segmented control (AGENTiX pill toggle) ------------------------ */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-sm);
  background: var(--gray-soft);
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segmented button:hover { color: var(--black); }
.segmented button.active { background: var(--white); color: var(--black); box-shadow: var(--shadow-soft); }

/* Info tooltip --------------------------------------------------- */
.header-with-info {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.info-tip {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--gray-border);
  border-radius: 50%;
  background: var(--white);
  color: var(--gray-muted-text);
  font: 700 11px/1 var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
  cursor: help;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.info-tip::after {
  content: attr(data-info);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 9px);
  transform: translate(-50%, 4px);
  width: max-content;
  max-width: 260px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--black);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.25);
  color: var(--white);
  font: 500 12px/1.5 var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
}
.info-tip:hover,
.info-tip:focus-visible {
  border-color: hsl(190 100% 50% / 0.6);
  color: var(--black);
  outline: none;
}
.info-tip:hover::after,
.info-tip:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* Skeleton loaders ----------------------------------------------- */
.skeleton-line {
  position: relative;
  display: block;
  overflow: hidden;
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--gray-border);
}
.skeleton-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  animation: skeletonSweep 1.4s ease-in-out infinite;
}

/* Modal ---------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  z-index: 1000;
  animation: fadeIn 0.2s var(--ease);
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
  animation: fadeUp 0.3s var(--ease);
}
.modal-header { padding: var(--space-lg) var(--space-lg) 0; }
.modal-title { font-size: 20px; font-weight: 700; }
.modal-body { padding: var(--space-lg); }
.modal-footer {
  padding: var(--space-md) var(--space-lg) var(--space-lg);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* Toast ---------------------------------------------------------- */
#toast-root {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--black);
  color: var(--white);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.25);
  animation: fadeUp 0.3s var(--ease);
  font-size: 14px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--cyan); }

/* Spinner -------------------------------------------------------- */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

/* Empty state ---------------------------------------------------- */
.empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-lg);
  color: hsl(var(--muted-foreground));
}
.empty-title { font-weight: 700; color: var(--black); margin-bottom: 6px; }
.empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto var(--space-md);
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--cyan-tint);
  color: var(--cyan-ink);
}
.empty-icon svg { width: 22px; height: 22px; }

/* Divider -------------------------------------------------------- */
.divider { height: 1px; background: var(--gray-border); border: none; margin: var(--space-lg) 0; }

/* Page-level grids ----------------------------------------------- */
.overview-grid,
.manager-grid,
.insight-grid,
.status-list {
  display: grid;
  gap: var(--space-lg);
}
.overview-grid { grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr); }
.manager-grid { grid-template-columns: minmax(0, 1fr); }
.account-panel,
.manager-grid .panel { padding: var(--space-xl); }
.account-panel { max-width: 880px; }


/* Status / error page -------------------------------------------- */
.status-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-lg);
  background: var(--dark-bg);
  color: var(--on-dark);
  position: relative;
  overflow: hidden;
}
.status-card {
  position: relative;
  z-index: 1;
  width: min(100%, 440px);
  padding: var(--space-2xl);
  border-radius: var(--radius-lg);
  background: var(--dark-card);
  border: 1px solid var(--dark-border);
  text-align: center;
}
.status-card .status-eyebrow { color: var(--dark-muted-text); }
.status-card h1 {
  margin: var(--space-md) 0 8px;
  font-size: 64px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--on-dark);
}
.status-card p { color: var(--dark-muted-text); margin-bottom: var(--space-xl); }

@media (max-width: 1080px) {
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .hero-panel { flex-direction: column; align-items: stretch; }
  .panel,
  .metric-card,
  .account-panel,
  .manager-grid .panel { padding: var(--space-md); }
  .settings-form > .btn,
  .auth-form > .btn { justify-self: stretch; }
  .data-table th,
  .data-table td { padding: 10px 12px; }
}
