:root {
  --font-heading: "Montserrat", "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --font-body: "Plus Jakarta Sans", "Montserrat", system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --success: #6bd35f;
  --warning: #f8d64a;
  --error: #eb5545;
  --info: #3b85f7;
}

html[data-theme="light"] {
  --bg-app: #ffffff;
  --bg-surface-1: #f7f8ff;
  --bg-surface-2: #eee6ff;
  --border-color: #dfd5ef;
  --text-primary: #141425;
  --text-secondary: #3b3b55;
  --text-muted: #676480;
  --primary: #4c18ae;
  --primary-hover: #7302ff;
  --secondary-accent: #04efc4;
  --accent-extra: #ba32ec;
  --imagination-optimo: #1f9f59;
  --imagination-viable: #5ca838;
  --imagination-medio: #b4871f;
  --imagination-jugueton: #c55a26;
  --imagination-locura: #d2374f;
}

html[data-theme="dark"] {
  --bg-app: #0b0b0f;
  --bg-surface-1: #12121a;
  --bg-surface-2: #171725;
  --border-color: #24243a;
  --text-primary: #f2f3ff;
  --text-secondary: #b6b8d6;
  --text-muted: #8c8fb3;
  --primary: #7302ff;
  --primary-hover: #4c18ae;
  --secondary-accent: #04efc4;
  --accent-extra: #ba32ec;
  --imagination-optimo: #6bd35f;
  --imagination-viable: #8dd957;
  --imagination-medio: #f8d64a;
  --imagination-jugueton: #f0a44a;
  --imagination-locura: #eb5545;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-app);
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-surface-1);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.logo {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 24px;
}

.sidebar-brand {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 86%, transparent);
}

.sidebar-logo-wrap {
  width: 100%;
  max-width: 220px;
  min-height: 56px;
  max-height: 96px;
  margin: 0 auto 8px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo {
  display: block;
  width: 100%;
  max-height: 96px;
  object-fit: contain;
  object-position: center;
}

.sidebar-powered {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.25;
  font-style: italic;
  color: var(--text-muted);
}

.sidebar-nav {
  margin-top: 10px;
  flex: 1;
}

.sidebar-footer {
  border-top: 1px solid color-mix(in srgb, var(--border-color) 86%, transparent);
  padding-top: 12px;
  margin-top: 8px;
}

.sidebar-logout-btn {
  width: 100%;
}

.sidebar-user {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-word;
}

.nav-link {
  display: block;
  text-decoration: none;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.nav-link.active,
.nav-link:hover {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
}

.main {
  padding: 20px;
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 10% 10%, color-mix(in srgb, var(--secondary-accent) 20%, transparent), transparent 35%),
    radial-gradient(circle at 90% 90%, color-mix(in srgb, var(--accent-extra) 18%, transparent), transparent 36%),
    var(--bg-app);
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
}

.auth-logo {
  display: block;
  width: 160px;
  margin: 0 auto 12px auto;
  object-fit: contain;
}

.auth-subtitle {
  color: var(--text-secondary);
  margin-top: 6px;
  margin-bottom: 14px;
}

.input-stack {
  display: grid;
  gap: 10px;
}

.badge-role {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge-role-glow {
  color: #fff;
  background: linear-gradient(135deg, #131d5f, #117d8a);
}

.badge-role-client {
  color: #fff;
  background: linear-gradient(135deg, #5a219f, #a12edd);
}

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

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-surface-1);
  color: var(--text-primary);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 22, 0.5);
  z-index: 45;
}

body.sidebar-open {
  overflow: hidden;
}

.page-dashboard {
  position: relative;
}

.page-dashboard::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 220px;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 0%, color-mix(in srgb, var(--secondary-accent) 22%, transparent), transparent 52%),
    radial-gradient(circle at 88% 4%, color-mix(in srgb, var(--accent-extra) 20%, transparent), transparent 54%);
}

.dashboard-shell {
  display: grid;
  gap: 12px;
}

.dashboard-hero {
  position: relative;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--secondary-accent) 35%, var(--border-color));
  background:
    linear-gradient(
      110deg,
      color-mix(in srgb, var(--bg-surface-1) 80%, var(--primary) 20%),
      color-mix(in srgb, var(--bg-surface-1) 75%, var(--secondary-accent) 25%)
    );
}

