:root {
  --bg: #0b0f19;
  --surface: #121829;
  --surface-2: #1a2236;
  --border: #2a3550;
  --text: #eef2ff;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.18), transparent 35%),
    radial-gradient(circle at 80% 0%, rgba(217, 70, 239, 0.12), transparent 30%),
    var(--bg);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(420px, 92vw);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.logo-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--gradient);
  display: grid;
  place-items: center;
  font-weight: 800;
}

h1, h2, h3 {
  letter-spacing: -0.02em;
}

h1 {
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

label {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(99, 102, 241, 0.35);
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
}

.btn-primary {
  background: var(--gradient);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
}

.error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  display: none;
}

.error.visible {
  display: block;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.dashboard-intro {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 0 0 1.25rem;
  max-width: 72ch;
}

.section-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.75rem 0 1.25rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.section-divider::before,
.section-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.dashboard-summary {
  margin-bottom: 1.5rem;
  border-color: rgba(99, 102, 241, 0.25);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(14, 165, 233, 0.03));
}

.summary-header {
  margin-bottom: 1rem;
}

.summary-header h2 {
  margin: 0 0 0.15rem;
  font-size: 1.15rem;
}

.summary-highlights {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.summary-highlight {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.summary-highlight-label {
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.25rem;
}

.summary-highlight-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.summary-highlight-value.positive {
  color: var(--success);
}

.summary-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.summary-point {
  position: relative;
  padding: 0.65rem 0.85rem 0.65rem 1.75rem;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.35);
  font-size: 0.9rem;
  line-height: 1.45;
}

.summary-point::before {
  content: "•";
  position: absolute;
  left: 0.75rem;
  color: var(--muted);
}

.summary-point--positive {
  border-left: 3px solid var(--success);
}

.summary-point--warn {
  border-left: 3px solid #f59e0b;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
}

.kpi-value.positive {
  color: var(--success);
}

.kpi-value.warn,
td.warn {
  color: #fbbf24;
}

.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: 0.2s ease;
  cursor: pointer;
}

.client-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.client-card h3 {
  margin-bottom: 0.35rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-meta { background: rgba(24, 119, 242, 0.15); color: #93c5fd; }
.badge-google { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.badge-tiktok { background: rgba(236, 72, 153, 0.15); color: #f9a8d4; }
.badge-linkedin { background: rgba(14, 165, 233, 0.15); color: #7dd3fc; }

.tracked-campaigns-card {
  border: 1px solid rgba(34, 197, 94, 0.25);
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.06), transparent 48%);
}

.tracked-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.tracked-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.roas-view-toggle {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.roas-view-toggle--top {
  opacity: 0.72;
}

.roas-view-toggle--top:hover,
.roas-view-toggle--top:focus-within {
  opacity: 1;
}

.roas-view-toggle--top .roas-view-btn {
  min-width: 38px;
  padding: 0.35rem 0.55rem;
  font-size: 0.72rem;
}

.roas-view-btn {
  border: 0;
  border-radius: 7px;
  padding: 0.45rem 0.7rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.roas-view-btn:hover {
  color: var(--text);
}

.roas-view-btn.active {
  color: #fff;
  background: var(--gradient);
  box-shadow: 0 3px 12px rgba(99, 102, 241, 0.25);
}

.tracked-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.tracked-campaigns-card[data-roas-view="any"] .roas-last,
.tracked-campaigns-card[data-roas-view="last"] .roas-any {
  display: none;
}

.row-tracked td:first-child {
  color: #bbf7d0;
}

.muted {
  color: #94a3b8;
}

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

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

th, td {
  text-align: left;
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  place-items: center;
  z-index: 100;
  padding: 1rem;
}

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

.modal {
  width: min(520px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.share-box {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-top: 1rem;
}

.share-box code {
  display: block;
  word-break: break-all;
  color: #c4b5fd;
  margin: 0.5rem 0;
}

.chart-container {
  height: 280px;
  position: relative;
}

.wallet-card {
  border-color: rgba(34, 197, 94, 0.35);
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.08), rgba(99, 102, 241, 0.06));
}

.integration-panel {
  margin-top: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
}

.integration-panel h3 {
  margin-bottom: 0.75rem;
}

.integration-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.success { background: var(--success); }
.status-dot.error { background: var(--danger); }
.status-dot.pending { background: var(--warning); }

.help-steps {
  margin: 1rem 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.help-steps li {
  margin-bottom: 0.35rem;
}

.sync-result {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: #86efac;
  display: none;
}

.sync-result.visible {
  display: block;
}

.hidden {
  display: none !important;
}

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

.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  align-items: center;
  justify-content: flex-end;
}

.toolbar-sync {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding-right: 0.65rem;
  margin-right: 0.15rem;
  border-right: 1px solid var(--border);
}

.toolbar-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-right: 0.15rem;
}

.btn-sync {
  padding: 0.28rem 0.55rem;
  font-size: 0.76rem;
  font-weight: 500;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #c7d2fe;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.15s ease;
}

.btn-sync:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
}

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

.btn-sync.sync-ok {
  border-color: rgba(34, 197, 94, 0.45);
  color: #86efac;
}

.btn-sync.sync-err {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.sync-toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  max-width: 360px;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: none;
}

.sync-toast.visible {
  display: block;
}

.sync-toast.error {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.period-bar {
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
}

.period-bar--compact .period-bar-header {
  margin-bottom: 0.6rem;
}

.period-header-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.period-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.period-bar--compact .period-presets {
  margin-bottom: 0;
}

.period-bar--compact .period-inputs {
  margin-bottom: 0;
}

.period-calendar-body {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.2s ease;
  max-height: 420px;
  opacity: 1;
  margin-top: 0.75rem;
}

.period-calendar-body--collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

.period-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.period-summary {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.2rem;
}

.period-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.period-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.85rem;
  font-size: 0.875rem;
}

.period-date-input {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: inherit;
}

.period-calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-weight: 600;
  text-transform: capitalize;
  max-width: 320px;
}

.period-calendar-grid {
  max-width: 320px;
}

.cal-weekdays,
.cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0.25rem 0;
}

.cal-day {
  border: none;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  padding: 0.45rem 0;
  font-size: 0.82rem;
  cursor: pointer;
}

.cal-day:hover {
  background: rgba(99, 102, 241, 0.15);
}

.cal-day--in-range {
  background: rgba(99, 102, 241, 0.12);
}

.cal-day--start,
.cal-day--end {
  background: rgba(99, 102, 241, 0.85);
  color: #fff;
  font-weight: 600;
}

.cal-day--today {
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.6);
}

