:root {
  --blue: #0057ff;
  --blue-dark: #003dc4;
  --blue-soft: #eaf1ff;
  --cyan: #0fb7d5;
  --green: #18b981;
  --purple: #7c3cff;
  --text: #10182f;
  --muted: #667085;
  --line: #e6eaf2;
  --bg: #f7f9fc;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(16, 24, 47, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 74px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 330px 1fr 330px;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 30px;
  font-size: 22px;
  font-weight: 800;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand span {
  color: var(--blue);
}

.search {
  display: flex;
  justify-content: center;
}

.search-box {
  width: 70%;
  height: 44px;
  border: 1px solid #d8deea;
  border-radius: 10px;
  background: #fbfcff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  color: #98a2b3;
  font-size: 14px;
}

.user-zone {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  padding: 0 28px;
}

.icon-wrap {
  position: relative;
  color: #172554;
}

.notif {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #0b3fbf;
  color: white;
  font-size: 11px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--blue-dark);
}

.user-name {
  font-weight: 700;
  font-size: 14px;
}

.user-role {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.sidebar {
  padding: 104px 28px 28px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.rightbar {
  padding: 104px 28px 28px;
  border-left: 1px solid var(--line);
  background: #ffffff;
  position: relative;
}

.main {
  padding: 104px 30px 30px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 22px;
}

.spark {
  color: var(--blue);
}

.agent-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.agent-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 80px;
  box-shadow: 0 6px 20px rgba(16, 24, 47, 0.04);
  cursor: pointer;
  transition: 0.2s;
}

.agent-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.agent-card.active {
  background: linear-gradient(135deg, #0057ff, #003dc4);
  color: white;
  border-color: transparent;
  box-shadow: 0 18px 40px rgba(0, 87, 255, 0.25);
}

.agent-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--blue-soft);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.agent-card.active .agent-icon {
  background: rgba(255, 255, 255, 0.16);
  color: white;
}

.agent-name {
  font-weight: 800;
  line-height: 1.25;
}

.agent-check {
  margin-left: auto;
  width: 22px;
  height: 22px;
  background: white;
  color: var(--blue);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
}

.agent-card.active .agent-check {
  display: flex;
}

.promo {
  margin-top: 28px;
  background: linear-gradient(135deg, #eef6ff, #f8fbff);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  gap: 14px;
  align-items: center;
}

.promo-img {
  width: 70px;
  height: 70px;
  border-radius: 18px;
  background: linear-gradient(135deg, #003dc4, #041236);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex: none;
}

.promo h3 {
  margin: 0 0 6px;
  color: #12326d;
  font-size: 17px;
}

.promo p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.promo a {
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
}

.collapse {
  margin-top: 110px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  color: #344054;
  font-size: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.dashboard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}

.dashboard-head h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.8px;
}

.actions {
  display: flex;
  gap: 14px;
}

.btn {
  height: 42px;
  border-radius: 9px;
  border: 1px solid #d5ddeb;
  background: white;
  color: #173b82;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
  user-select: none;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  opacity: 0.8;
}

.btn.primary {
  background: linear-gradient(135deg, #0057ff, #003dc4);
  border-color: transparent;
  color: white;
  box-shadow: 0 14px 28px rgba(0, 87, 255, 0.22);
}

.btn.login-btn,
.btn.logout-btn {
  min-width: 150px;
}

.btn.logout-btn {
  background: #f8fafc;
  border-color: #d8e2f0;
  color: #0f172a;
}

.auth-error {
  padding: 120px 30px;
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
}

.auth-error h1 {
  margin-bottom: 18px;
  font-size: 32px;
}

.auth-error p {
  margin-bottom: 24px;
  color: var(--muted);
  line-height: 1.7;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.kpi {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 8px 22px rgba(16, 24, 47, 0.05);
}

.kpi-top {
  display: flex;
  gap: 16px;
  align-items: center;
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-blue {
  background: #e7f0ff;
  color: #0057ff;
}

.kpi-green {
  background: #def7ec;
  color: #0b8a5a;
}

.kpi-purple {
  background: #efe7ff;
  color: #7c3cff;
}

.kpi-cyan {
  background: #dff8fb;
  color: #0fb7d5;
}

.kpi-title {
  font-size: 14px;
  color: #344054;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.8px;
}

.growth {
  margin-top: 8px;
  font-size: 13px;
  color: var(--green);
  font-weight: 700;
}

.neutral {
  color: #667085;
}

.sparkline {
  height: 36px;
  margin-top: 16px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0%, transparent 40%, rgba(0, 87, 255, 0.12) 40%, transparent 80%),
    repeating-linear-gradient(135deg, transparent 0 14px, rgba(0, 87, 255, 0.18) 15px 16px);
  opacity: 0.75;
}

.content-grid {
  display: grid;
  grid-template-columns: 1.05fr 1.35fr;
  gap: 18px;
  margin-bottom: 22px;
}

.agent-context-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.agent-context {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 22px rgba(16, 24, 47, 0.05);
  padding: 22px;
}

.agent-context-title {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.agent-context-icon {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0057ff;
  background: #eaf1ff;
  flex: none;
}

.agent-context-title h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.agent-context-title p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.agent-history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 18px;
}

.agent-history-main,
.agent-history-list,
.agent-history-empty {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
  padding: 18px;
}

.agent-history-main {
  display: grid;
  gap: 16px;
  align-content: start;
}

.agent-history-empty {
  min-height: 340px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.agent-history-empty h2 {
  margin: 0;
  color: var(--text);
}

.agent-history-empty p {
  margin: 0 0 8px;
}

.history-detail {
  display: grid;
  gap: 14px;
}

.detail-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.prompt-preview,
.response-preview {
  overflow-y: auto;
  white-space: pre-wrap;
  border: 1px solid #d8e1ef;
  border-radius: 12px;
  background: white;
  color: #1d2939;
  padding: 16px;
  line-height: 1.55;
}

.prompt-preview {
  max-height: 180px;
}

.response-preview {
  min-height: 230px;
  max-height: 420px;
}

.agent-history-list {
  display: grid;
  gap: 10px;
  align-content: start;
  max-height: 560px;
  overflow-y: auto;
}

.agent-history-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  color: #344054;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.agent-history-row span {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef4ff;
  color: #0b4bd3;
  font-size: 12px;
  font-weight: 900;
}

.agent-history-row strong {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.4;
}

.agent-history-row.active,
.agent-history-row:hover {
  border-color: #9bbcff;
  background: #f5f8ff;
}

.panel,
.automation {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 22px rgba(16, 24, 47, 0.05);
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 17px;
  font-weight: 900;
  display: flex;
  gap: 8px;
  align-items: center;
}

.link {
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.activity-row {
  display: grid;
  grid-template-columns: 60px 32px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #edf1f7;
  font-size: 13px;
}

.activity-row:last-child {
  border-bottom: none;
}

.time {
  color: #344054;
  font-weight: 700;
}

.small-icon {
  color: var(--blue);
}

.badge {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.badge.green {
  background: #dff8ed;
  color: #0b8a5a;
}

.badge.blue {
  background: #e7f0ff;
  color: #075ad7;
}

.agent-view-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-height: 126px;
  background: #fbfdff;
}

.mini-card h4 {
  margin: 0 0 12px;
  font-size: 14px;
  color: #173b82;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-card p,
.mini-card li {
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.mini-card ul {
  margin: 0;
  padding-left: 16px;
}

.history-card {
  display: grid;
  gap: 10px;
}

.history-head,
.history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-head h4 {
  margin: 0;
}

.history-head h2 {
  margin: 0;
  font-size: 17px;
}

.history-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.history-current,
.history-item {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: #344054;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.history-current {
  min-height: 92px;
  border-radius: 12px;
  padding: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.history-list {
  display: grid;
  gap: 6px;
}

.history-item {
  height: 34px;
  border-radius: 9px;
  padding: 0 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.active,
.history-current:hover,
.history-item:hover {
  border-color: #9bbcff;
  background: #f5f8ff;
  color: #0b4bd3;
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.flow {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  padding: 14px 0 6px;
}

.flow-block {
  min-width: 150px;
  border: 1px solid #d8e1ef;
  border-radius: 10px;
  padding: 14px;
  background: #fbfdff;
  font-size: 13px;
}

.flow-tag {
  width: 36px;
  height: 54px;
  border-radius: 8px;
  background: #00338f;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 12px;
  flex: none;
}

.plus {
  color: var(--blue);
  font-size: 24px;
  font-weight: 700;
}

.right-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.right-title h2 {
  margin: 0;
  font-size: 20px;
}

.right-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.connector-card {
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(16, 24, 47, 0.05);
  background: white;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px;
  margin-bottom: 20px;
}

.connector-logo {
  color: var(--blue);
  width: 50px;
  display: flex;
  justify-content: center;
}

.connector-name {
  font-weight: 900;
  margin-bottom: 7px;
}

.connected {
  color: var(--green);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot-green {
  width: 9px;
  height: 9px;
  background: var(--green);
  border-radius: 50%;
}

.dots {
  margin-left: auto;
  color: #344054;
}

.manage-connectors {
  width: 100%;
  justify-content: center;
}

.tenant-title {
  margin-top: 28px;
}

.tenant-members,
.tenant-add {
  display: grid;
  gap: 10px;
}

.tenant-member {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 36px;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.tenant-member .connector-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tenant-member select,
.tenant-add select,
.tenant-add input {
  height: 36px;
  min-width: 0;
  border: 1px solid #d8deea;
  border-radius: 10px;
  padding: 0 10px;
  background: white;
  color: var(--text);
}

.tenant-add {
  margin-top: 12px;
}

.tenant-add .btn {
  width: 100%;
  justify-content: center;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  color: #b42318;
  border-color: #f3b3aa;
  background: #fff7f5;
}

.empty-state {
  padding: 12px;
  border: 1px dashed #cfd7e6;
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 47, 0.35);
  z-index: 40;
  align-items: center;
  justify-content: center;
}

.modal {
  width: 760px;
  max-width: calc(100vw - 40px);
  background: white;
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(16, 24, 47, 0.28);
  padding: 24px;
}

.modal h2 {
  margin: 0 0 8px;
}

.modal p {
  margin: 0 0 18px;
  color: var(--muted);
}

textarea {
  width: 100%;
  height: 170px;
  border: 1px solid #d8deea;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  resize: vertical;
  outline: none;
}

textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(0, 87, 255, 0.08);
}

.response {
  margin-top: 16px;
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

@media (max-width: 1300px) {
  .app,
  .topbar {
    grid-template-columns: 290px 1fr;
  }

  .rightbar {
    display: none;
  }

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

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 16px;
    gap: 14px;
  }

  .brand,
  .user-zone {
    padding: 0;
  }

  .search-box {
    width: 100%;
  }

  .app {
    display: block;
  }

  .sidebar,
  .main,
  .rightbar {
    padding: 120px 20px 20px;
    border: none;
  }

  .content-grid,
  .agent-view-grid,
  .agent-history-layout,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .agent-context-head,
  .agent-context-title {
    align-items: stretch;
    flex-direction: column;
  }
}
