@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f8f9fc;
  --card: #ffffff;
  --line: #dfe3ee;
  --text: #101426;
  --muted: #667085;
  --primary: #5547e8;
  --primary-soft: #ecebff;
  --orange: #f5a623;
  --orange-soft: #fff4dd;
  --red: #ef3b4d;
  --red-soft: #ffe8ec;
  --green: #19b86a;
  --green-soft: #dcfbea;
  --yellow: #f0aa20;
  --yellow-soft: #fff4d8;
  --sidebar: #f4f6fb;
}

body {
  font-family: 'Ubuntu', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button,
input,
textarea,
select {
  font-family: 'Ubuntu', sans-serif;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 235px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 26px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7a5cff);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

.brand h1 {
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
}

.brand span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.side-menu {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.menu-item {
  border: none;
  background: transparent;
  padding: 12px 12px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: 0.2s;
  font-weight: 500;
}

.menu-item:hover,
.menu-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.plan-box {
  margin-top: auto;
  background: linear-gradient(135deg, #fff7fb, #f0efff);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px;
}

.plan-box strong {
  display: block;
  margin-bottom: 6px;
}

.plan-box p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.plan-box button {
  margin-top: 12px;
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 9px;
  padding: 10px;
  font-weight: 700;
}

.main {
  margin-left: 235px;
  width: calc(100% - 235px);
}

.topbar {
  height: 58px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.search {
  width: 430px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
}

.search input {
  border: none;
  outline: none;
  width: 100%;
  color: var(--text);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chip,
.icon-btn,
.profile {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  height: 38px;
}

.chip {
  padding: 0 20px;
  font-weight: 700;
}

.icon-btn {
  width: 40px;
  cursor: pointer;
}

.profile {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px 0 8px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile strong {
  display: block;
  font-size: 12px;
}

.profile span {
  color: var(--muted);
  font-size: 11px;
}

.page {
  display: none;
  padding: 32px;
}

.active-page {
  display: block;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-head h2 {
  font-size: 28px;
  margin-bottom: 6px;
  font-weight: 400;
}

.page-head p {
  color: #46536b;
}

.primary-btn,
.outline-btn {
  border-radius: 10px;
  height: 38px;
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn {
  border: none;
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(85,71,232,0.25);
}

.outline-btn {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
}

.outline-btn.danger {
  color: #222;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.alert-card,
.stat-card,
.panel,
.message-form,
.message-detail,
.automation-card,
.source-summary {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 2px 5px rgba(16,24,40,0.03);
}

.alert-card {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 24px;
}

.alert-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--red-soft);
  color: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
}

.alert-card span,
.stat-card span,
.source-summary span {
  font-size: 12px;
  color: #344054;
  letter-spacing: .04em;
  font-weight: 700;
}

.alert-card h3 {
  font-weight: 400;
  margin: 8px 0;
  font-size: 19px;
}

.alert-card h3 b {
  color: var(--red);
}

.alert-card p {
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

.stat-grid.three {
  grid-template-columns: repeat(3, 1fr);
}

.stat-card {
  padding: 20px;
  min-height: 118px;
}

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.stat-icon.purple { background: var(--primary-soft); color: var(--primary); }
.stat-icon.green { background: var(--green-soft); color: var(--green); }
.stat-icon.red { background: var(--red-soft); color: var(--red); }
.stat-icon.yellow { background: var(--yellow-soft); color: #9a6700; }

.stat-card h3 {
  font-size: 28px;
  font-weight: 400;
  margin-top: 8px;
}

.stat-card p {
  color: var(--muted);
  margin-top: 6px;
}

.soft-red {
  background: linear-gradient(90deg, #fff1f3, #fff);
}

.soft-yellow {
  background: linear-gradient(90deg, #fff7e7, #fff);
}

.soft-green {
  background: linear-gradient(90deg, #ebfff4, #fff);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 24px;
  margin-bottom: 24px;
}

.dashboard-grid .large {
  min-height: 200px;
}

.panel {
  padding: 24px;
}

.panel.full {
  width: 100%;
}

.panel.no-padding {
  padding: 0;
}

.panel h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.panel p {
  color: #475467;
  margin-bottom: 18px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
}

.legend {
  display: flex;
  gap: 10px;
  color: #475467;
  font-size: 12px;
}

.legend i {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
}

.blue-dot { background: var(--primary); }
.green-dot { background: var(--green); }
.red-dot { background: var(--red); }

.trend-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 24px;
}

.trend-list div,
.reason-list div,
.action-list div {
  border: 1px solid var(--line);
  background: #fbfcff;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trend-list b {
  color: var(--primary);
}

.bar-row {
  margin-top: 18px;
}

.bar-row div:first-child {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
}

.bar-row b {
  font-weight: 500;
}

.bar {
  width: 100%;
  height: 7px;
  background: #eff1f6;
  border-radius: 99px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--orange);
  border-radius: 99px;
  transition: .3s;
}

.tip {
  background: var(--primary-soft);
  padding: 12px;
  border-radius: 10px;
  font-size: 12px;
  color: #1f1a70;
  margin-top: 22px;
}

/* MESSAGE PAGE */

.message-form {
  padding: 24px;
  margin-bottom: 22px;
}

.form-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.form-title p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.plus-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.1fr 2.2fr .9fr 120px;
  gap: 12px;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  padding: 10px 12px;
  outline: none;
  color: var(--text);
}

textarea {
  min-height: 50px;
  resize: vertical;
}

.add-btn {
  height: 42px;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.filter {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  height: 34px;
  padding: 0 14px;
  cursor: pointer;
  color: #24304a;
}

.filter.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #fbfbff;
}

.filter b {
  margin-left: 4px;
  color: var(--muted);
  font-weight: 400;
}

.message-layout {
  display: grid;
  grid-template-columns: 40% 60%;
  gap: 24px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-item {
  border: 1px solid var(--line);
  background: white;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  gap: 14px;
  cursor: pointer;
}

.message-item.active {
  border-color: var(--primary);
}

.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffd4b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.message-info {
  flex: 1;
}

.message-info strong {
  display: block;
  margin-bottom: 4px;
}

.message-info p {
  color: #344054;
  margin-bottom: 8px;
}

.message-time {
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
}

.tag.orange { background: var(--orange-soft); color: #855800; }
.tag.green { background: var(--green-soft); color: #087443; }
.tag.red { background: var(--red-soft); color: #b42335; }
.tag.purple { background: var(--primary-soft); color: var(--primary); }

.detail-card {
  padding: 22px;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.detail-user {
  display: flex;
  gap: 12px;
  align-items: center;
}

.dm-bubble {
  background: #eef1f7;
  border-radius: 14px;
  padding: 16px;
  margin: 16px 0;
}

.ai-box {
  border: 1px solid #c9c4ff;
  background: #f5f4ff;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.ai-box span,
.reply-box span {
  display: block;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.reply-box textarea {
  width: 100%;
  min-height: 64px;
}

.reply-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.reply-actions .primary-btn {
  flex: 1;
}

.empty-state {
  text-align: center;
  padding: 80px 30px;
  color: var(--muted);
}

/* INSIGHTS */

.insight-hero {
  border: 1px solid #cec9ff;
  border-radius: 16px;
  background: linear-gradient(90deg, #ffffff, #fff8fb);
  padding: 28px;
  margin-bottom: 24px;
}

.insight-hero span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.insight-hero h3 {
  font-size: 26px;
  font-weight: 400;
  margin: 12px 0;
  line-height: 1.35;
}

.insight-hero em {
  color: #ff3d8b;
}

.danger-title { color: var(--red); }
.success-title { color: var(--green); }
.primary-title { color: var(--primary); }

.reason-list,
.action-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reason-list b {
  background: var(--primary);
  color: white;
  min-width: 23px;
  height: 23px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

/* AUTOMATION */

.automation-card {
  padding: 22px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.auto-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.auto-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.switch input {
  display: none;
}

.switch span {
  display: block;
  width: 38px;
  height: 20px;
  background: #d9dde8;
  border-radius: 99px;
  position: relative;
  cursor: pointer;
}

.switch span:before {
  content: "";
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  position: absolute;
  left: 2px;
  top: 2px;
  transition: .2s;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span:before {
  transform: translateX(18px);
}

.panel-header {
  padding: 22px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.rules-list .rule-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.rule-left {
  display: flex;
  gap: 14px;
  align-items: center;
}

.rule-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* DATA SOURCES */

.source-summary {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 26px;
  margin-bottom: 24px;
}

.source-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.source-summary div:not(.source-icon) {
  border-right: 1px solid var(--line);
  padding-right: 22px;
}

.source-summary div:last-child {
  border-right: none;
}

.source-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
  font-weight: 400;
}

.upload-box {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 36px;
  text-align: center;
  color: #344054;
  margin: 18px 0;
}

.upload-box div {
  font-size: 32px;
  margin-bottom: 10px;
}

.upload-box span {
  display: block;
  color: var(--muted);
  margin-top: 6px;
}

.check-list {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}

.check-list li {
  margin-bottom: 10px;
}

.check-list li:before {
  content: "✓";
  color: var(--green);
  margin-right: 8px;
}

/* ADMIN */

.admin-grid {
  display: grid;
  grid-template-columns: .8fr 1.2fr;
  gap: 24px;
}

.admin-form {
  display: grid;
  gap: 14px;
}

.permission-table-wrap {
  overflow-x: auto;
}

.permission-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.permission-table th,
.permission-table td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  white-space: nowrap;
}

.permission-table th {
  font-size: 12px;
  color: var(--muted);
}

.permission-table select {
  min-width: 120px;
}

.permission-check {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

@media (max-width: 950px) {
  .sidebar {
    width: 78px;
  }

  .brand h1,
  .brand span,
  .menu-item {
    font-size: 0;
  }

  .menu-item span {
    font-size: 18px;
  }

  .plan-box {
    display: none;
  }

  .main {
    margin-left: 78px;
    width: calc(100% - 78px);
  }

  .search {
    width: 260px;
  }

  .stat-grid,
  .stat-grid.three,
  .dashboard-grid,
  .message-layout,
  .admin-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .top-actions {
    display: none;
  }
}