.dashboard-hero::after {
  content: "";
  position: absolute;
  inset: auto -16% -85% auto;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 22%, transparent);
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  letter-spacing: 0.08em;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--bg-surface-1) 72%, var(--secondary-accent) 28%);
  border: 1px solid color-mix(in srgb, var(--secondary-accent) 40%, var(--border-color));
  border-radius: 999px;
  padding: 6px 12px;
}

.hero-content {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.hero-title {
  margin: 0;
  font-family: var(--font-heading);
}

.hero-subtitle {
  margin: 8px 0 0 0;
  color: var(--text-secondary);
}

.hero-range {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--primary) 40%, var(--border-color));
  background: color-mix(in srgb, var(--bg-surface-1) 78%, var(--primary) 22%);
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
}

.dashboard-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  border-style: dashed;
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border-color));
}

.dashboard-filter-group {
  min-width: 180px;
}

.dashboard-filter-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.dashboard-error {
  color: var(--error);
  font-weight: 600;
  font-size: 0.9rem;
}

.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 12px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--bg-surface-1) 86%, var(--bg-surface-2) 14%),
    var(--bg-surface-1)
  );
  border-color: color-mix(in srgb, var(--primary) 24%, var(--border-color));
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -42px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 15%, transparent);
}

.kpi-quality {
  border-color: color-mix(in srgb, var(--secondary-accent) 36%, var(--border-color));
  background: linear-gradient(
    140deg,
    color-mix(in srgb, var(--bg-surface-1) 78%, var(--secondary-accent) 22%),
    var(--bg-surface-1)
  );
}

.kpi-title {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 8px;
}

.kpi-caption {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.metric-value-emphasis {
  font-size: 2.15rem;
  line-height: 1.1;
  margin: 4px 0 6px 0;
}

.kpi-trend {
  margin-top: 8px;
  font-size: 0.96rem;
  font-weight: 700;
}

.kpi-trend-up {
  color: var(--success);
}

.kpi-trend-down {
  color: var(--error);
}

.quality-gauge {
  width: min(260px, 100%);
  height: auto;
  margin: 4px auto 10px auto;
}

.quality-gauge-svg {
  display: block;
  width: 100%;
  height: auto;
}

.gauge-segment {
  fill: none;
  stroke-width: 16;
  stroke-linecap: round;
}

.gauge-red { stroke: var(--error); }
.gauge-yellow { stroke: var(--warning); }
.gauge-green { stroke: var(--success); }

.gauge-needle {
  stroke: var(--text-primary);
  stroke-width: 4;
  stroke-linecap: round;
  transform-origin: 120px 120px;
  transition: transform 0.4s ease;
}

.gauge-center-dot {
  fill: var(--text-primary);
  stroke: var(--bg-surface-1);
  stroke-width: 2;
}

.quality-gauge-state {
  margin-top: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.quality-gauge-note {
  margin-top: 6px;
  min-height: 38px;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.quality-gauge[data-state="red"] .quality-gauge-state,
.quality-gauge[data-state="empty"] .quality-gauge-state {
  color: var(--error);
}

.quality-gauge[data-state="yellow"] .quality-gauge-state {
  color: color-mix(in srgb, var(--warning) 78%, var(--text-primary) 22%);
}

.quality-gauge[data-state="green"] .quality-gauge-state {
  color: var(--success);
}

.dashboard-panel {
  position: relative;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bg-surface-1) 89%, var(--bg-surface-2) 11%),
    var(--bg-surface-1)
  );
}

.dashboard-panel h3 {
  margin-top: 0;
  margin-bottom: 10px;
  font-family: var(--font-heading);
}

.dashboard-table td {
  color: var(--text-secondary);
}

.dashboard-table tr:hover td {
  background: color-mix(in srgb, var(--bg-surface-2) 76%, var(--secondary-accent) 24%);
  color: var(--text-primary);
}

.podium-track {
  height: 6px;
  margin: 8px 0 12px 0;
  border-radius: 999px;
  background: repeating-linear-gradient(
    90deg,
    color-mix(in srgb, var(--text-muted) 42%, transparent) 0 14px,
    transparent 14px 20px
  );
}

.podium-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.podium-item {
  text-align: center;
}

.podium-name {
  font-weight: 700;
  font-size: 0.83rem;
  color: var(--text-primary);
}

.podium-messages {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.podium-car {
  margin: 8px 0 6px 0;
  font-size: 1rem;
}

.podium-block {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--border-color));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: var(--font-heading);
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
}

.podium-height-1 { height: 92px; }
.podium-height-2 { height: 68px; }
.podium-height-3 { height: 52px; }

