/* ============================================================
   HERMES MAIL — Premium SaaS Dashboard Stylesheet
   Design System: Dark Mode with Glassmorphism & Gradient Accents
   ============================================================ */

/* ── CSS Custom Properties (Design Tokens) ─────────────────── */
:root {
  /* Backgrounds */
  --bg-deep:        #0a0a0f;
  --bg-card:        #12121a;
  --bg-card-hover:  #161620;
  --bg-surface:     #0e0e16;
  --bg-input:       #1a1a28;
  --bg-sidebar:     #0c0c14;
  --bg-header:      rgba(10, 10, 15, 0.82);
  --bg-glass:       rgba(18, 18, 26, 0.8);
  --bg-overlay:     rgba(0, 0, 0, 0.6);

  /* Borders */
  --border-subtle:  rgba(255, 255, 255, 0.06);
  --border-light:   rgba(255, 255, 255, 0.10);
  --border-accent:  rgba(102, 126, 234, 0.4);

  /* Accent */
  --accent-start:   #667eea;
  --accent-end:     #764ba2;
  --accent-gradient: linear-gradient(135deg, #667eea, #764ba2);
  --accent-glow:    rgba(102, 126, 234, 0.25);

  /* Urgent */
  --urgent-start:   #f5576c;
  --urgent-end:     #ff6b6b;
  --urgent-gradient: linear-gradient(135deg, #f5576c, #ff6b6b);

  /* Status */
  --success:        #10b981;
  --success-dim:    rgba(16, 185, 129, 0.15);
  --warning:        #f59e0b;
  --warning-dim:    rgba(245, 158, 11, 0.15);
  --danger:         #ef4444;
  --danger-dim:     rgba(239, 68, 68, 0.15);
  --info:           #3b82f6;
  --info-dim:       rgba(59, 130, 246, 0.15);

  /* Text */
  --text-primary:   #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --text-white:     #ffffff;
  --text-inverse:   #0a0a0f;

  /* Typography */
  --font-family:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-xs:        0.6875rem;   /* 11px */
  --font-sm:        0.75rem;     /* 12px */
  --font-base:      0.875rem;    /* 14px */
  --font-md:        1rem;        /* 16px */
  --font-lg:        1.125rem;    /* 18px */
  --font-xl:        1.5rem;      /* 24px */
  --font-2xl:       2rem;        /* 32px */

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radii */
  --radius-sm:    6px;
  --radius-md:    8px;
  --radius-lg:    12px;
  --radius-xl:    16px;
  --radius-pill:  20px;
  --radius-full:  9999px;

  /* Shadows */
  --shadow-card:    0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-float:   0 8px 40px rgba(0, 0, 0, 0.45);
  --shadow-glow:    0 0 20px rgba(102, 126, 234, 0.15);
  --shadow-inner:   inset 0 1px 2px rgba(0, 0, 0, 0.3);

  /* Layout */
  --sidebar-width:  260px;
  --header-height:  64px;
  --detail-width:   520px;

  /* Transitions */
  --ease-default:   all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce:    all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-fast:      all 0.15s ease;
}


/* ── Reset / Normalize ─────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-base);
  color: var(--text-primary);
  background: var(--bg-deep);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--accent-start);
  text-decoration: none;
  transition: var(--ease-fast);
}
a:hover { color: var(--accent-end); }

ul, ol { list-style: none; }

img { max-width: 100%; display: block; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  outline: none;
  border: none;
  background: none;
}

button { cursor: pointer; }


/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}


/* ── Layout Shell ──────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  min-height: 100vh;
}


/* ── Header ────────────────────────────────────────────────── */
.app-header {
  grid-area: header;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  background: var(--bg-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-lg);
  font-weight: 700;
  white-space: nowrap;
}
.header-logo .logo-icon {
  font-size: 1.5rem;
}
.header-logo .logo-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-center {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.account-badge {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: var(--font-sm);
  color: var(--text-secondary);
}
.account-badge .sync-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--success);
  flex-shrink: 0;
}
.account-badge .sync-dot.offline {
  background: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.sync-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-sm);
  color: var(--text-muted);
}
.sync-status .pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--success);
  animation: pulse-glow 2s ease-in-out infinite;
}
.sync-status .pulse-dot.syncing {
  background: var(--warning);
  animation: pulse-glow-warn 1s ease-in-out infinite;
}

