/* ============================================================
   Kaaf Foods™ Mailer — Design System
   Primary: #007336 | Accent: #fdb813
   ============================================================ */

:root {
  --kp-primary: #007336;
  --kp-primary-dark: #005a29;
  --kp-primary-light: #e8f5ee;
  --kp-accent: #fdb813;
  --kp-accent-dark: #d99a00;

  --kp-info: #2196f3;
  --kp-warning: #ff9800;
  --kp-danger: #e74c3c;
  --kp-purple: #9c27b0;
  --kp-success: #16a34a;

  --kp-bg: #f5f7fa;
  --kp-card: #ffffff;
  --kp-text: #0f172a;
  --kp-text-soft: #334155;
  --kp-muted: #64748b;
  --kp-muted-soft: #94a3b8;
  --kp-border: #e2e8f0;
  --kp-border-soft: #f1f5f9;

  --kp-r-sm: 8px;
  --kp-r: 12px;
  --kp-r-lg: 16px;

  --kp-sh-sm: 0 1px 3px rgba(15,23,42,.04);
  --kp-sh: 0 4px 14px rgba(15,23,42,.06);
  --kp-sh-md: 0 12px 32px rgba(15,23,42,.10);
}

/* ---------- DARK MODE ---------- */
body.dark {
  --kp-bg: #0f172a;
  --kp-card: #1e293b;
  --kp-text: #f1f5f9;
  --kp-text-soft: #cbd5e1;
  --kp-muted: #94a3b8;
  --kp-muted-soft: #64748b;
  --kp-border: #334155;
  --kp-border-soft: #1e293b;
  --kp-primary-light: #064e3b;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--kp-bg);
  color: var(--kp-text);
  font-size: 14px;
  line-height: 1.55;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}

h1,h2,h3,h4,h5,h6 { font-weight: 700; letter-spacing: -.01em; color: var(--kp-text); margin: 0 0 8px; }
a { color: var(--kp-primary); text-decoration: none; }
a:hover { color: var(--kp-primary-dark); }

/* ---------- NAVBAR ---------- */
.nav {
  background: #fff;
  border-bottom: 1px solid var(--kp-border);
  height: 62px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 1030;
  gap: 20px;
  box-shadow: 0 1px 3px rgba(15,23,42,.03);
}
body.dark .nav { background: #1e293b; }

.nav .brand {
  font-weight: 800;
  font-size: 17px;
  color: var(--kp-text);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav .brand::before {
  content: '📧';
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--kp-primary), var(--kp-accent));
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.nav .brand span { color: var(--kp-accent); font-size: 12px; }

.nav .links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav .links::-webkit-scrollbar { display: none; }

.nav .links a {
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--kp-text-soft);
  transition: all .15s;
  white-space: nowrap;
}
.nav .links a:hover { background: var(--kp-border-soft); color: var(--kp-primary); }
.nav .links a.active {
  background: var(--kp-primary-light);
  color: var(--kp-primary-dark);
  font-weight: 600;
}
body.dark .nav .links a.active { background: rgba(0,115,54,.25); color: #6ee7b7; }

.nav .user-chip {
  background: var(--kp-border-soft);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--kp-text-soft);
  white-space: nowrap;
}
body.dark .nav .user-chip { background: #334155; }

.nav-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.nav-icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--kp-border);
  background: #fff;
  color: var(--kp-text-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.nav-icon-btn:hover { border-color: var(--kp-primary); color: var(--kp-primary); background: var(--kp-primary-light); }
body.dark .nav-icon-btn { background: #1e293b; }

.hamburger {
  display: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--kp-border);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ---------- CONTAINER ---------- */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}
@media (max-width: 767.98px) { .container { padding: 16px; } }

/* ---------- CARDS ---------- */
.card {
  background: var(--kp-card);
  border: 1px solid var(--kp-border);
  border-radius: var(--kp-r-lg);
  padding: 22px;
  box-shadow: var(--kp-sh-sm);
  margin-bottom: 18px;
  transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--kp-sh); border-color: #c7e5d3; }
.card h3 {
  font-size: 15.5px;
  font-weight: 700;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card.p-0 { padding: 0; overflow: hidden; }

/* ---------- STATS GRID ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: var(--kp-card);
  border: 1px solid var(--kp-border);
  border-radius: var(--kp-r);
  padding: 18px;
  box-shadow: var(--kp-sh-sm);
  transition: transform .15s, box-shadow .15s;
  position: relative;
  overflow: hidden;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--kp-sh); }
.stat .icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
  background: var(--kp-primary-light);
  color: var(--kp-primary);
}
.stat .num {
  font-size: 26px;
  font-weight: 800;
  color: var(--kp-text);
  line-height: 1.1;
  letter-spacing: -.02em;
}
.stat .lbl {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--kp-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: 4px;
}
.stat.blue   .icon { background: #dbeafe; color: #1e40af; }
.stat.green  .icon { background: #dcfce7; color: #166534; }
.stat.orange .icon { background: #fed7aa; color: #9a3412; }
.stat.red    .icon { background: #fee2e2; color: #991b1b; }
.stat.purple .icon { background: #ede9fe; color: #6b21a8; }
.stat.gray   .icon { background: #f1f5f9; color: #475569; }
body.dark .stat.green .icon { background: rgba(22,163,74,.2); }
body.dark .stat.blue .icon { background: rgba(30,64,175,.2); }
body.dark .stat.orange .icon { background: rgba(154,52,18,.2); }
body.dark .stat.red .icon { background: rgba(153,27,27,.2); }
body.dark .stat.purple .icon { background: rgba(107,33,168,.2); }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 10px;
  border: none;
  background: var(--kp-primary);
  color: #fff !important;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { background: var(--kp-primary-dark); box-shadow: 0 6px 16px rgba(0,115,54,.25); color: #fff !important; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-accent { background: var(--kp-accent); color: #0f172a !important; }
.btn-accent:hover { background: var(--kp-accent-dark); color: #0f172a !important; box-shadow: 0 6px 16px rgba(253,184,19,.3); }

.btn-danger { background: var(--kp-danger); }
.btn-danger:hover { background: #b71c1c; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--kp-border);
  color: var(--kp-text-soft) !important;
}
.btn-outline:hover { border-color: var(--kp-primary); color: var(--kp-primary) !important; background: var(--kp-primary-light); box-shadow: none; }

.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

.btn-group { display: inline-flex; gap: 6px; }

/* ---------- FORMS ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--kp-text-soft);
  margin-bottom: 6px;
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="file"], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--kp-border);
  border-radius: 10px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--kp-text);
  background: var(--kp-card);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--kp-primary);
  box-shadow: 0 0 0 3px rgba(0,115,54,.12);
}
textarea { min-height: 120px; resize: vertical; font-family: 'Consolas', 'Monaco', monospace; line-height: 1.6; }
select[multiple] { min-height: 140px; padding: 6px; }
.hint { display: block; font-size: 12px; color: var(--kp-muted); margin-top: 5px; }
code { background: var(--kp-border-soft); padding: 2px 6px; border-radius: 5px; font-size: 12.5px; font-family: 'Consolas', monospace; color: var(--kp-primary-dark); }

/* ---------- TABLES ---------- */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table thead th {
  background: var(--kp-border-soft);
  padding: 12px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--kp-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1.5px solid var(--kp-border);
  white-space: nowrap;
}
table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--kp-border-soft);
  color: var(--kp-text-soft);
  vertical-align: middle;
}
table tbody tr { transition: background .12s; }
table tbody tr:hover { background: var(--kp-primary-light); }
body.dark table tbody tr:hover { background: rgba(0,115,54,.08); }

