/* ───────────────────────────────────────────────────────────────────────────
   MailShield — Main Stylesheet
   Dark-mode glassmorphism design + fully responsive
   ─────────────────────────────────────────────────────────────────────────── */

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

:root {
  --bg:          #070c18;
  --surface:     #0d1422;
  --surface-2:   #111827;
  --border:      #1e293b;
  --border-2:    #243044;
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;

  --red:         #ef4444;
  --orange:      #f97316;
  --green:       #22c55e;
  --blue:        #3b82f6;
  --purple:      #7c3aed;
  --yellow:      #eab308;

  --sidebar-w:           220px;
  --sidebar-w-collapsed: 64px;
  --topbar-h:            56px;
  --radius:              10px;
  --radius-sm:           6px;

  --shadow: 0 4px 24px #00000050;
  --glow-red: 0 0 24px #ef444430;
  --row-hover: #ffffff05;
  --overlay:   #00000060;
  --overlay-strong: #00000080;

  --alert-error-text:   #fca5a5;
  --alert-success-text: #86efac;
}

:root[data-theme="light"] {
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --surface-2:   #e2e8f0;
  --border:      #e2e8f0;
  --border-2:    #cbd5e1;
  --text:        #0f172a;
  --text-muted:  #64748b;
  --text-dim:    #475569;

  /* accent colors unchanged (red/orange/green/blue/purple/yellow) */

  --shadow: 0 4px 24px #0f172a1a;
  --glow-red: 0 0 24px #ef444445;
  --row-hover: #0f172a0d;
  /* overlays stay dark-translucent in both themes so they dim content */

  --alert-error-text:   #b91c1c;
  --alert-success-text: #15803d;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login Page ─────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, #3b1f5520 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 80% 80%, #ef444415 0%, transparent 60%),
    var(--bg);
}