.podium-place-1 .podium-block {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--warning) 68%, var(--primary) 32%),
    var(--warning)
  );
  color: var(--text-primary);
}

.podium-place-2 .podium-block {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--info) 54%, var(--text-muted) 46%),
    color-mix(in srgb, var(--info) 68%, var(--bg-surface-1) 32%)
  );
}

.podium-place-3 .podium-block {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--accent-extra) 62%, var(--primary) 38%),
    var(--accent-extra)
  );
}

.users-bars {
  display: grid;
  gap: 8px;
}

.user-bar-row {
  display: grid;
  grid-template-columns: 28px minmax(120px, 1fr) minmax(140px, 2fr) 44px;
  gap: 8px;
  align-items: center;
}

.user-rank {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--bg-surface-2) 70%, var(--primary) 30%);
  color: var(--text-primary);
}

.user-name {
  font-size: 0.84rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-bar-track {
  height: 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border-color) 82%, var(--text-muted) 18%);
  background: color-mix(in srgb, var(--bg-surface-2) 70%, transparent);
  overflow: hidden;
}

.user-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--secondary-accent), var(--primary));
}

.user-value {
  text-align: right;
  font-size: 0.82rem;
  color: var(--text-primary);
  font-weight: 700;
}

.question-count {
  text-align: right;
  font-weight: 700;
  color: var(--text-primary);
}

.card {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
}

.grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
}

.btn-secondary {
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(20, 20, 37, 0.15);
  filter: brightness(1.03);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 3px 10px rgba(20, 20, 37, 0.12);
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  filter: none;
}

.input-field,
.textarea-field,
.select-field {
  width: 100%;
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.textarea-field { min-height: 120px; }

.agent-config-page label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

.agent-advanced-config {
  margin-top: 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-surface-2) 82%, transparent);
  padding: 8px 10px 12px 10px;
}

.agent-advanced-config summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  user-select: none;
}

.agent-advanced-config summary::-webkit-details-marker {
  display: none;
}

.agent-advanced-config summary::before {
  content: "▸";
  margin-right: 8px;
  color: var(--text-secondary);
}

.agent-advanced-config[open] summary::before {
  content: "▾";
}

.agent-advanced-config[open] label:first-of-type {
  margin-top: 12px;
}

.imagination-level-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--bg-surface-2) 85%, transparent);
  color: var(--text-primary);
}

.imagination-slider {
  --imagination-color: var(--imagination-optimo);
  width: 100%;
  appearance: none;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--imagination-optimo) 0%,
    var(--imagination-medio) 50%,
    var(--imagination-locura) 100%
  );
  border: 1px solid var(--border-color);
  outline: none;
}

.imagination-slider[data-level="optimo"],
.imagination-level-pill[data-level="optimo"] {
  --imagination-color: var(--imagination-optimo);
}

.imagination-slider[data-level="viable"],
.imagination-level-pill[data-level="viable"] {
  --imagination-color: var(--imagination-viable);
}

.imagination-slider[data-level="medio"],
.imagination-level-pill[data-level="medio"] {
  --imagination-color: var(--imagination-medio);
}

.imagination-slider[data-level="jugueton"],
.imagination-level-pill[data-level="jugueton"] {
  --imagination-color: var(--imagination-jugueton);
}

.imagination-slider[data-level="locura"],
.imagination-level-pill[data-level="locura"] {
  --imagination-color: var(--imagination-locura);
}

.imagination-level-pill[data-level] {
  color: var(--imagination-color);
  border-color: color-mix(in srgb, var(--imagination-color) 45%, var(--border-color));
  background: color-mix(in srgb, var(--imagination-color) 16%, var(--bg-surface-1));
}

.imagination-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--imagination-optimo) 0%,
    var(--imagination-medio) 50%,
    var(--imagination-locura) 100%
  );
}

.imagination-slider::-webkit-slider-thumb {
  appearance: none;
  margin-top: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--bg-app);
  background: var(--imagination-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.24);
  cursor: pointer;
}

.imagination-slider::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--imagination-optimo) 0%,
    var(--imagination-medio) 50%,
    var(--imagination-locura) 100%
  );
}

.imagination-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--bg-app);
  background: var(--imagination-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.24);
  cursor: pointer;
}

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

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
}

.user-department-checklist {
  display: grid;
  gap: 6px;
  min-width: 180px;
  max-height: 160px;
  overflow-y: auto;
}

