:root {
  --primary: #2563eb;
  --sidebar: #0f172a;
  --sidebar-active: #1e293b;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --success: #22c55e;
  --warning: #facc15;
  --orange: #f97316;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 220px;
  background: var(--sidebar);
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.sidebar-brand {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  color: #fff;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary);
  font-size: 12px;
}

.sidebar-nav {
  padding: 14px 10px;
  display: grid;
  gap: 4px;
}

.sidebar-link {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  color: #cbd5e1;
  border-radius: 8px;
  text-decoration: none;
}

.sidebar-link:hover,
.sidebar-link.active {
  background: var(--sidebar-active);
  color: #fff;
  text-decoration: none;
}

.sidebar-link i {
  width: 18px;
  font-size: 16px;
}

.sidebar-user {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #334155;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.user-meta strong {
  display: block;
  color: #fff;
  line-height: 1.1;
}

.user-meta button {
  border: 0;
  background: transparent;
  color: #94a3b8;
  padding: 2px 0 0;
}

.app-shell {
  min-height: 100vh;
  margin-left: 220px;
}

.sidebar-collapsed .app-sidebar {
  transform: translateX(-220px);
}

.sidebar-collapsed .app-shell {
  margin-left: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 14px;
}

.topbar-title {
  font-weight: 700;
  color: var(--text);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  color: #374151;
  display: inline-grid;
  place-items: center;
}

.app-main {
  padding: 24px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.page-title {
  font-size: 24px;
  font-weight: 750;
  margin: 0;
}

.page-subtitle {
  color: var(--muted);
  margin: 5px 0 0;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.card-panel,
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.card-panel {
  padding: 18px;
}

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

.stat-card {
  padding: 16px;
  display: flex;
  gap: 14px;
  min-height: 112px;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-size: 18px;
}

.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green { background: #dcfce7; color: #166534; }
.stat-icon.yellow { background: #fef9c3; color: #854d0e; }
.stat-icon.orange { background: #ffedd5; color: #c2410c; }
.stat-icon.red { background: #fee2e2; color: #b91c1c; }
.stat-icon.purple { background: #f3e8ff; color: #7e22ce; }
.stat-icon.gray { background: #f3f4f6; color: #4b5563; }

.stat-title {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 28px;
  font-weight: 760;
  line-height: 1.1;
  margin-top: 4px;
}

.stat-hint {
  color: var(--muted);
  margin-top: 8px;
  font-size: 12px;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.section-grid.two {
  grid-template-columns: 1.2fr 1fr;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title-row h2,
.card-panel h2 {
  font-size: 16px;
  margin: 0;
  font-weight: 720;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.filter-grid.large {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

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

.crm-table {
  min-width: 1180px;
  margin: 0;
}

.crm-table th {
  color: #374151;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  background: #f9fafb;
  border-bottom-color: var(--border);
  cursor: pointer;
}

.crm-table td {
  vertical-align: middle;
  max-width: 260px;
}

.table-tools {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.table-search {
  max-width: 280px;
}

.badge-soft {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.badge-tier-a1 { background: #dcfce7; color: #166534; }
.badge-tier-a2 { background: #fef9c3; color: #854d0e; }
.badge-tier-b { background: #dbeafe; color: #1d4ed8; }
.badge-tier-c { background: #f3f4f6; color: #4b5563; }
.badge-tier-skip { background: #e5e7eb; color: #374151; }
.badge-status-new { background: #dbeafe; color: #1d4ed8; }
.badge-status-sent { background: #dcfce7; color: #166534; }
.badge-status-replied { background: #f3e8ff; color: #7e22ce; }
.badge-status-follow { background: #ffedd5; color: #c2410c; }
.badge-status-paused { background: #f3f4f6; color: #4b5563; }
.badge-status-closed { background: #e5e7eb; color: #1f2937; }
.badge-status-success { background: #dcfce7; color: #166534; }
.badge-status-failed { background: #fee2e2; color: #b91c1c; }
.badge-status-partial { background: #ffedd5; color: #c2410c; }

.contact-actions,
.row-actions {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-copy {
  --bs-btn-padding-y: 0.2rem;
  --bs-btn-padding-x: 0.45rem;
  --bs-btn-font-size: 0.75rem;
}

.text-muted-small {
  color: var(--muted);
  font-size: 12px;
}

.message-preview {
  max-width: 240px;
  color: #374151;
}

.progress-mini {
  width: 82px;
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
}

.progress-mini span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.trend-bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 10px;
  min-height: 180px;
}

.trend-bar {
  display: grid;
  gap: 8px;
  justify-items: center;
  color: var(--muted);
  font-size: 12px;
}

.trend-bar span {
  width: 28px;
  min-height: 4px;
  border-radius: 8px 8px 0 0;
  background: var(--primary);
}

.distribution-row {
  display: grid;
  grid-template-columns: 120px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.distribution-track {
  height: 8px;
  border-radius: 999px;
  background: #edf2f7;
  overflow: hidden;
}

.distribution-fill {
  height: 100%;
  background: var(--primary);
}

.detail-hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.detail-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.field-list {
  display: grid;
  gap: 10px;
}

.field-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
}

.field-label {
  color: var(--muted);
}

.message-box,
.preserve {
  white-space: pre-wrap;
}

.message-box {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.timeline {
  display: grid;
  gap: 14px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px #dbeafe;
}

.empty-state {
  padding: 42px 16px;
  text-align: center;
  color: var(--muted);
}

.empty-state i {
  display: block;
  font-size: 28px;
  margin-bottom: 8px;
  color: #9ca3af;
}

.login-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-box {
  width: min(420px, 92vw);
  padding: 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.08);
}

.pagination-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

@media (max-width: 1365px) {
  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .section-grid,
  .section-grid.two,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .app-sidebar {
    transform: translateX(-100%);
  }

  .app-shell {
    margin-left: 0;
  }

  .topbar {
    padding: 0 14px;
  }

  .app-main {
    padding: 16px;
  }

  .page-header,
  .detail-hero,
  .pagination-wrap {
    flex-direction: column;
  }

  .stat-grid,
  .filter-grid,
  .filter-grid.large {
    grid-template-columns: 1fr;
  }
}
