/* ==========================================================================
   Mail Panel — ERP dashboard design system
   Loaded after Bootstrap 5 (CDN). Bootstrap still supplies the grid,
   utilities (row/col, spacing, flex helpers) and JS-free form controls;
   everything visual (color, shape, nav, cards, tables, badges) is redefined
   here so every existing page (which already uses .card/.btn/.table/.badge/
   .alert/.form-control) picks up the new look with no markup changes.
   ========================================================================== */

:root {
  --ink: #14171f;
  --ink-soft: #4b5266;
  --muted: #8a90a3;
  --line: #e6e8f0;
  --line-soft: #eef0f6;
  --surface: #ffffff;
  --canvas: #f4f5fa;

  --brand: #4f46e5;
  --brand-dark: #3f37c9;
  --brand-light: #eef0ff;

  --accent: #06b6a4;
  --accent-light: #e3faf6;

  --success: #16a34a;
  --success-light: #e9f9ee;
  --danger: #dc2626;
  --danger-light: #fdecec;
  --warning: #d97706;
  --warning-light: #fef3e2;
  --info: #2563eb;
  --info-light: #eaf1ff;

  --sidebar-bg: #171a2b;
  --sidebar-bg-soft: #1f2338;
  --sidebar-text: #b7bad0;
  --sidebar-text-active: #ffffff;
  --sidebar-line: rgba(255,255,255,.08);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20,23,31,.05);
  --shadow: 0 4px 16px rgba(20,23,31,.06), 0 1px 2px rgba(20,23,31,.05);
  --shadow-lg: 0 12px 32px rgba(20,23,31,.12);

  --sidebar-w: 240px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 0;
}

h1, h2, h3, h4, h5, h6 { color: var(--ink); font-weight: 700; letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

/* ---------- App shell: sidebar + topbar + content ---------- */

.sidebar-toggle-input { display: none; }
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-soft) 100%);
  background-color: var(--sidebar-bg); /* fallback if gradient/stylesheet is delayed */
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  height: 100dvh; /* tracks the real visual viewport on mobile, avoids a gap when the browser chrome collapses */
  z-index: 1040;
  transition: transform .22s ease;
}

.sidebar-brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-line);
}
.brand-mark { display: flex; align-items: center; gap: .55rem; color: #fff; }
.brand-mark:hover { color: #fff; }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--brand); color: #fff;
}
.brand-logo svg { width: 17px; height: 17px; }
.brand-text { font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }
.brand-text b { font-weight: 800; }
.sidebar-close { display: none; color: var(--sidebar-text); font-size: 1.4rem; cursor: pointer; line-height: 1; }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: .9rem .75rem; }
.sidebar-group-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  font-weight: 700; color: #6a6f89; margin: 1.1rem .6rem .4rem;
}
.sidebar-group-label:first-child { margin-top: .2rem; }

.side-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .85rem .6rem .65rem; margin: .25rem 0;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-weight: 500; font-size: .89rem;
  transition: background .15s ease, color .15s ease;
}
.side-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.side-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-link.active { background: var(--brand); color: var(--sidebar-text-active); box-shadow: var(--shadow-sm); }
.side-link.active .side-icon { opacity: 1; }

