/* ═══════════════════════════════════════════════════════════════
   ReLink Messaging — Modern UI Design System
   ═══════════════════════════════════════════════════════════════ */

:root {
  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --topbar-height: 64px;
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --bg: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: all .2s cubic-bezier(.4,0,.2,1);
  --transition-slow: all .35s cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; }

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

/* ── SIDEBAR ──────────────────────────────────────────────────── */

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  overflow-y: auto;
  overflow-x: hidden;
  transition: var(--transition-slow);
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79,70,229,.4);
}

.brand-text {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
}

/* Nav sections */
.sidebar-nav-section {
  padding: 4px 12px;
}

.nav-section-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: 16px 12px 6px;
  text-transform: uppercase;
}

#sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.65);
  font-size: 14px;
  font-weight: 450;
  transition: var(--transition);
  text-decoration: none;
  position: relative;
  overflow: hidden;
}

#sidebar .nav-link i {
  font-size: 18px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  transition: var(--transition);
}

#sidebar .nav-link span {
  white-space: nowrap;
}

#sidebar .nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
}

#sidebar .nav-link:hover i {
  transform: scale(1.15);
}

#sidebar .nav-link.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(79,70,229,.5) 0%, rgba(6,182,212,.3) 100%);
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(79,70,229,.25);
}

#sidebar .nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.user-card:hover { background: rgba(255,255,255,.06); }

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  line-height: 1.2;
}

.user-role {
  font-size: 11px;
  color: rgba(255,255,255,.4);
}

.logout-btn {
  color: rgba(255,255,255,.4);
  font-size: 16px;
  padding: 6px;
  transition: var(--transition);
  text-decoration: none;
}

.logout-btn:hover { color: var(--danger); transform: translateX(2px); }

