/* =========================================================
   WebSupportHQ Mail System — Design System v2
   Same class names as before, restyled for a polished,
   modern "full product" look. No markup changes required.
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-light: #eef2ff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #64748b;
  --border: #e2e8f0;
  --surface: #ffffff;
  --bg: #f4f6fb;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --purple: #6d28d9;
  --purple-bg: #ede9fe;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 14px rgba(15,23,42,.06);
  --shadow-hover: 0 6px 20px rgba(15,23,42,.10);
  --hover-bg: #f8fafc;
  --surface-alt: #f8fafc;
}

/* ============================================================
   Dark theme — overrides the same variables everything else already
   uses (var(--surface), var(--bg), var(--ink), etc.), so no markup
   or per-component changes are needed anywhere else in the CSS.
   Keyed off [data-theme="dark"] on <html>, set by an inline script
   in header.php before paint (same anti-flash approach as the
   sidebar collapse feature) so a returning user in dark mode never
   sees a flash of the light theme first.
   ============================================================ */
html[data-theme="dark"] {
  --brand: #6366f1;
  --brand-dark: #818cf8;
  --brand-light: #312e81;
  --ink: #f1f5f9;
  --ink-soft: #cbd5e1;
  --muted: #94a3b8;
  --border: #334155;
  --surface: #1e293b;
  --bg: #0f172a;
  --success: #4ade80;
  --success-bg: #14532d;
  --warn: #fbbf24;
  --warn-bg: #78350f;
  --danger: #f87171;
  --danger-bg: #7f1d1d;
  --info: #60a5fa;
  --info-bg: #1e3a8a;
  --purple: #a78bfa;
  --purple-bg: #4c1d95;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.4);
  --shadow-hover: 0 6px 20px rgba(0,0,0,.5);
  --hover-bg: #263449;
  --surface-alt: #263449;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  margin: 0;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top navigation ---------- */
.topbar {
  background: linear-gradient(180deg, #111827 0%, #0b1120 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 12px 26px;
  flex-wrap: wrap;
  gap: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  font-weight: 800;
  font-size: 16.5px;
  margin-right: 20px;
  letter-spacing: .1px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .brand::before {
  content: "✦";
  color: #818cf8;
  font-size: 16px;
}
.topbar .nav { flex: 1; display: flex; gap: 4px; flex-wrap: wrap; }
.topbar .nav a {
  color: #cbd5e1;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 7px;
  transition: background .15s ease, color .15s ease;
}
.topbar .nav a.active { color: #fff; background: rgba(99,102,241,.22); }
.topbar .nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.topbar .user { font-size: 13px; color: #94a3b8; white-space: nowrap; }
.topbar .user a { color: #a5b4fc; text-decoration: none; }
.topbar .user a:hover { text-decoration: underline; }

.container { max-width: 1800px; margin: 28px auto; padding: 0 24px; width: 96%; }

h1 { font-size: 23px; margin-bottom: 12px; font-weight: 800; letter-spacing: -.2px; }
h2 { font-size: 17px; margin-top: 30px; font-weight: 700; color: var(--ink); }
h3 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); font-size: 14px; }
.muted.small { font-size: 12px; }

/* ---------- Stat cards ---------- */
.cards { display: flex; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 22px;
  box-shadow: var(--shadow);
  min-width: 130px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.card-num { font-size: 27px; font-weight: 800; color: var(--brand); letter-spacing: -.5px; }
.card-label { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* ---------- Module quick-access grid (dashboard) ---------- */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin: 18px 0 8px;
}
.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
  position: relative;
  overflow: hidden;
}
.module-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--module-color, var(--brand));
}
.module-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); border-color: var(--module-color, var(--brand)); }
.module-card .module-icon { font-size: 22px; line-height: 1; }
.module-card .module-title { font-weight: 700; font-size: 15px; }
.module-card .module-desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.module-card .module-badge {
  position: absolute; top: 14px; right: 16px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px;
}