.user-department-option {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1.25;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.notifications {
  position: relative;
}

.badge {
  position: absolute;
  right: -4px;
  top: -4px;
  background: var(--accent-extra);
  color: #fff;
  border-radius: 100px;
  font-size: 0.75rem;
  padding: 2px 6px;
}

.notification-panel {
  position: absolute;
  right: 0;
  top: 30px;
  width: 360px;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px;
  z-index: 10;
  display: none;
}

.notification-panel.open { display: block; }

.notification-item {
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.notification-item:hover { background: var(--bg-surface-2); }

.notification-more {
  width: 100%;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
}

.notification-more:hover {
  background: var(--bg-surface-2);
}

.state-pill {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 20, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.modal-backdrop.open {
  display: flex;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid color-mix(in srgb, var(--border-color) 85%, transparent);
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

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

.modal-card {
  position: relative;
  width: min(760px, 92vw);
  max-height: 80vh;
  overflow: auto;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 22px;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

.folder-browser {
  margin-top: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px;
}

.folder-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
}

.folder-item:hover {
  background: var(--bg-surface-2);
}

.row-disabled {
  opacity: 0.5;
}

.row-active td {
  background: color-mix(in srgb, var(--bg-surface-2) 70%, var(--secondary-accent) 30%);
}

.row-clickable {
  cursor: pointer;
}

.row-clickable td {
  transition: background-color 0.15s ease;
}

.row-clickable:hover td {
  background: color-mix(in srgb, var(--bg-surface-2) 78%, transparent);
}

.actions-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-icon {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-surface-1);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}

.btn-icon:hover {
  background: var(--bg-surface-2);
}

.help-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.crud-inline-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr auto;
  gap: 8px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-google span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #fff;
  color: #4285f4;
}

.permissions-layout {
  display: grid;
  grid-template-columns: 0.9fr 1.4fr;
  gap: 12px;
}

.btn-link-like {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.btn-link-like:hover {
  color: var(--primary-hover);
}

.agent-actions {
  margin-top: 10px;
}

.agent-chat-card {
  padding: 0;
  overflow: hidden;
}

.widget-admin-config {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-color);
}

.widget-admin-config h3 { margin: 0; }
.widget-admin-help { margin: 6px 0 14px; color: var(--text-secondary); }
.widget-color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.widget-color-grid label { display: grid; gap: 7px; }
.widget-color-format { margin-left: 4px; color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; letter-spacing: .08em; }
.widget-color-control { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 8px; align-items: center; }
.widget-color-picker { width: 48px; height: 42px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-surface-1); padding: 3px; cursor: pointer; }
.widget-hex-input { margin: 0; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-transform: uppercase; letter-spacing: .04em; }
.widget-hex-input[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 2px color-mix(in srgb, var(--error) 18%, transparent); }
.widget-field-help { margin: 8px 0 14px; color: var(--text-muted); font-size: .82rem; }
.widget-field-help code { color: var(--purple, var(--primary)); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.widget-image-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 16px; }
.widget-image-preview { width: 54px; height: 54px; border-radius: 999px; display: grid; place-items: center; overflow: hidden; color: #fff; background: var(--accent-extra); font-weight: 800; }
.widget-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.widget-snippet { min-height: 76px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.state-pill.status-success { color: #166534; background: #dcfce7; border-color: #86efac; }

.agent-chat-shell {
  --widget-header-color: #6750A4;
  --widget-background-color: #F7F7FB;
  display: grid;
  grid-template-rows: auto auto minmax(320px, 1fr) auto;
  min-height: 560px;
}

.agent-chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  color: #fff;
  background: var(--widget-header-color);
}

.agent-chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-chat-brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  border: 2px solid color-mix(in srgb, #fff 82%, transparent);
}

.agent-chat-title-main {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
}

.agent-chat-title-sub {
  margin-top: 2px;
  font-size: 0.8rem;
  color: color-mix(in srgb, #fff 84%, transparent);
}

.agent-chat-refresh-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, #fff 45%, transparent);
  background: color-mix(in srgb, #fff 12%, transparent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.agent-chat-refresh-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.agent-chat-refresh-btn:hover {
  background: color-mix(in srgb, #fff 18%, transparent);
}

.agent-chat-refresh-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, #fff 84%, transparent);
  outline-offset: 2px;
}

.agent-chat-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid color-mix(in srgb, #fff 26%, var(--border-color));
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface-1);
}

.agent-config-page .agent-chat-group-label {
  display: inline-block;
  margin: 0;
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.agent-select.agent-chat-group-select {
  margin: 0;
  font-size: 0.9rem;
  padding: 8px 10px;
}

.agent-chat-log {
  height: 360px;
  overflow-y: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--widget-background-color);
}

.agent-chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-app);
}

.agent-chat-input {
  width: 100%;
  min-height: 40px;
  max-height: 150px;
  resize: none;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-surface-1);
  color: var(--text-primary);
  padding: 9px 12px;
  line-height: 1.35;
  font: inherit;
}