.cal-day--empty {
  pointer-events: none;
}

.period-hint {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
}

.target-field {
  display: none;
}

.real-revenue-card {
  border: 1px solid rgba(34, 197, 94, 0.35);
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.07), rgba(99, 102, 241, 0.04));
}

.reco-panel {
  border-color: rgba(99, 102, 241, 0.3);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.06), rgba(14, 165, 233, 0.04));
}

.reco-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.reco-obj {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.18);
  color: #c7d2fe;
}

.reco-obj-warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

.reco-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.rec-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--bg, rgba(15, 23, 42, 0.4));
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
}

.rec-item.rec-high { border-left-color: var(--danger); }
.rec-item.rec-medium { border-left-color: var(--warning); }
.rec-item.rec-low { border-left-color: var(--success); }
.rec-item.rec-done { opacity: 0.6; }

.rec-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}

.rec-action {
  font-weight: 700;
  font-size: 0.9rem;
}

.rec-entity {
  font-size: 0.8rem;
  color: var(--muted);
}

.rec-reason {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.rec-budget {
  font-weight: 600;
  color: #c7d2fe;
  white-space: nowrap;
}

.rec-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.rec-ok {
  color: #86efac;
  font-weight: 600;
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .dashboard-toolbar {
    width: 100%;
    justify-content: flex-start;
  }
  .toolbar-sync {
    width: 100%;
    border-right: none;
    padding-right: 0;
    margin-right: 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
  }
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .summary-highlights {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .rec-item {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 560px) {
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .summary-highlights {
    grid-template-columns: 1fr;
  }
  .period-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ——— Assistant IA (chatbot) ——— */
#ai-chat-root {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  font-family: Inter, system-ui, sans-serif;
}

.ai-chat-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.15rem;
  border: none;
  border-radius: 999px;
  background: var(--gradient);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(99, 102, 241, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.ai-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(99, 102, 241, 0.5);
}

.ai-chat-toggle-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.ai-chat-panel {
  display: none;
  position: absolute;
  bottom: calc(100% + 0.85rem);
  right: 0;
  width: min(440px, calc(100vw - 1.5rem));
  height: min(580px, calc(100vh - 6rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  flex-direction: column;
  overflow: hidden;
}

.ai-chat-panel.open {
  display: flex;
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.14), rgba(139, 92, 246, 0.06));
  flex-shrink: 0;
}

.ai-chat-header-text strong {
  font-size: 0.95rem;
}

.ai-chat-subtitle {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.ai-chat-close-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.ai-chat-close-btn:hover {
  background: var(--border);
  color: var(--text);
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 0;
}

.ai-chat-bubble {
  max-width: 88%;
  padding: 0.75rem 0.95rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.ai-chat-bubble.thinking {
  opacity: 0.65;
  font-style: italic;
}

.ai-chat-bubble.ai-chat-warn {
  border-color: rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.1);
  color: #fcd34d;
  font-size: 0.8rem;
  max-width: 100%;
}

.ai-chat-footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.ai-chat-error {
  display: none;
  margin-bottom: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.8rem;
}

.ai-chat-error.visible {
  display: block;
}

.ai-chat-form {
  margin: 0;
}

.ai-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ai-chat-composer:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.ai-chat-composer textarea {
  flex: 1;
  width: auto;
  min-width: 0;
  min-height: 24px;
  max-height: 120px;
  margin: 0;
  padding: 0.45rem 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
  outline: none;
  box-shadow: none;
}

.ai-chat-composer textarea:focus {
  outline: none;
  border: none;
  box-shadow: none;
}

.ai-chat-composer textarea::placeholder {
  color: #64748b;
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: var(--gradient);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.ai-chat-send:hover:not(:disabled) {
  transform: scale(1.04);
}

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

.ai-chat-hint {
  margin: 0.45rem 0 0 0.35rem;
  font-size: 0.7rem;
  color: #64748b;
}

.ai-chat-action-card {
  align-self: stretch;
  margin-top: 0.25rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(99, 102, 241, 0.45);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(139, 92, 246, 0.06));
}

.ai-chat-action-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #c7d2fe;
  margin-bottom: 0.4rem;
}

.ai-chat-action-summary {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 0.75rem;
}

.ai-chat-action-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  #ai-chat-root {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
  }

  .ai-chat-panel {
    width: 100%;
    right: 0;
    height: min(70vh, 520px);
  }

  .ai-chat-toggle-label {
    display: none;
  }

  .ai-chat-toggle {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
}

/* ——— Wenov agency overview ——— */
.agency-kpi-row {
  margin-bottom: 0;
}

.kpi-card--alert {
  border-color: rgba(248, 113, 113, 0.45);
}

.agency-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin: 1.75rem 0 0.85rem;
}

.agency-alerts {
  padding: 1rem 1.25rem;
}

.agency-alert-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.agency-alert-link {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.agency-alert-link:hover {
  border-color: rgba(196, 181, 253, 0.45);
  background: rgba(255, 255, 255, 0.03);
}

.agency-alert-level {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
}

.agency-alert--critical .agency-alert-level,
.agency-alert--critical {
  color: #fecaca;
}

.agency-alert--critical .agency-alert-level {
  background: rgba(239, 68, 68, 0.2);
}

.agency-alert--warning .agency-alert-level,
.agency-alert--warning {
  color: #fde68a;
}

.agency-alert--warning .agency-alert-level {
  background: rgba(245, 158, 11, 0.2);
}

.agency-clients-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.agency-client-card {
  border-left: 3px solid transparent;
}

.agency-client-card.status-critical {
  border-left-color: #f87171;
}

.agency-client-card.status-warning {
  border-left-color: #fbbf24;
}

.agency-client-card.status-ok {
  border-left-color: #34d399;
}

.agency-client-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.agency-status {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.agency-status.status-critical {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
}

.agency-status.status-warning {
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
}

.agency-status.status-ok {
  background: rgba(16, 185, 129, 0.15);
  color: #86efac;
}

.agency-client-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.agency-primary {
  margin: 0;
  font-size: 0.9rem;
}

.agency-card-alerts {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.agency-card-alerts li {
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.agency-sync-status {
  padding: 1rem 1.25rem;
}

.agency-loading {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(7, 10, 20, 0.76);
  backdrop-filter: blur(5px);
}

.agency-loading.hidden {
  display: none;
}

.agency-loading-card {
  width: min(420px, 100%);
  padding: 1.5rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid rgba(196, 181, 253, 0.35);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.agency-loading-card strong {
  display: block;
  margin-top: 0.9rem;
  font-size: 1.05rem;
}

.agency-loading-card p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.agency-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border: 3px solid rgba(196, 181, 253, 0.22);
  border-top-color: #c4b5fd;
  border-radius: 50%;
  animation: agency-spin 0.75s linear infinite;
}

.agency-spinner--button {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin: 0 0.35rem 0 0;
  border-width: 2px;
  vertical-align: -2px;
}

body.agency-is-loading {
  overflow: hidden;
}

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

@media (prefers-reduced-motion: reduce) {
  .agency-spinner {
    animation-duration: 1.5s;
  }
}