.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 1.25rem;
  transition: var(--ease-fast);
}
.mobile-menu-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}


/* ── Sidebar ───────────────────────────────────────────────── */
.app-sidebar {
  grid-area: sidebar;
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: var(--space-6) 0;
  z-index: 90;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 0 var(--space-3);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--font-base);
  font-weight: 500;
  transition: var(--ease-default);
  cursor: pointer;
  position: relative;
  user-select: none;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-gradient);
  color: var(--text-white);
  box-shadow: 0 2px 12px rgba(102, 126, 234, 0.3);
}
.nav-item .nav-icon {
  font-size: 1.15rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.nav-item .nav-label {
  flex: 1;
}
.nav-item .nav-badge {
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--font-xs);
  font-weight: 600;
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  min-width: 22px;
  text-align: center;
}
.nav-item.active .nav-badge {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-white);
}

.sidebar-bottom {
  padding: var(--space-4) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}


/* ── Main Content ──────────────────────────────────────────── */
.app-main {
  grid-area: main;
  margin-top: var(--header-height);
  margin-left: var(--sidebar-width);
  padding: var(--space-8);
  min-height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.page-title {
  font-size: var(--font-xl);
  font-weight: 700;
  margin-bottom: var(--space-6);
  color: var(--text-primary);
}


/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-card);
  transition: var(--ease-default);
}
.card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-float);
}
.card-glass {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-flat {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-flat:hover {
  border-color: var(--border-light);
}


/* ── Filter Bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: var(--space-1);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
}
.filter-tab {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-muted);
  transition: var(--ease-fast);
  cursor: pointer;
  white-space: nowrap;
}
.filter-tab:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
}
.filter-tab.active {
  background: var(--accent-gradient);
  color: var(--text-white);
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 320px;
}
.search-box .search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: var(--font-base);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: var(--space-2) var(--space-4) var(--space-2) 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-sm);
  transition: var(--ease-fast);
}
.search-box input::placeholder {
  color: var(--text-muted);
}
.search-box input:focus {
  border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}


/* ── Email List ────────────────────────────────────────────── */
.email-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.email-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--ease-default);
}
.email-item:hover {
  border-color: var(--border-light);
  background: var(--bg-card-hover);
  transform: translateX(4px);
}
.email-item.unread {
  border-left: 3px solid var(--accent-start);
}

.email-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-md);
  color: var(--text-white);
  flex-shrink: 0;
  text-transform: uppercase;
}

