/* =========================================================
   ReraGuruji WhatsApp CRM — design system
   Blue / white theme, tick-motif status language
   ========================================================= */

:root {
  --bg: #F5F8FF;
  --surface: #FFFFFF;
  --surface-sunken: #EEF3FF;
  --primary: #1652F0;
  --primary-dark: #0F3FC4;
  --primary-tint: #E8EFFF;
  --ink: #0B1E3D;
  --muted: #5A6B8C;
  --border: #DCE5FA;
  --success: #1B8A5A;
  --warning: #B9770E;
  --danger: #D1403A;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-soft: 0 1px 2px rgba(11,30,61,0.04), 0 8px 24px -12px rgba(22,82,240,0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 4px 0;
}
h1 { font-size: 1.65rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin-top: 32px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

/* ---------- Shell layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 24px 10px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(155deg, var(--primary), var(--primary-dark));
  display: flex; align-items: center; justify-content: center;
  color: white; font-family: var(--font-display); font-weight: 600; font-size: 1.05rem;
}
.brand-mark-img {
  width: 38px; height: 38px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(11,30,61,0.15);
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; line-height: 1.1; }
.brand-sub { font-family: var(--font-mono); font-size: 0.66rem; color: var(--muted); letter-spacing: 0.04em; }

.nav-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-item a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item a:hover { background: var(--surface-sunken); color: var(--ink); }
.nav-item.active a { background: var(--primary-tint); color: var(--primary-dark); font-weight: 600; }
.nav-icon { width: 16px; text-align: center; font-size: 0.95rem; }

.main { flex: 1; padding: 32px 40px 60px; max-width: 980px; }

.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
  margin-bottom: 24px;
}

/* ---------- Cards / surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 24px;
}

/* Chat-bubble style preview, tail bottom-left, used for template body previews */
.bubble {
  background: var(--primary-tint);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
  padding: 14px 16px;
  color: var(--ink);
  font-size: 0.92rem;
  position: relative;
  max-width: 420px;
}
.bubble-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.bubble mark {
  background: var(--primary);
  color: white;
  padding: 0 4px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.82em;
}

/* ---------- Forms ---------- */
label { display: block; margin-top: 14px; font-weight: 600; font-size: 0.85rem; color: var(--ink); }
.field-hint { font-size: 0.78rem; color: var(--muted); margin-top: 3px; }

input[type=text], input[type=password], input[type=file], select, textarea {
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
textarea { min-height: 90px; resize: vertical; font-family: var(--font-mono); font-size: 0.88rem; }

button, .btn {
  margin-top: 18px;
  background: var(--primary);
  border: none;
  color: white;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: var(--font-body);
  transition: background 0.15s ease, transform 0.05s ease;
}
button:hover, .btn:hover { background: var(--primary-dark); }
button:active, .btn:active { transform: translateY(1px); }
button.secondary { background: var(--surface); color: var(--primary); border: 1.5px solid var(--border); }
button.secondary:hover { background: var(--surface-sunken); }

/* Drag-and-drop CSV zone */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 6px;
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
}
.dropzone.dragover { border-color: var(--primary); background: var(--primary-tint); color: var(--primary-dark); }

/* Tag filter chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.chip {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--primary); color: var(--primary-dark); }
.chip.active { background: var(--primary); border-color: var(--primary); color: white; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 6px; }
th {
  text-align: left; padding: 10px 8px;
  font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); border-bottom: 1.5px solid var(--border);
}
td { padding: 12px 8px; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
tr:last-child td { border-bottom: none; }
tr.row-hidden { display: none; }

/* ---------- Tick status motif ---------- */
.ticks { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 600; }
.ticks svg { display: block; }
.tick-sent .tick-svg path { stroke: var(--muted); }
.tick-sent .tick-label { color: var(--muted); }
.tick-delivered .tick-svg path { stroke: var(--primary); }
.tick-delivered .tick-label { color: var(--primary); }
.tick-read .tick-svg path { stroke: var(--success); }
.tick-read .tick-label { color: var(--success); }
.tick-failed .tick-svg path { stroke: var(--danger); }
.tick-failed .tick-label { color: var(--danger); }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status-APPROVED, .status-approved { background: #E6F5EC; color: var(--success); }
.status-PENDING, .status-pending, .status-sent { background: #FDF2E0; color: var(--warning); }
.status-REJECTED, .status-rejected, .status-failed { background: #FBEAEA; color: var(--danger); }
.status-delivered { background: var(--primary-tint); color: var(--primary-dark); }
.status-read { background: #E6F5EC; color: var(--success); }

/* ---------- Toast ---------- */
#toast-stack {
  position: fixed; top: 20px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 999;
}
.toast {
  background: var(--ink);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(-6px);
  animation: toast-in 0.25s ease forwards;
  max-width: 340px;
}
.toast.toast-error { background: var(--danger); }
@keyframes toast-in { to { opacity: 1; transform: translateY(0); } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(11,30,61,0.45);
  display: none;
  align-items: center; justify-content: center;
  z-index: 998;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-soft);
}
.modal h3 { margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 0.88rem; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { margin-top: 0; flex: 1; }

/* ---------- Stat cards (dashboard) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
}
.stat-card .eyebrow { margin-bottom: 10px; }
.stat-value {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}
.stat-delta {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.stat-delta.up { background: #E6F5EC; color: var(--success); }
.stat-delta.down { background: #FBEAEA; color: var(--danger); }
.stat-delta.flat { background: var(--surface-sunken); color: var(--muted); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.chart-wrap { position: relative; height: 260px; }

.legend-row { display: flex; gap: 18px; margin-top: 14px; font-size: 0.8rem; color: var(--muted); }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.mini-list li:last-child { border-bottom: none; }

/* ---------- Toggle switch (flows active/inactive) ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  transition: background 0.15s ease; cursor: pointer;
}
.switch-track::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: transform 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- Focus visibility ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; border-right: none; border-bottom: 1px solid var(--border); }
  .main { padding: 24px 18px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}