.agent-chat-input::placeholder {
  color: var(--text-muted);
}

.agent-chat-send-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: var(--widget-header-color);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.agent-chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.agent-chat-send-btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

.agent-chat-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.agent-chat-send-btn:focus-visible,
.agent-chat-input:focus-visible {
  outline: 2px solid var(--secondary-accent);
  outline-offset: 2px;
}

.agent-chat-row {
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--border-color) 88%, transparent);
  margin: 0;
}

.agent-chat-row-user {
  background: color-mix(in srgb, var(--widget-header-color) 14%, #fff);
  border-color: color-mix(in srgb, var(--widget-header-color) 26%, transparent);
}

.agent-chat-row-assistant {
  background: color-mix(in srgb, var(--bg-surface-1) 92%, var(--bg-app));
}

.agent-chat-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.agent-markdown {
  color: var(--text-primary);
  line-height: 1.45;
}

.agent-markdown pre {
  margin: 8px 0;
  padding: 8px;
  border-radius: 6px;
  background: var(--bg-surface-2);
  overflow-x: auto;
  border: 1px solid color-mix(in srgb, var(--border-color) 85%, transparent);
}

.agent-markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.agent-markdown ul {
  margin: 6px 0 6px 18px;
}

.agent-markdown blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 3px solid var(--border-color);
  color: var(--text-secondary);
}

.agent-markdown p {
  margin: 0;
}

@media (max-width: 700px) {
  .widget-color-grid {
    grid-template-columns: 1fr;
  }

  .agent-chat-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .agent-chat-group-label {
    white-space: normal;
  }
}

@media (max-width: 1100px) {
  .grid-5 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .hero-content { flex-direction: column; align-items: flex-start; }
  .dashboard-kpi-grid { grid-template-columns: 1fr; }
  .dashboard-filter-group { min-width: 100%; }
  .user-bar-row {
    grid-template-columns: 24px minmax(90px, 1fr) minmax(90px, 2fr) 36px;
    gap: 6px;
  }
  .permissions-layout { grid-template-columns: 1fr; }
  .crud-inline-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .main {
    padding: 16px;
  }

  .row-between {
    justify-content: flex-end;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 320px);
    padding: 20px 14px;
    border-right: 1px solid var(--border-color);
    border-bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 50;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

.kpi-row-between,
.panel-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dashboard-coverage-warning {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--border-color));
  background: color-mix(in srgb, var(--warning) 12%, var(--bg-surface-1));
  color: var(--text-primary);
  font-size: 13px;
}

.pie-wrap {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.pie-main svg {
  width: 180px;
  height: 180px;
}

.pie-total-label {
  fill: var(--text-muted);
  font-size: 12px;
}

.pie-total-value {
  fill: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
}

.pie-legend {
  flex: 1;
  min-width: 230px;
}

.pie-legend-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}

.pie-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.hbar-wrap,
.vbar-wrap {
  min-height: 180px;
}

.hbar-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 2fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
}

.hbar-track {
  height: 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border-color) 72%, transparent);
  overflow: hidden;
}

.hbar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #1f6f8b, #99f3bd);
}

.vbar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 220px;
}

.vbar-item {
  display: grid;
  grid-template-rows: auto 160px auto;
  gap: 5px;
  justify-items: center;
}

.vbar-track {
  width: 100%;
  max-width: 22px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border-color) 72%, transparent);
  display: flex;
  align-items: end;
  overflow: hidden;
}

.vbar-fill {
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg, #0e7490, #34d399);
}

.vbar-value {
  font-size: 11px;
  color: var(--text-secondary);
}

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

.chart-empty {
  padding: 20px 0;
  text-align: center;
  color: var(--text-muted);
}

.dashboard-table-scroll {
  max-height: 360px;
  overflow: auto;
}

.dashboard-table-scroll-large {
  max-height: 520px;
  overflow: auto;
}

.dashboard-pagination {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.message-row-session-start td {
  border-top: 2px solid color-mix(in srgb, var(--primary) 35%, var(--border-color));
}

.message-row-grouped td {
  border-top: 1px dashed color-mix(in srgb, var(--border-color) 85%, transparent);
}