.email-content {
  flex: 1;
  min-width: 0;
}
.email-sender {
  font-weight: 600;
  font-size: var(--font-base);
  color: var(--text-primary);
  margin-bottom: 2px;
}
.email-subject {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.email-preview {
  font-size: var(--font-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  flex-shrink: 0;
}
.email-time {
  font-size: var(--font-xs);
  color: var(--text-muted);
  white-space: nowrap;
}
.email-meta-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}


/* ── Badges / Pills ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--font-xs);
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.badge-primary        { background: rgba(102,126,234,0.15); color: var(--accent-start); }
.badge-urgent         { background: rgba(245,87,108,0.15);  color: var(--urgent-start); }
.badge-actionable     { background: rgba(245,158,11,0.15);  color: var(--warning); }
.badge-info           { background: rgba(59,130,246,0.15);  color: var(--info); }
.badge-newsletter     { background: rgba(139,92,246,0.15);  color: #8b5cf6; }
.badge-spam           { background: rgba(107,114,128,0.15); color: #6b7280; }
.badge-success        { background: var(--success-dim);     color: var(--success); }
.badge-danger         { background: var(--danger-dim);      color: var(--danger); }
.badge-status-active  { background: var(--success-dim);     color: var(--success); }
.badge-status-inactive{ background: rgba(107,114,128,0.15); color: #6b7280; }

.entity-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--font-xs);
  font-weight: 500;
  background: rgba(102, 126, 234, 0.1);
  color: var(--accent-start);
  border: 1px solid rgba(102, 126, 234, 0.2);
}


/* ── Priority Dots ─────────────────────────────────────────── */
.priority-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.priority-dot.p1 { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,0.5); }
.priority-dot.p2 { background: #f97316; box-shadow: 0 0 6px rgba(249,115,22,0.4); }
.priority-dot.p3 { background: #eab308; }
.priority-dot.p4 { background: #22c55e; }
.priority-dot.p5 { background: #64748b; }


/* ── Email Detail Panel ────────────────────────────────────── */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.detail-overlay.open {
  opacity: 1;
  visibility: visible;
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--detail-width), 92vw);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.detail-panel.open {
  transform: translateX(0);
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.detail-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 1.25rem;
  transition: var(--ease-fast);
}
.detail-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

.detail-subject {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  line-height: 1.4;
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.detail-meta-row {
  display: flex;
  gap: var(--space-2);
  font-size: var(--font-sm);
}
.detail-meta-row .label {
  color: var(--text-muted);
  min-width: 48px;
}
.detail-meta-row .value {
  color: var(--text-secondary);
}

.detail-email-body {
  font-size: var(--font-base);
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: var(--space-8);
  word-break: break-word;
}
.detail-email-body a {
  color: var(--accent-start);
  text-decoration: underline;
}

.ai-analysis {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
}
.ai-analysis-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}
.ai-analysis-title .ai-icon {
  font-size: 1.25rem;
}
.ai-section {
  margin-bottom: var(--space-4);
}
.ai-section:last-child {
  margin-bottom: 0;
}
.ai-section-label {
  font-size: var(--font-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.ai-summary-text {
  font-size: var(--font-base);
  color: var(--text-secondary);
  line-height: 1.6;
}

.ai-action-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  font-size: var(--font-sm);
  color: var(--text-secondary);
}
.ai-action-item .check-icon {
  color: var(--accent-start);
  margin-top: 2px;
  flex-shrink: 0;
}

.ai-entities {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.ai-sentiment {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-sm);
}
.sentiment-bar {
  width: 100px;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.sentiment-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.sentiment-positive { background: var(--success); }
.sentiment-negative { background: var(--danger); }
.sentiment-neutral  { background: var(--text-muted); }

.ai-confidence {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}


/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--font-sm);
  transition: var(--ease-default);
  white-space: nowrap;
  line-height: 1.5;
}
.btn-primary {
  background: var(--accent-gradient);
  color: var(--text-white);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.45);
  transform: translateY(-1px);
}
.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  border-color: var(--border-accent);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: var(--danger-dim);
}
.btn-google {
  background: var(--text-white);
  color: #1f1f1f;
  font-weight: 600;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  gap: var(--space-3);
}
.btn-google:hover {
  box-shadow: 0 2px 12px rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}
.btn-google .google-icon {
  width: 18px;
  height: 18px;
}
.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-xs);
}
.btn-block {
  width: 100%;
}


/* ── Forms / Inputs ────────────────────────────────────────── */
.form-group {
  margin-bottom: var(--space-4);
}
.form-label {
  display: block;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-sm);
  transition: var(--ease-fast);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}
.form-select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  transition: var(--ease-default);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-muted);
  border-radius: var(--radius-full);
  transition: var(--ease-default);
}
.toggle input:checked + .toggle-slider {
  background: var(--accent-gradient);
  border-color: transparent;
}
.toggle input:checked + .toggle-slider::before {
  background: var(--text-white);
  transform: translateY(-50%) translateX(20px);
}


/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}
.modal-content {
  width: min(540px, 92vw);
  max-height: 85vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(12px);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.open .modal-content {
  transform: scale(1) translateY(0);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.modal-title {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-primary);
}
.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
}