/* ── MAIN CONTENT ─────────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  transition: var(--transition-slow);
}

.topbar {
  height: var(--topbar-height);
  background: rgba(255,255,255,.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.sidebar-toggle { color: var(--text); }

.topbar-right {
  margin-left: auto;
}

.content-wrapper {
  padding: 28px 32px 40px;
}

/* ── CARDS ─────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  padding: 16px 20px;
  color: var(--text);
}

.card-body { padding: 20px; }

/* Stat cards */
.stat-card {
  position: relative;
  overflow: hidden;
  border: none;
  transition: var(--transition);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card.stat-patients::before { background: linear-gradient(90deg, #4f46e5, #818cf8); }
.stat-card.stat-contacts::before { background: linear-gradient(90deg, #06b6d4, #67e8f9); }
.stat-card.stat-sent::before { background: linear-gradient(90deg, #8b5cf6, #c084fc); }
.stat-card.stat-delivered::before { background: linear-gradient(90deg, #10b981, #6ee7b7); }
.stat-card.stat-responses::before { background: linear-gradient(90deg, #f59e0b, #fcd34d); }
.stat-card.stat-batches::before { background: linear-gradient(90deg, #ef4444, #fca5a5); }

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 12px;
}

.stat-card.stat-patients .stat-icon { background: rgba(79,70,229,.1); color: var(--primary); }
.stat-card.stat-contacts .stat-icon { background: rgba(6,182,212,.1); color: var(--accent); }
.stat-card.stat-sent .stat-icon { background: rgba(139,92,246,.1); color: #8b5cf6; }
.stat-card.stat-delivered .stat-icon { background: rgba(16,185,129,.1); color: var(--success); }
.stat-card.stat-responses .stat-icon { background: rgba(245,158,11,.1); color: var(--warning); }
.stat-card.stat-batches .stat-icon { background: rgba(239,68,68,.1); color: var(--danger); }

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--text);
}

.stat-card .stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

a.stat-link {
  text-decoration: none;
  color: inherit;
}

a.stat-link:hover .stat-card {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

/* ── TABLES ────────────────────────────────────────────────────── */

.table-modern {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-modern thead th {
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: 12px 16px;
  white-space: nowrap;
}

.table-modern tbody tr {
  transition: var(--transition);
}

.table-modern tbody tr:hover {
  background: var(--surface-hover);
}

.table-modern tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* ── BADGES ────────────────────────────────────────────────────── */

.badge {
  font-weight: 500;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: .02em;
}

.badge-status-delivered, .badge-status-sent-success {
  background: rgba(16,185,129,.1);
  color: #059669;
}

.badge-status-pending {
  background: rgba(100,116,139,.1);
  color: var(--text-muted);
}

.badge-status-error, .badge-status-failed {
  background: rgba(239,68,68,.1);
  color: #dc2626;
}

.badge-status-sent {
  background: rgba(245,158,11,.1);
  color: #d97706;
}

/* ── BUTTONS ───────────────────────────────────────────────────── */

.btn {
  font-weight: 500;
  font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  transition: var(--transition);
  letter-spacing: .01em;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border: none;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  box-shadow: 0 4px 12px rgba(79,70,229,.4);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
  border: none;
  box-shadow: 0 2px 8px rgba(16,185,129,.3);
}

.btn-success:hover {
  box-shadow: 0 4px 12px rgba(16,185,129,.4);
  transform: translateY(-1px);
}

.btn-outline-primary {
  border: 1.5px solid var(--primary);
  color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* ── FORMS ─────────────────────────────────────────────────────── */

.form-control, .form-select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  transition: var(--transition);
  background: var(--surface);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

/* ── ALERTS ────────────────────────────────────────────────────── */

.alert-modern {
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 450;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.alert-success { background: rgba(16,185,129,.1); color: #065f46; border-left: 4px solid var(--success); }
.alert-warning { background: rgba(245,158,11,.1); color: #92400e; border-left: 4px solid var(--warning); }
.alert-danger { background: rgba(239,68,68,.1); color: #991b1b; border-left: 4px solid var(--danger); }
.alert-info { background: rgba(6,182,212,.1); color: #155e75; border-left: 4px solid var(--accent); }

/* ── BREADCRUMBS ───────────────────────────────────────────────── */

.breadcrumb {
  font-size: 13px;
  margin-bottom: 20px;
  padding: 0;
  background: transparent;
}

.breadcrumb-item a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.breadcrumb-item a:hover { text-decoration: underline; }
.breadcrumb-item.active { color: var(--text-muted); }

/* ── PAGE TITLES ───────────────────────────────────────────────── */

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

h3 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}

h5 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ── PAGINATION ────────────────────────────────────────────────── */

.pagination .page-link {
  border: none;
  border-radius: var(--radius-sm);
  margin: 0 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 8px 14px;
  transition: var(--transition);
}

.pagination .page-item.active .page-link {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(79,70,229,.3);
}

.pagination .page-link:hover {
  background: var(--bg);
  color: var(--primary);
}

/* ── LOGIN PAGE ────────────────────────────────────────────────── */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 40%, #334155 100%);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.login-wrapper::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(79,70,229,.3) 0%, transparent 70%);
  top: -200px;
  right: -100px;
  animation: float 8s ease-in-out infinite;
}

.login-wrapper::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(6,182,212,.2) 0%, transparent 70%);
  bottom: -100px;
  left: -50px;
  animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-30px) scale(1.05); }
}

.login-card {
  background: rgba(255,255,255,.07);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: 0 25px 50px rgba(0,0,0,.3);
  animation: cardSlideUp .6s cubic-bezier(.4,0,.2,1);
}

@keyframes cardSlideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-card .brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  font-size: 24px;
}

.login-card h4 {
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -.02em;
  text-align: center;
  margin-bottom: 8px;
}

.login-card .login-subtitle {
  color: rgba(255,255,255,.5);
  font-size: 14px;
  text-align: center;
  margin-bottom: 32px;
}

.login-card .form-label {
  color: rgba(255,255,255,.7);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.login-card .form-control {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  padding: 12px 16px;
}

.login-card .form-control::placeholder { color: rgba(255,255,255,.3); }
.login-card .form-control:focus {
  background: rgba(255,255,255,.1);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.2);
}

.login-card .btn-primary {
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  width: 100%;
}

/* ── FILTER PILLS ──────────────────────────────────────────────── */

.filter-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-pills .btn {
  font-size: 13px;
  padding: 6px 16px;
  border-radius: 20px;
}

/* ── DATA TABLE CARD ───────────────────────────────────────────── */

.data-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.data-card .table {
  margin-bottom: 0;
}

/* ── ANIMATIONS ────────────────────────────────────────────────── */

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.stagger-in > * {
  opacity: 0;
  animation: fadeUp .5s cubic-bezier(.4,0,.2,1) forwards;
}

.stagger-in > *:nth-child(1) { animation-delay: .05s; }
.stagger-in > *:nth-child(2) { animation-delay: .1s; }
.stagger-in > *:nth-child(3) { animation-delay: .15s; }
.stagger-in > *:nth-child(4) { animation-delay: .2s; }
.stagger-in > *:nth-child(5) { animation-delay: .25s; }
.stagger-in > *:nth-child(6) { animation-delay: .3s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.hover-lift {
  transition: var(--transition);
}

.hover-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

/* Pulse for action buttons */
.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
  margin-right: 6px;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,.4); }
  70% { box-shadow: 0 0 0 8px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* Count up animation for stat numbers */
.count-up {
  display: inline-block;
  animation: countFade .6s cubic-bezier(.4,0,.2,1);
}

@keyframes countFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Table row stagger */
.table-modern tbody tr {
  animation: tableRowIn .4s cubic-bezier(.4,0,.2,1) both;
}

.table-modern tbody tr:nth-child(1) { animation-delay: .02s; }
.table-modern tbody tr:nth-child(2) { animation-delay: .04s; }
.table-modern tbody tr:nth-child(3) { animation-delay: .06s; }
.table-modern tbody tr:nth-child(4) { animation-delay: .08s; }
.table-modern tbody tr:nth-child(5) { animation-delay: .1s; }
.table-modern tbody tr:nth-child(6) { animation-delay: .12s; }
.table-modern tbody tr:nth-child(7) { animation-delay: .14s; }
.table-modern tbody tr:nth-child(8) { animation-delay: .16s; }
.table-modern tbody tr:nth-child(9) { animation-delay: .18s; }
.table-modern tbody tr:nth-child(10) { animation-delay: .2s; }

@keyframes tableRowIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── DETAIL INFO GRID ──────────────────────────────────────────── */

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.info-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: var(--transition);
}

.info-item:hover { background: #e2e8f0; }

.info-item .info-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.info-item .info-value {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

/* ── RESPONSIVE ────────────────────────────────────────────────── */

@media (max-width: 991.98px) {
  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.show {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .main-content {
    margin-left: 0;
  }

  .content-wrapper {
    padding: 20px 16px;
  }
}

/* ── EMPTY STATES ──────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .3;
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 0;
}

/* ── SECTION DIVIDER ───────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  margin-top: 8px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── CHECKBOXES ────────────────────────────────────────────────── */

.form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* ── COLLAPSE ANIMATION ────────────────────────────────────────── */

.collapse, .collapsing {
  transition: height .3s cubic-bezier(.4,0,.2,1);
}

/* ── SCROLLBAR ─────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