/* ---------- BADGES ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active, .badge.sent, .badge.on { background: #dcfce7; color: #166534; }
.badge.pending, .badge.queued { background: #fef3c7; color: #92400e; }
.badge.failed, .badge.bounced, .badge.suspended { background: #fee2e2; color: #991b1b; }
.badge.unsubscribed { background: #f1f5f9; color: #475569; }
.badge.paused, .badge.off { background: #f1f5f9; color: #64748b; }

/* ---------- ALERTS ---------- */
.alert {
  padding: 14px 18px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-info { background: #dbeafe; color: #1e40af; border-left: 4px solid #3b82f6; }
.alert-success { background: #dcfce7; color: #166534; border-left: 4px solid #16a34a; }
.alert-error { background: #fee2e2; color: #991b1b; border-left: 4px solid #e74c3c; }
.alert-warning { background: #fef3c7; color: #92400e; border-left: 4px solid #f59e0b; }

/* ---------- QUOTA BARS ---------- */
.quota { margin-bottom: 16px; }
.quota.disabled { opacity: .45; }
.quota-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: 6px;
}
.quota-head span:last-child { font-size: 12px; color: var(--kp-muted); font-weight: 600; }
.quota-bar {
  height: 8px;
  background: var(--kp-border-soft);
  border-radius: 20px;
  overflow: hidden;
}
.quota-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--kp-primary), #10b981);
  border-radius: 20px;
  transition: width .5s cubic-bezier(.4,0,.2,1);
}

/* ---------- GRID ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- LOGIN ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #007336 0%, #005a29 50%, #003d1c 100%);
  position: relative;
  overflow: hidden;
}
.login-wrap::before {
  content: '';
  position: absolute;
  top: -50%; right: -50%;
  width: 100%; height: 100%;
  background: radial-gradient(circle, rgba(253,184,19,.15) 0%, transparent 60%);
  animation: float 20s infinite ease-in-out;
}
@keyframes float { 0%,100% { transform: translate(0,0); } 50% { transform: translate(-30px,30px); } }

.login-box {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
  position: relative;
  z-index: 2;
}
.login-box h1 {
  font-size: 24px;
  margin: 0 0 6px;
  text-align: center;
  color: var(--kp-primary-dark);
}
.login-box .sub {
  text-align: center;
  font-size: 13px;
  color: var(--kp-muted);
  margin-bottom: 28px;
}
.login-box form button {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--kp-primary), var(--kp-primary-dark));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: .15s;
  margin-top: 8px;
}
.login-box form button:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0,115,54,.35); }

/* ---------- TOAST ---------- */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 13px 20px;
  border-radius: 12px;
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: 0 12px 32px rgba(15,23,42,.22);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  max-width: 360px;
  animation: slideIn .3s cubic-bezier(.4,0,.2,1);
  pointer-events: auto;
}
.toast.removing { animation: slideOut .25s forwards; }
.toast-success { background: linear-gradient(135deg, #16a34a, #15803d); }
.toast-error   { background: linear-gradient(135deg, #e74c3c, #b71c1c); }
.toast-warning { background: linear-gradient(135deg, #ff9800, #e65100); }
.toast-info    { background: linear-gradient(135deg, #2196f3, #1565c0); }
.toast .t-icon { font-size: 18px; }

@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateX(120%); opacity: 0; } }

/* ---------- LOADING OVERLAY ---------- */
#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}
#loadingOverlay.show { display: flex; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinner-sm {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}

/* ---------- MODAL ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9990;
  padding: 20px;
  animation: fadeIn .2s;
}
.modal-backdrop.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--kp-card);
  border-radius: 16px;
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  animation: zoomIn .25s cubic-bezier(.4,0,.2,1);
}
@keyframes zoomIn { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-head {
  padding: 18px 24px;
  background: linear-gradient(135deg, var(--kp-primary), var(--kp-primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 15px;
  border-radius: 16px 16px 0 0;
}
.modal-head .close {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}
.modal-head .close:hover { background: rgba(255,255,255,.3); }
.modal-body { padding: 22px 24px; }
.modal-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--kp-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- SKELETON ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--kp-border-soft) 25%, var(--kp-border) 50%, var(--kp-border-soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- TABS ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid var(--kp-border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 10px 18px;
  border: none;
  background: transparent;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--kp-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  margin-bottom: -1.5px;
  transition: all .15s;
}
.tab:hover { color: var(--kp-primary); }
.tab.active { color: var(--kp-primary-dark); border-bottom-color: var(--kp-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .25s; }

/* ---------- RICH EDITOR (Quill container) ---------- */
.editor-wrap { border-radius: 12px; overflow: hidden; border: 1.5px solid var(--kp-border); }
.editor-wrap .ql-toolbar {
  background: var(--kp-border-soft);
  border: none;
  border-bottom: 1.5px solid var(--kp-border);
  padding: 8px 12px;
}
.editor-wrap .ql-container {
  border: none;
  font-family: inherit;
  font-size: 14px;
  min-height: 260px;
}
.editor-wrap .ql-editor { min-height: 260px; padding: 16px; }

/* ---------- PREVIEW IFRAME ---------- */
.preview-frame {
  width: 100%;
  height: 480px;
  border: 1.5px solid var(--kp-border);
  border-radius: 12px;
  background: #fff;
}

/* ---------- MISC ---------- */
.text-muted { color: var(--kp-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }

/* Animated counters */
[data-count] { display: inline-block; }

/* Responsive */
@media (max-width: 767.98px) {
  .nav { padding: 0 12px; gap: 8px; }
  .nav .brand { font-size: 14px; }
  .nav .brand::before { width: 30px; height: 30px; font-size: 15px; }
  .nav .links { display: none; }
  .nav .links.show {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 62px; left: 0; right: 0;
    background: #fff;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
    align-items: stretch;
  }
  .hamburger { display: inline-flex; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .stat .num { font-size: 22px; }
  .stat .icon { width: 38px; height: 38px; font-size: 17px; margin-bottom: 8px; }
  .login-box { padding: 28px 22px; }
  .card { padding: 16px; }
}

/* Dark mode inputs */
body.dark input, body.dark select, body.dark textarea {
  background: #0f172a;
  color: #f1f5f9;
  border-color: #334155;
}
body.dark input:focus, body.dark select:focus, body.dark textarea:focus {
  border-color: var(--kp-accent);
  box-shadow: 0 0 0 3px rgba(253,184,19,.15);
}
body.dark .alert-info { background: rgba(30,64,175,.2); color: #93c5fd; }
body.dark .alert-success { background: rgba(22,163,74,.2); color: #86efac; }
body.dark .alert-error { background: rgba(153,27,27,.2); color: #fca5a5; }
body.dark .badge.active, body.dark .badge.sent { background: rgba(22,163,74,.2); color: #86efac; }
body.dark .badge.failed, body.dark .badge.bounced { background: rgba(153,27,27,.2); color: #fca5a5; }
body.dark code { background: #334155; color: #fdb813; }