/* ---------- Buttons ---------- */
.btn {
  background: var(--brand); color: #fff; border: none; padding: 9px 18px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 600;
  margin-bottom: 14px; transition: background .15s ease, box-shadow .15s ease, transform .05s ease;
  box-shadow: 0 1px 2px rgba(79,70,229,.25); display: inline-block; text-align: center;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn-secondary { background: #64748b; box-shadow: none; }
.btn-secondary:hover { background: #475569; }
.btn-small { padding: 5px 11px; font-size: 12.5px; margin: 3px 3px; border-radius: 6px; }
.btn-danger { background: var(--danger); box-shadow: none; }
.btn-danger:hover { background: #b91c1c; }

/* ---------- Tables ---------- */
.data-table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.data-table th, .data-table td {
  text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.data-table th { background: var(--surface-alt); font-weight: 700; color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
.data-table tbody tr:hover { background: var(--hover-bg); }
.table-scroll { max-height: 480px; overflow-y: auto; }

/* ---------- Badges ---------- */
.badge { padding: 3px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; letter-spacing: .1px; }
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--danger-bg); color: var(--danger); }
.badge-failed { background: var(--danger-bg); color: var(--danger); }
.badge-none { background: var(--border); color: var(--muted); }
.badge-pending { background: var(--warn-bg); color: var(--warn); }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-followup { background: var(--purple-bg); color: var(--purple); }

.contact-name-link { color: var(--brand); text-decoration: none; font-weight: 600; }
.contact-name-link:hover { text-decoration: underline; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: radial-gradient(circle at top, #1e293b, #0b1120); font-family: 'Inter', sans-serif; }
.login-box { background: #fff; padding: 36px; border-radius: 16px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-box h2 { margin-top: 0; text-align: center; font-weight: 800; }

label { display: block; margin: 12px 0 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13.5px;
  font-family: inherit; transition: border-color .15s ease, box-shadow .15s ease; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
textarea { font-family: inherit; resize: vertical; }

.form-box { background: var(--surface); padding: 22px; border-radius: var(--radius); max-width: 500px; box-shadow: var(--shadow); border: 1px solid var(--border); }

.upload-box { background: var(--surface); padding: 20px 22px; border-radius: var(--radius); margin-bottom: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }

.two-col-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start;
}
.two-col-grid > * { margin-bottom: 0; }
@media (max-width: 1100px) {
  .two-col-grid { grid-template-columns: 1fr; }
}

.filter-box { background: var(--surface); padding: 16px 20px; border-radius: var(--radius); margin-bottom: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.filter-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.filter-row > div { display: flex; flex-direction: column; min-width: 140px; }
.filter-row label { margin: 0 0 4px; }
.filter-actions { display: flex; flex-direction: row; gap: 8px; }
.filter-actions .btn { margin: 0; }
#uploadForm { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
#uploadForm .btn { margin: 0; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin: 10px 0; font-weight: 500; border: 1px solid transparent; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }

.info-box { background: var(--brand-light); border: 1px solid var(--brand); padding: 14px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-top: 20px; color: var(--brand-dark); }

.modal-overlay {
  position: fixed; top:0; left:0; right:0; bottom:0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; z-index: 999; padding: 20px; backdrop-filter: blur(2px);
}
.modal { background: var(--surface); border-radius: 14px; padding: 26px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.contact-picker { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; margin-top: 8px; }
.contact-picker label { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 4px 0; }
.contact-picker input[type=checkbox] { width: auto; }

.progress-bar { background: var(--border); border-radius: 20px; height: 8px; width: 120px; overflow: hidden; }
.progress-fill { background: var(--success); height: 100%; transition: width .4s ease; }

.filter-row { margin: 16px 0; }
.filter-row select { width: auto; display: inline-block; padding: 6px 10px; }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--hover-bg); }

.history-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px; background: var(--surface); }
.history-item .campaign-name { font-weight: 700; margin-bottom: 6px; }
.history-item .row-line { font-size: 13px; margin: 4px 0; color: var(--ink-soft); }

::selection { background: rgba(79,70,229,.2); }

/* ---------- Left sidebar navigation (replaces .topbar layout) ---------- */
/* .topbar rules above are left in place, unused, in case any page still
   references that markup directly — costs nothing to leave them. */

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

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #111827 0%, #0b1120 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-brand {
  font-weight: 800;
  font-size: 16px;
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: .1px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand span { color: #818cf8; font-size: 16px; }

.sidebar-search-wrap { position: relative; padding: 0 14px 12px; }
.sidebar-search-input {
  width: 100%; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1);
  color: #fff; padding: 7px 10px; border-radius: 7px; font-size: 12.5px; font-family: inherit;
}
.sidebar-search-input::placeholder { color: #64748b; }
.sidebar-search-input:focus { outline: none; border-color: #6366f1; background: rgba(255,255,255,.12); }
.sidebar.collapsed .sidebar-search-wrap { display: none; }
.sidebar-search-results {
  display: none; position: absolute; left: 14px; right: 14px; top: 100%; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-hover); max-height: 400px; overflow-y: auto; z-index: 200;
}
.sidebar-search-results.open { display: block; }
.search-group-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 8px 12px 4px;
}
.search-result-item {
  display: flex; flex-direction: column; gap: 1px; padding: 6px 12px; text-decoration: none;
}
.search-result-item:hover { background: var(--hover-bg); }
.search-result-title { color: var(--ink); font-size: 13px; font-weight: 600; }
.search-result-sub { color: var(--muted); font-size: 11.5px; }
.search-no-results { padding: 14px 12px; color: var(--muted); font-size: 12.5px; text-align: center; }

.sidebar-nav {
  flex: 1;
  padding: 10px 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-single, .nav-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  white-space: nowrap;
}
.nav-single:hover, .nav-group-title:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-single.active { color: #fff; background: rgba(99,102,241,.22); font-weight: 600; }

.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px; flex-shrink: 0;
}

.nav-group { display: flex; flex-direction: column; }
.nav-group-title-row { display: flex; align-items: center; }
.nav-group-title { flex: 1; min-width: 0; }
.nav-group-active .nav-group-title { color: #fff; }
.nav-chevron-btn {
  font-size: 10px; color: #64748b; transition: transform .15s ease;
  flex-shrink: 0; padding: 9px 12px 9px 4px; cursor: pointer; border-radius: 7px;
}
.nav-chevron-btn:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-group-open .nav-chevron-btn { transform: rotate(180deg); }

.nav-group-items {
  display: none;
  flex-direction: column;
  padding-left: 30px;
  gap: 1px;
}
.nav-group-open .nav-group-items { display: flex; }
.nav-group-items a {
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 6px;
  transition: background .15s ease, color .15s ease;
}
.nav-group-items a:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-group-items a.active { color: #fff; background: rgba(99,102,241,.18); font-weight: 600; }

.nav-group[data-nav-group="audit"] { margin-top: 8px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 8px; }
.nav-group[data-nav-group="audit"] .nav-group-title { color: #5eead4; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user { font-size: 12.5px; color: #94a3b8; font-weight: 600; margin-bottom: 8px; }

.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: rgba(255,255,255,.06);
  border: none;
  color: #cbd5e1;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background .15s ease, color .15s ease;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.sidebar.collapsed .theme-toggle-btn { justify-content: center; }

.sidebar-account-links { display: flex; flex-direction: column; gap: 4px; }
.sidebar-account-links a { color: #a5b4fc; text-decoration: none; font-size: 12.5px; }
.sidebar-account-links a:hover { text-decoration: underline; }

.main-area {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.sidebar-toggle-mobile {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  background: #111827;
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
}

/* ============================================================
   Desktop sidebar collapse — icon-only rail. Every nav item already
   has an icon, so collapsing to just those is a clean, low-effort
   way to reclaim horizontal space on pages with wide tables (the
   exact pages this was requested for). State remembered via
   localStorage; the inline <script> in header.php applies a marker
   class to <html> before the sidebar paints, so a returning user
   with it collapsed never sees a flash of the full-width version.
   ============================================================ */
.sidebar-collapse-btn {
  background: rgba(255,255,255,.06);
  border: none;
  color: #94a3b8;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.14); color: #fff; }

.sidebar.collapsed {
  width: 64px;
}
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .nav-chevron-btn,
.sidebar.collapsed .nav-group-items,
.sidebar.collapsed .sidebar-user,
.sidebar.collapsed .theme-toggle-btn .nav-label,
.sidebar.collapsed .sidebar-account-links a span {
  display: none;
}
.sidebar.collapsed .sidebar-brand {
  padding: 20px 0 16px;
  justify-content: center;
}
.sidebar.collapsed .sidebar-collapse-btn {
  margin-left: 0;
  transform: rotate(180deg);
}
.sidebar.collapsed .nav-single,
.sidebar.collapsed .nav-group-title {
  justify-content: center;
  padding: 9px 0;
}
.sidebar.collapsed .nav-group-title-row {
  justify-content: center;
}
.sidebar.collapsed .sidebar-account-links {
  align-items: center;
}
.sidebar.collapsed .sidebar-footer {
  padding: 14px 8px;
}
/* Tooltips on hover while collapsed, so item names are still one hover away */
.sidebar.collapsed .nav-single,
.sidebar.collapsed .nav-group-title {
  position: relative;
}
.sidebar.collapsed .nav-single:hover::after,
.sidebar.collapsed .nav-group-title:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background: #111827;
  color: #fff;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  z-index: 100;
  pointer-events: none;
}

/* Pre-paint anti-flash: collapse immediately, before appSidebar's own
   'collapsed' class gets synced onto it by the inline script. */
html.sidebar-collapsed-init .sidebar { width: 64px; }
html.sidebar-collapsed-init .sidebar-brand-text,
html.sidebar-collapsed-init .nav-label,
html.sidebar-collapsed-init .nav-badge,
html.sidebar-collapsed-init .nav-chevron-btn,
html.sidebar-collapsed-init .nav-group-items { display: none; }

@media (max-width: 900px) {
  .sidebar-toggle-mobile { display: block; }
  .sidebar-collapse-btn { display: none; }
  .sidebar {
    position: fixed;
    left: -260px;
    transition: left .2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }
  .sidebar.sidebar-open-mobile { left: 0; }
  .container { padding: 0 12px; margin-top: 60px; }

  /* ============================================================
     Responsive tables — every .data-table on every page becomes a
     stacked card layout below 700px, driven entirely by the paired
     script in header.php that copies each table's own header text
     onto a data-label attribute on every cell (including rows added
     later by app.js via a MutationObserver) — no per-page CSS or JS
     customization needed, this applies system-wide automatically.
     ============================================================ */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 4px 10px; background: var(--surface); box-shadow: var(--shadow);
  }
  .data-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 8px 2px; border-bottom: 1px solid var(--border); text-align: right; font-size: 13px;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label); font-weight: 600; color: var(--ink-soft); text-align: left;
    flex-shrink: 0; font-size: 12px;
  }
  .data-table td:empty { display: none; }
}

