/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --primary:       #4f46e5;
  --primary-dark:  #4338ca;
  --primary-light: #eef2ff;
  --primary-ring:  rgba(79,70,229,.12);
  --success:       #16a34a;
  --success-light: #f0fdf4;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;
  --warning:       #d97706;
  --warning-light: #fffbeb;
  --border:        #e2e8f0;
  --muted:         #64748b;
  --card:          #ffffff;
  --radius:        10px;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.05);
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:     0 20px 60px rgba(0,0,0,.14);
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted  { color: var(--muted); }
.text-sm     { font-size: 13px; }
.text-xs     { font-size: 12px; }
.fw-600      { font-weight: 600; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.flex        { display: flex; }
.items-center{ align-items: center; }
.gap-8       { gap: 8px; }

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 58px;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}
.navbar-brand {
  font-size: 17px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.4px;
  margin-right: 12px;
  white-space: nowrap;
}
.navbar-menu { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.nav-btn {
  padding: 6px 13px;
  border: none;
  background: transparent;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  transition: all .15s;
  font-family: inherit;
  white-space: nowrap;
}
.nav-btn:hover  { background: #f1f5f9; color: #1e293b; }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }
.navbar-logout {
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  white-space: nowrap;
}
.navbar-logout:hover { background: var(--danger-light); color: var(--danger); border-color: #fca5a5; }

/* ── Page container ────────────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}
@media (max-width: 600px) { .container { padding: 20px 16px; } }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.4px;
  line-height: 1.2;
}
.page-header p { color: var(--muted); font-size: 14px; margin-top: 3px; }

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 20px 24px; }
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}

/* ── Stats grid ────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 32px;
}
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.stat-icon.purple { background: #ede9fe; }
.stat-icon.green  { background: #dcfce7; }
.stat-icon.blue   { background: #dbeafe; }
.stat-icon.red    { background: #fee2e2; }
.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1;
  letter-spacing: -1px;
}
.stat-label { font-size: 13px; color: var(--muted); margin-top: 5px; }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  background: #f8fafc;
  padding: 11px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafafa; }
.table input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

/* ── Badge ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #f1f5f9; color: var(--muted); }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-ghost   { background: transparent; color: #1e293b; border-color: var(--border); }
.btn-ghost:hover   { background: #f8fafc; }
.btn-sm { padding: 6px 13px; font-size: 13px; }
.btn-xs { padding: 4px 9px;  font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

.action-group { display: flex; gap: 5px; align-items: center; }
.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--muted);
  transition: all .12s;
  font-family: inherit;
  flex-shrink: 0;
}
.btn-icon:hover           { background: #f1f5f9; color: #1e293b; }
.btn-icon.edit:hover      { background: #eff6ff; color: #2563eb; border-color: #bfdbfe; }
.btn-icon.danger:hover    { background: var(--danger-light); color: var(--danger); border-color: #fca5a5; }
.btn-icon.toggle-on:hover { background: var(--warning-light); color: var(--warning); border-color: #fcd34d; }
.btn-icon.toggle-off:hover{ background: var(--success-light); color: var(--success); border-color: #86efac; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 15px; }
.form-group:last-of-type  { margin-bottom: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
label { font-size: 13.5px; font-weight: 500; color: #334155; }
label .req { color: var(--danger); margin-left: 2px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.input, .textarea, select.input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  color: #1e293b;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  width: 100%;
}
.input:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.input::placeholder, .textarea::placeholder { color: #94a3b8; }
.textarea { resize: vertical; min-height: 130px; line-height: 1.6; }
.form-error {
  background: var(--danger-light);
  border: 1px solid #fca5a5;
  color: #991b1b;
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 14px;
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-body   { padding: 18px 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ── Toast ─────────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
  width: calc(100vw - 40px);
}
.toast {
  padding: 12px 16px 12px 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  color: #1e293b;
  pointer-events: all;
  animation: toastIn .2s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error   { border-left: 4px solid var(--danger); }
.toast-info    { border-left: 4px solid var(--primary); }
.toast-icon    { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  line-height: 1;
  padding: 0 0 0 8px;
  flex-shrink: 0;
}
@keyframes toastIn { from { opacity:0; transform:translateX(16px); } to { opacity:1; transform:translateX(0); } }

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .65s linear infinite;
  flex-shrink: 0;
}
.spinner-dark { border-color: rgba(0,0,0,.15); border-top-color: var(--primary); }
.spinner-lg   { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty / loading states ────────────────────────────────────────────────── */
.state-box {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
}
.state-box .state-icon { font-size: 44px; margin-bottom: 12px; }
.state-box p { font-size: 15px; }

/* ── Email layout ──────────────────────────────────────────────────────────── */
.email-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 22px;
  align-items: start;
}
@media (max-width: 900px) { .email-layout { grid-template-columns: 1fr; } }

.company-picker { overflow: hidden; }
.company-picker-list {
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 0;
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid #f8fafc;
}
.picker-item:last-child { border-bottom: none; }
.picker-item:hover { background: #f8fafc; }
.picker-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.picker-item .pname { font-size: 13.5px; font-weight: 500; color: #1e293b; }
.picker-item .prole { font-size: 12px; color: var(--muted); }

.attachment-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--primary);
  margin-top: 8px;
}
.attachment-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: #818cf8;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  display: flex;
}
.attachment-tag button:hover { color: var(--danger); }

/* ── Logs filter bar ───────────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.filter-btn {
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .12s;
  color: var(--muted);
  font-family: inherit;
}
.filter-btn:hover  { background: #f8fafc; color: #1e293b; }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Result box ────────────────────────────────────────────────────────────── */
.result-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.7;
}
.result-box .r-sent   { color: var(--success); font-weight: 700; }
.result-box .r-failed { color: var(--danger);  font-weight: 700; }
.result-box .r-errors { margin-top: 8px; font-size: 13px; color: var(--muted); }
.result-box .r-errors li { margin-left: 16px; }

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ede9fe 0%, #dbeafe 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 40px 36px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-logo { text-align: center; margin-bottom: 30px; }
.login-logo h1 { font-size: 28px; font-weight: 800; color: var(--primary); letter-spacing: -0.6px; }
.login-logo p  { color: var(--muted); font-size: 14px; margin-top: 5px; }