.login-container { width: 100%; max-width: 400px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo { margin-bottom: 1.25rem; }

.login-title {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ef4444, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: .35rem;
}

.login-subtitle { color: var(--text-muted); margin-bottom: 2rem; font-size: .9rem; }

.login-form { text-align: left; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.form-group input,
.filter-input,
.filter-select,
.muted-input {
  width: 100%;
  padding: .65rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  transition: border-color .15s;
  outline: none;
}
.form-group input:focus,
.filter-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px #3b82f620;
}
.filter-select { width: auto; cursor: pointer; }
.muted-input { color: var(--text-muted); cursor: not-allowed; }

/* Ensure 'x' clear button appears on search inputs */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: searchfield-cancel-button;
  cursor: pointer;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--full { width: 100%; justify-content: center; }
.btn--sm { padding: .35rem .8rem; font-size: .8rem; }
.btn--primary { background: linear-gradient(135deg, #ef4444, #7c3aed); color: #fff; }
.btn--danger   { background: var(--red); color: #fff; }
.btn--success  { background: var(--green); color: #fff; }
.btn--ghost    { background: transparent; border: 1px solid var(--border-2); color: var(--text-dim); }
.btn--ghost:hover { border-color: var(--blue); color: var(--text); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge--danger,
.badge--rate,
.badge--hourly_rate,
.badge--daily_rate    { background: #ef444420; color: var(--red); border: 1px solid #ef444440; }
.badge--success        { background: #22c55e20; color: var(--green); border: 1px solid #22c55e40; }
.badge--warning,
.badge--soft_bounce    { background: #f9731620; color: var(--orange); border: 1px solid #f9731640; }
.badge--info,
.badge--hard_bounce    { background: #3b82f620; color: var(--blue); border: 1px solid #3b82f640; }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .875rem;
  border: 1px solid;
}
.alert--error   { background: #ef444415; border-color: #ef444440; color: var(--alert-error-text); }
.alert--success { background: #22c55e15; border-color: #22c55e40; color: var(--alert-success-text); }

/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL — Sidebar + Main content
   ═══════════════════════════════════════════════════════════════════════════ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Mobile top bar (hamburger) ──────────────────────────────────────────── */
.topbar {
  display: none;            /* hidden on desktop */
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 200;
}

.topbar-brand {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1rem; font-weight: 700;
  background: linear-gradient(135deg, #ef4444, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: .4rem;
  color: var(--text-dim);
  font-size: 1.15rem;
  line-height: 1;
  transition: color .15s;
}
.hamburger:hover { color: var(--text); }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: 149;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 150;
  transition: transform .25s cubic-bezier(.4,0,.2,1),
              width     .25s cubic-bezier(.4,0,.2,1);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ef4444, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .85rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav-link:hover { background: var(--border); color: var(--text); text-decoration: none; }
.nav-link--active {
  background: linear-gradient(135deg, #ef444415, #7c3aed15);
  color: var(--text);
  border: 1px solid #7c3aed30;
}

.nav-icon { font-size: 1rem; width: 1.2rem; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: .5rem .75rem .75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .25rem;
}

.sidebar-control {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .55rem .85rem;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar-control:hover { background: var(--border); color: var(--text); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .25rem;
  padding: .5rem .35rem 0;
  border-top: 1px solid var(--border);
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-username {
  flex: 1; font-size: .8rem; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-logout {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; padding: .25rem;
  transition: color .15s;
}
.btn-logout:hover { color: var(--red); }

/* ── Main Content ───────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 1.75rem 2rem;
  min-height: 100vh;
  min-width: 0; /* prevent flex overflow */
  transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}

/* ── Collapsed sidebar (desktop icon rail) ──────────────────────────────────── */
.sidebar--collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.sidebar--collapsed .main-content { margin-left: var(--sidebar-w-collapsed); }

.sidebar--collapsed .nav-label,
.sidebar--collapsed .sidebar-brand-name,
.sidebar--collapsed .sidebar-username,
.sidebar--collapsed .sidebar-control .nav-label {
  display: none;
}

/* Center icons when collapsed */
.sidebar--collapsed .nav-link,
.sidebar--collapsed .sidebar-control { justify-content: center; gap: 0; padding-left: 0; padding-right: 0; }
.sidebar--collapsed .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar--collapsed .sidebar-user { justify-content: center; border-top: none; margin-top: 0; }
.sidebar--collapsed .btn-logout { display: none; }

/* Pre-paint collapsed state set by the bootstrap script, before main.js
   migrates the flag from <html> to <body>. Prevents a width/label flash. */
html.preload-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
html.preload-collapsed .main-content { margin-left: var(--sidebar-w-collapsed); }
html.preload-collapsed .nav-label,
html.preload-collapsed .sidebar-brand-name,
html.preload-collapsed .sidebar-username,
html.preload-collapsed .sidebar-control .nav-label {
  display: none;
}

/* ── Page Header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.75rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.page-subtitle { color: var(--text-muted); font-size: .85rem; margin-top: .15rem; }
.header-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.live-badge {
  background: #22c55e20;
  border: 1px solid #22c55e60;
  color: var(--green);
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.card--compact { padding: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: .95rem; font-weight: 600; }

/* ── Stat Grid ──────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform .15s;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-icon { font-size: 1.5rem; flex-shrink: 0; color: var(--text-dim); width: 2rem; text-align: center; }
.stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--text-muted); font-size: .75rem; margin-top: .2rem; text-transform: uppercase; letter-spacing: .05em; }

.stat-card--neutral  { border-color: var(--border-2); }
.stat-card--danger   { border-color: #ef444440; box-shadow: var(--glow-red); }
.stat-card--warning  { border-color: #f9731640; }
.stat-card--info     { border-color: #3b82f640; }

.stat-card--danger  .stat-value { color: var(--red); }
.stat-card--warning .stat-value { color: var(--orange); }
.stat-card--info    .stat-value { color: var(--blue); }

/* ── Two-column layout ──────────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

/* ── Chart ──────────────────────────────────────────────────────────────── */
.chart-wrap {
  padding: 1.25rem;
  height: 240px;
  position: relative;
}

/* ── Data Table (with horizontal scroll on small screens) ───────────────── */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 540px;   /* prevents columns from collapsing too small */
  border-collapse: collapse;
  font-size: .85rem;
}
.data-table th {
  text-align: left;
  padding: .75rem 1.25rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
  white-space: nowrap;
}
.data-table td {
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--row-hover); }
.data-table .mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: .82rem; }
.data-table .muted { color: var(--text-muted); }
.data-table .nowrap { white-space: nowrap; }
.table-link { color: var(--text-dim); }
.table-link:hover { color: var(--blue); }

/* ── Rate Bar ───────────────────────────────────────────────────────────── */
.rate-bar-wrap {
  display: flex; align-items: center; gap: .75rem;
}
.rate-bar {
  height: 6px; border-radius: 3px;
  max-width: 120px; min-width: 4px;
  flex-shrink: 0;
  transition: width .3s;
}

/* ── Filter bar ─────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .75rem 1rem;
  flex-wrap: wrap;
}
.filter-input { flex: 1; min-width: 180px; }

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: .9rem;
}
.hidden { display: none !important; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--overlay-strong);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  width: 100%; max-width: 460px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.1rem; }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }

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

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tablet / small desktop (≤ 1024px) ─────────────────────────────────── */
@media (max-width: 1024px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

/* ── Mobile (≤ 768px) ───────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Show top bar, hide sidebar brand close button is via JS */
  .topbar { display: flex; }

  /* Sidebar slides off-screen by default */
  .sidebar {
    transform: translateX(-100%);
    top: 0;  /* full height from top on mobile */
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Push content below the topbar */
  .main-content {
    margin-left: 0;
    padding: 1.25rem 1rem;
    padding-top: calc(var(--topbar-h) + 1.25rem);
  }

  /* Stat grid: 2 columns on mobile */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
  }

  .stat-value { font-size: 1.4rem; }
  .stat-icon  { font-size: 1.3rem; }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .5rem;
    margin-bottom: 1.25rem;
  }

  .page-title { font-size: 1.25rem; }

  /* Card header wraps */
  .card-header { flex-direction: column; align-items: flex-start; }

  /* Chart shorter on mobile */
  .chart-wrap { height: 200px; }

  /* Filter bar stacks */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-input { min-width: 0; }
  .filter-select { width: 100%; }

  /* Modal full-width */
  .modal { padding: 1.25rem; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; justify-content: center; }

  /* Collapse rail is a desktop-only feature; mobile uses the hamburger overlay */
  .sidebar-control--collapse { display: none; }

  .sidebar--collapsed .sidebar,
  html.preload-collapsed .sidebar { width: var(--sidebar-w); }
  .sidebar--collapsed .main-content,
  html.preload-collapsed .main-content { margin-left: 0; }
  .sidebar--collapsed .nav-label,
  .sidebar--collapsed .sidebar-control .nav-label,
  .sidebar--collapsed .sidebar-brand-name,
  .sidebar--collapsed .sidebar-username,
  html.preload-collapsed .nav-label,
  html.preload-collapsed .sidebar-control .nav-label,
  html.preload-collapsed .sidebar-brand-name,
  html.preload-collapsed .sidebar-username { display: inline; }
  .sidebar--collapsed .nav-link,
  .sidebar--collapsed .sidebar-control { justify-content: flex-start; gap: .75rem; }
  .sidebar--collapsed .btn-logout { display: inline; }
  .sidebar--collapsed .sidebar-user {
    justify-content: flex-start;
    border-top: 1px solid var(--border);
    margin-top: .25rem;
  }
  .sidebar--collapsed .sidebar-brand {
    justify-content: flex-start;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }
}

/* ── Very small (≤ 480px) ───────────────────────────────────────────────── */
@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: .6rem;
  }
  .stat-card { padding: .85rem; gap: .65rem; }
  .stat-value { font-size: 1.25rem; }

  /* Header actions stack below title */
  .header-actions { width: 100%; justify-content: flex-start; }

  /* Table cells tighter */
  .data-table th,
  .data-table td { padding: .6rem .85rem; }

  .main-content { padding: 1rem .75rem; padding-top: calc(var(--topbar-h) + 1rem); }
}