/* ── Toast Notifications ───────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--space-4));
  right: var(--space-4);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  font-size: var(--font-sm);
  color: var(--text-primary);
  pointer-events: auto;
  animation: slideInRight 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 380px;
}
.toast.toast-exit {
  animation: fadeOutRight 0.3s ease forwards;
}
.toast-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
}
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon   { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon    { color: var(--info); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--info); }


/* ── Analytics ─────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: var(--ease-default);
}
.stat-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-glow);
}
.stat-label {
  font-size: var(--font-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.stat-value {
  font-size: var(--font-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.stat-value.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: var(--space-2);
}
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.chart-title {
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-5);
}
.chart-container {
  width: 100%;
  position: relative;
}
.chart-container svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Chart tooltip */
.chart-tooltip {
  position: absolute;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: var(--font-xs);
  color: var(--text-primary);
  pointer-events: none;
  z-index: 50;
  box-shadow: var(--shadow-card);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.chart-tooltip.visible {
  opacity: 1;
}

/* Chart legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-xs);
  color: var(--text-secondary);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}


/* ── Rules Page ────────────────────────────────────────────── */
.rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.rule-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  transition: var(--ease-default);
}
.rule-item:hover {
  border-color: var(--border-light);
}
.rule-info {
  flex: 1;
  min-width: 0;
}
.rule-name {
  font-weight: 600;
  font-size: var(--font-base);
  color: var(--text-primary);
  margin-bottom: 2px;
}
.rule-desc {
  font-size: var(--font-sm);
  color: var(--text-muted);
}
.rule-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Conditions builder */
.condition-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-2);
}
.condition-row .form-select,
.condition-row .form-input {
  flex: 1;
}
.condition-remove {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: var(--ease-fast);
  flex-shrink: 0;
}
.condition-remove:hover {
  background: var(--danger-dim);
  color: var(--danger);
}


/* ── Accounts Page ─────────────────────────────────────────── */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-4);
}

.account-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: var(--ease-default);
}
.account-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-glow);
}
.account-email {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}
.account-name {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}
.account-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.account-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-sm);
}
.account-detail-row .label { color: var(--text-muted); }
.account-detail-row .value { color: var(--text-secondary); }
.account-actions {
  display: flex;
  gap: var(--space-3);
}


/* ── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}
.page-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  transition: var(--ease-fast);
}
.page-btn:hover {
  border-color: var(--border-light);
  color: var(--text-primary);
}
.page-btn.active {
  background: var(--accent-gradient);
  color: var(--text-white);
  border-color: transparent;
}
.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.page-info {
  font-size: var(--font-sm);
  color: var(--text-muted);
  padding: 0 var(--space-3);
}


/* ── Loading Skeleton ──────────────────────────────────────── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-card);
  border-radius: var(--radius-md);
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.04),
    transparent
  );
  animation: shimmer 1.8s infinite;
}
.skeleton-line {
  height: 14px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
}
.skeleton-line.w-75  { width: 75%; }
.skeleton-line.w-50  { width: 50%; }
.skeleton-line.w-30  { width: 30%; }
.skeleton-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
}
.skeleton-card {
  height: 80px;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-2);
}
.skeleton-stat {
  height: 120px;
  border-radius: var(--radius-lg);
}


/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-8);
  text-align: center;
}
.empty-state-icon {
  font-size: 3.5rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}
.empty-state-title {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}
.empty-state-desc {
  font-size: var(--font-sm);
  color: var(--text-muted);
  max-width: 360px;
}


/* ── Confirm Dialog ────────────────────────────────────────── */
.confirm-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-6);
}


/* ── Animations ────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-24px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOutRight {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(48px); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

@keyframes pulse-glow-warn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

@keyframes drawLine {
  from { stroke-dashoffset: 1000; }
  to   { stroke-dashoffset: 0; }
}

@keyframes donutFill {
  from { stroke-dasharray: 0, 1000; }
}

@keyframes barGrow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.anim-fade-in {
  animation: fadeIn 0.4s ease;
}
.anim-fade-in-up {
  animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}


/* ── Responsive ────────────────────────────────────────────── */

/* Tablet: 1024px */
@media (max-width: 1024px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .accounts-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile: 768px */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
  }

  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
  }

  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-float);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: var(--bg-overlay);
    z-index: 85;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    visibility: visible;
  }

  .app-main {
    margin-left: 0;
    padding: var(--space-4);
  }

  .mobile-menu-btn {
    display: flex;
  }

  .header-center {
    display: none;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-tabs {
    overflow-x: auto;
    flex-shrink: 0;
  }
  .search-box {
    max-width: none;
  }

  .email-item {
    padding: var(--space-3);
    gap: var(--space-3);
  }
  .email-preview {
    display: none;
  }

  .detail-panel {
    width: 100vw;
  }
}

/* Small mobile: 480px */
@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: var(--font-xl);
  }

  .email-avatar {
    width: 34px;
    height: 34px;
    font-size: var(--font-sm);
  }

  .page-title {
    font-size: var(--font-lg);
  }
}
