/* ========================================
   SpamJammer Dashboard - Product-Led Style
   ======================================== */

:root {
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --accent-light: #EFF6FF;
  --orange: #F59E0B;
  --orange-light: #FFF7ED;
  --green: #10B981;
  --green-light: #ECFDF5;
  --red: #EF4444;
  --red-light: #FEF2F2;
  --purple: #8B5CF6;
  --purple-light: #F5F3FF;
  --gray: #6B7280;

  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-sidebar: #FFFFFF;
  --bg-topnav: #FFFFFF;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #94A3B8;

  --border: #E2E8F0;
  --border-light: #F1F5F9;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;

  --sidebar-width: 260px;
  --topnav-height: 60px;
}

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

html { font-size: 14px; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  /* Dot grid background */
  background-image: radial-gradient(circle, #CBD5E1 0.8px, transparent 0.8px);
  background-size: 24px 24px;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ---- Top Navigation ---- */
.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topnav-height);
  background: var(--bg-topnav);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.92);
}

.topnav-left {
  display: flex;
  align-items: center;
  gap: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.topnav-links {
  display: flex;
  gap: 4px;
}

.topnav-links a {
  text-decoration: none;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.92rem;
  transition: all 0.15s ease;
}

.topnav-links a:hover {
  color: var(--text-primary);
  background: var(--border-light);
}

.topnav-links a.active {
  color: var(--accent);
  background: var(--accent-light);
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  position: relative;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-topnav);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.user-menu:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #6366F1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
}

.user-role {
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

.chevron {
  color: var(--text-tertiary);
}

/* ---- Layout ---- */
.app-layout {
  display: flex;
  padding-top: var(--topnav-height);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--topnav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 12px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: all 0.15s ease;
  position: relative;
}

.nav-item:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.nav-item svg {
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--accent-light);
  color: var(--accent);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.nav-badge.warn {
  background: var(--orange-light);
  color: var(--orange);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.plan-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), #6366F1);
  color: #fff;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.usage-info {
  margin-top: 12px;
}

.usage-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.usage-numbers {
  color: var(--text-secondary);
}

.usage-bar {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #6366F1);
  border-radius: 3px;
  transition: width 1.2s ease;
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 28px 32px;
  max-width: calc(100vw - var(--sidebar-width));
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-tertiary);
  font-size: 0.88rem;
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

.btn-outline {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: all 0.2s ease;
}

.stat-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

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

.stat-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon.blue { background: var(--accent-light); color: var(--accent); }
.stat-icon.orange { background: var(--orange-light); color: var(--orange); }
.stat-icon.green { background: var(--green-light); color: var(--green); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 8px;
}

.stat-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 500;
}

.stat-change.positive {
  color: var(--green);
}

.stat-detail {
  font-size: 0.82rem;
  color: var(--text-tertiary);
}

.stat-pct {
  font-weight: 600;
  color: var(--orange);
}

/* Detection Gauge */
.detection-card .stat-header {
  margin-bottom: 0;
}

.detection-gauge-row {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 4px;
}

.gauge-container {
  width: 120px;
  height: 120px;
}

.gauge-svg {
  width: 100%;
  height: 100%;
}

.gauge-fill {
  transition: stroke-dashoffset 2s ease;
}

.gauge-text {
  font-family: 'DM Sans', sans-serif;
}

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 22px 16px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ---- Charts Row ---- */
.charts-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

/* Activity Chart */
.chart-card {
  min-height: 320px;
}