.sidebar-foot { padding: .9rem .75rem; border-top: 1px solid var(--sidebar-line); background: rgba(255,255,255,.03); }
.sidebar-user { display: flex; align-items: center; gap: .65rem; padding: .4rem; border-radius: var(--radius-sm); }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-light); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { color: #fff; font-size: .85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-logout { display: block; margin-left: -.25rem; font-size: .76rem; color: var(--sidebar-text); }
.user-logout:hover { color: #fff; }

.sidebar-scrim { display: none; position: fixed; inset: 0; background: rgba(15,17,26,.5); z-index: 1030; }

.app-main { flex: 1 1 auto; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .9rem;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1010;
}
.topbar-burger { display: none; color: var(--ink-soft); cursor: pointer; }
.topbar-burger svg { width: 22px; height: 22px; }
.topbar-title { margin: 0; font-size: 1.15rem; font-weight: 700; flex: 1 1 auto; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.topbar-run-btn { display: inline-flex; align-items: center; gap: .4rem; border-radius: 999px; font-weight: 600; }

.app-content { flex: 1 1 auto; padding: 1.5rem; max-width: 1280px; width: 100%; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar-toggle-input:checked ~ .app-shell .sidebar { transform: translateX(0); }
  .sidebar-toggle-input:checked ~ .app-shell .sidebar-scrim { display: block; }
  .sidebar-close { display: block; }
  .topbar-burger { display: inline-flex; }
  .app-main { margin-left: 0; }
  .app-content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}
.card-header, .card-body, .card-footer { border-color: var(--line); }
.card-header { background: transparent; font-weight: 700; padding: 1rem 1.25rem; }
.card.p-3 { padding: 1.25rem !important; }

/* ---------- Stat tiles ---------- */

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.25rem;
  display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
  height: 100%;
}
.stat-tile-value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; color: var(--ink); }
.stat-tile-label { color: var(--muted); font-size: .8rem; font-weight: 600; margin-top: .3rem; }
.stat-tile-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-tile-icon svg { width: 19px; height: 19px; }
.stat-tile-icon.i-brand { background: var(--brand-light); color: var(--brand); }
.stat-tile-icon.i-accent { background: var(--accent-light); color: var(--accent); }
.stat-tile-icon.i-warn { background: var(--warning-light); color: var(--warning); }
.stat-tile-icon.i-danger { background: var(--danger-light); color: var(--danger); }
.stat-tile-icon.i-success { background: var(--success-light); color: var(--success); }

/* ---------- Buttons ---------- */

.btn { border-radius: 999px; font-weight: 600; font-size: .87rem; padding: .5rem 1.1rem; border-width: 1.5px; }
.btn-sm { padding: .32rem .8rem; font-size: .8rem; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-primary { color: var(--brand); border-color: var(--brand); }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); }
.btn-outline-secondary { color: var(--ink-soft); border-color: var(--line); }
.btn-outline-secondary:hover { background: var(--ink); border-color: var(--ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn:disabled { opacity: .5; }

/* ---------- Forms ---------- */

.form-control, .form-select { border-radius: var(--radius-sm); border-color: var(--line); padding: .55rem .8rem; font-size: .89rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.form-label { font-weight: 600; font-size: .82rem; color: var(--ink-soft); margin-bottom: .3rem; }
.form-text { color: var(--muted); font-size: .78rem; }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.input-group .btn { border-radius: 0 999px 999px 0; }
.input-group .form-control { border-radius: 999px 0 0 999px; }

/* ---------- Tables ---------- */

.table { color: var(--ink); font-size: .87rem; margin-bottom: 0; }
.table thead th {
  color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 700; border-bottom: 1px solid var(--line); padding: .7rem .9rem; background: var(--canvas);
}
.table tbody td { padding: .7rem .9rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr:hover { background: var(--brand-light); }
.card .table { border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }

/* ---------- Badges / status pills ---------- */

/* Non-pill, non-interactive shape everywhere so state labels (running, sent,
   inactive, health, "you") never read as clickable chips/buttons. */
.badge {
  display: inline-flex; align-items: center; gap: .4em;
  border-radius: var(--radius-sm); font-weight: 600; font-size: .72rem;
  padding: .35em .7em; letter-spacing: .01em; cursor: default;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0;
}
.badge.badge-plain::before { display: none; } /* opt out for tag-style badges like "you" / field chips */
.badge-status-sent { background: var(--success-light) !important; color: var(--success) !important; }
.badge-status-failed { background: var(--danger-light) !important; color: var(--danger) !important; }
.badge-status-skipped { background: var(--line-soft) !important; color: var(--muted) !important; }
.badge-status-pending { background: var(--info-light) !important; color: var(--info) !important; }
.badge-status-sending { background: var(--info-light) !important; color: var(--info) !important; }
.badge-status-retry { background: var(--warning-light) !important; color: var(--warning) !important; }
.badge-status-uncertain { background: var(--warning-light) !important; color: var(--warning) !important; }
.bg-info { background: var(--info-light) !important; color: var(--info) !important; }
.bg-success { background: var(--success-light) !important; color: var(--success) !important; }
.bg-secondary { background: var(--line-soft) !important; color: var(--ink-soft) !important; }
.bg-warning { background: var(--warning-light) !important; color: var(--warning) !important; }
.bg-danger { background: var(--danger-light) !important; color: var(--danger) !important; }

/* ---------- Alerts ---------- */

.alert { border: 1px solid transparent; border-left-width: 4px; border-radius: var(--radius-sm); font-size: .87rem; }
.alert-success { background: var(--success-light); border-left-color: var(--success); color: #0d5a2c; }
.alert-danger { background: var(--danger-light); border-left-color: var(--danger); color: #8a1d1d; }
.alert-info { background: var(--info-light); border-left-color: var(--info); color: #1b3f8f; }
.alert-warning { background: var(--warning-light); border-left-color: var(--warning); color: #8a5a08; }

/* ---------- Login page ---------- */

.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 500px at 15% -10%, rgba(79,70,229,.20), transparent),
    radial-gradient(800px 400px at 110% 10%, rgba(6,182,164,.16), transparent),
    var(--sidebar-bg);
  padding: 1.5rem;
}
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.1rem 2rem; }
.login-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.5rem; justify-content: center; }
.login-brand .brand-logo { width: 36px; height: 36px; }
.login-brand .brand-logo svg { width: 20px; height: 20px; }
.login-brand span { font-size: 1.2rem; font-weight: 700; color: var(--ink); }

/* ---------- Misc ---------- */

.table-responsive { -webkit-overflow-scrolling: touch; }
.contacts-scroll { max-height: 70vh; overflow: auto; }
.contacts-scroll table { min-width: 640px; }
.contacts-scroll thead th { position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.contacts-scroll td { white-space: nowrap; }
.text-muted { color: var(--muted) !important; }
hr { border-color: var(--line); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d3d6e3; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }


/* HTML template editor */
.email-editor{border:1px solid #ced4da;border-radius:.5rem;overflow:hidden;background:#fff}
.editor-tabs{display:flex;align-items:center;gap:2px;padding:8px 10px 0;background:#fff;border-bottom:1px solid #dee2e6}
.editor-tab{border:1px solid transparent;border-bottom:0;background:transparent;color:#495057;padding:9px 18px;border-radius:.35rem .35rem 0 0;cursor:pointer;font-size:14px}
.editor-tab:hover{background:#f5f6f7}
.editor-tab.active{background:#f1f3f5;border-color:#ced4da;color:#212529;font-weight:600}
.editor-toolbar{display:flex;gap:4px;flex-wrap:wrap;padding:8px 10px;background:#f8f9fa;border-bottom:1px solid #dee2e6}
.tool-btn{min-width:30px;height:30px;padding:2px 8px;border:1px solid #b9c7ff;background:#fff;color:#173cff;border-radius:3px;font-size:13px;cursor:pointer}
.tool-btn:hover{background:#eef2ff}
.editor-pane{min-height:560px}
.visual-editor{min-height:560px;padding:24px;background:#fff;outline:0;overflow:auto;font-family:Arial,sans-serif}
.visual-editor:focus{box-shadow:inset 0 0 0 2px rgba(13,110,253,.08)}
.code-editor{display:block;width:100%;height:560px;min-height:560px;border:0;outline:0;padding:16px;font:13px/1.55 Consolas,Monaco,"Courier New",monospace;resize:vertical;white-space:pre;tab-size:2}