.chart-legend {
  display: flex;
  gap: 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.blue { background: var(--accent); }
.legend-dot.orange { background: var(--orange); }

.chart-container {
  padding: 0 22px 16px;
  position: relative;
}

.activity-svg {
  width: 100%;
  height: 200px;
}

.chart-x-labels {
  display: flex;
  justify-content: space-between;
  padding: 8px 50px 0;
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

.chart-tooltip {
  position: absolute;
  background: var(--text-primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
  white-space: nowrap;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
}

.chart-container:hover .chart-tooltip {
  opacity: 1;
}

.tooltip-date {
  font-weight: 600;
  margin-bottom: 4px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

/* Chart animations */
.chart-area-legit,
.chart-area-spam,
.chart-line-legit,
.chart-line-spam,
.chart-dots {
  transition: opacity 1s ease;
}

.chart-area-legit.visible,
.chart-area-spam.visible { opacity: 0.6; }
.chart-line-legit.visible,
.chart-line-spam.visible,
.chart-dots.visible { opacity: 1; }

/* ---- Live Feed ---- */
.feed-card {
  display: flex;
  flex-direction: column;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--green);
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16,185,129,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}

.feed-list {
  flex: 1;
  overflow-y: auto;
  max-height: 240px;
  padding: 0 22px 16px;
}

.feed-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  animation: feedSlideIn 0.4s ease;
}

.feed-item:last-child {
  border-bottom: none;
}

@keyframes feedSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.feed-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.feed-dot.blocked { background: var(--red); }
.feed-dot.quarantined { background: var(--orange); }
.feed-dot.allowed { background: var(--green); }

.feed-text {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.feed-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

.feed-time {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  margin-top: 2px;
}

/* ---- Bottom Row (Table) ---- */
.bottom-row {
  margin-bottom: 24px;
}

.table-card {
  overflow: visible;
}

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

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

.data-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--border-light);
  white-space: nowrap;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.data-table th.sortable:hover {
  color: var(--accent);
}

.data-table th svg {
  vertical-align: middle;
  margin-left: 2px;
}

.data-table td {
  padding: 12px 16px;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.data-table tr:hover td {
  background: var(--border-light);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.sender-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.sender-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}

.sender-avatar.red { background: var(--red); }
.sender-avatar.orange { background: var(--orange); }
.sender-avatar.purple { background: var(--purple); }
.sender-avatar.green { background: var(--green); }
.sender-avatar.blue { background: var(--accent); }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag.phishing { background: var(--red-light); color: var(--red); }
.tag.scam { background: var(--orange-light); color: #D97706; }
.tag.marketing { background: var(--accent-light); color: var(--accent); }
.tag.malware { background: var(--purple-light); color: var(--purple); }

.score {
  font-weight: 700;
  font-size: 0.85rem;
}

.score.high { color: var(--red); }
.score.medium { color: var(--orange); }
.score.low { color: var(--green); }

.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status.blocked { background: var(--red-light); color: var(--red); }
.status.quarantined { background: var(--orange-light); color: #D97706; }
.status.review { background: var(--accent-light); color: var(--accent); }

.time-cell {
  color: var(--text-tertiary);
  font-size: 0.82rem;
}

/* ---- Widgets Row ---- */
.widgets-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

/* Donut Chart */
.donut-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 0 22px 22px;
}

.donut-svg {
  width: 180px;
  height: 180px;
  flex-shrink: 0;
}

.donut-segment {
  transition: stroke-dasharray 1.5s ease;
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-row span:nth-child(2) {
  flex: 1;
  color: var(--text-secondary);
}

.legend-row strong {
  color: var(--text-primary);
}

/* Top Blocked */
.blocked-list {
  padding: 0 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.blocked-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.blocked-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.blocked-rank {
  width: 20px;
  height: 20px;
  background: var(--border-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.blocked-domain {
  flex: 1;
  font-weight: 500;
  color: var(--text-primary);
}

.blocked-count {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.blocked-bar {
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
}

.blocked-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--red));
  border-radius: 2px;
  transition: width 1s ease;
}

/* Quick Actions */
.actions-list {
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s ease;
  width: 100%;
}

.action-btn:hover {
  background: var(--border-light);
}

.action-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.action-icon.blue { background: var(--accent-light); color: var(--accent); }
.action-icon.orange { background: var(--orange-light); color: var(--orange); }
.action-icon.green { background: var(--green-light); color: var(--green); }
.action-icon.purple { background: var(--purple-light); color: var(--purple); }
.action-icon.red { background: var(--red-light); color: var(--red); }
.action-icon.gray { background: var(--border-light); color: var(--gray); }

.action-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.action-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.action-desc {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.action-arrow {
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.action-btn:hover .action-arrow {
  transform: translateX(2px);
  color: var(--accent);
}

/* ---- Responsive ---- */
@media (max-width: 1280px) {
  .widgets-row {
    grid-template-columns: 1fr 1fr;
  }
  .widgets-row > .card:last-child {
    grid-column: span 2;
  }
}

@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-row {
    grid-template-columns: 1fr;
  }
  .widgets-row {
    grid-template-columns: 1fr;
  }
  .widgets-row > .card:last-child {
    grid-column: span 1;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .main-content {
    margin-left: 0;
    max-width: 100vw;
    padding: 20px 16px;
  }
  .topnav-links {
    display: none;
  }
  .page-header {
    flex-direction: column;
    gap: 16px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .donut-container {
    flex-direction: column;
  }
}
