/* ============================================================
   CRM-RFM System | Global Stylesheet
   Design: Clean enterprise with accent gold
   ============================================================ */

:root {
  --ink: #0F172A;
  --ink-soft: #1E293B;
  --muted: #64748B;
  --muted-light: #94A3B8;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-light: #EFF6FF;
  --gold: #F59E0B;
  --gold-light: #FFFBEB;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F97316;
  --border: #E2E8F0;
  --surface: #28FAFC;
  --white: #FFFFFF;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow: 0 4px 16px rgba(15,23,42,.08);
  --shadow-lg: 0 8px 32px rgba(15,23,42,.12);
  --font-body: 'DM Sans', sans-serif;
  --font-display: 'DM Serif Display', serif;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── SIDEBAR ──────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--ink);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon {
  width: 34px; height: 34px;
  background: var(--gold);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand span {
  font-size: 16px;
  color: rgba(255,255,255,.7);
  font-weight: 300;
  letter-spacing: .02em;
}
.sidebar-brand b { color: var(--white); font-weight: 600; }

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 12px 8px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  transition: all .18s;
  margin-bottom: 2px;
}
.nav-item svg { width:18px; height:18px; fill:currentColor; flex-shrink:0; }
.nav-item:hover { background: rgba(255,255,255,.07); color: var(--white); }
.nav-item.active {
  background: rgba(245,158,11,.15);
  color: var(--gold);
  font-weight: 500;
}

.sidebar-user {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--gold);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  color: var(--ink);
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: var(--white); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,.4); text-transform: capitalize; }
.logout-btn { color: rgba(255,255,255,.4); transition: color .2s; }
.logout-btn:hover { color: var(--danger); }

/* ── MAIN WRAP ────────────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── TOPBAR ───────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
}
.topbar-title {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.badge-live {
  font-size: 11px;
  color: var(--success);
  font-weight: 500;
}

/* ── PAGE CONTENT ─────────────────────────────────────── */
.page-content { padding: 24px; flex: 1; }

/* ── FLASH MESSAGES ───────────────────────────────────── */
.flash {
  margin: 12px 24px 0;
  padding: 12px 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 500;
}
.flash button { background:none; border:none; cursor:pointer; font-size:16px; }
.flash-success { background: #D1FAE5; color: #065F46; }
.flash-error   { background: #FEE2E2; color: #991B1B; }
.flash-warning { background: #FEF3C7; color: #92400E; }
.flash-info    { background: var(--accent-light); color: #1E40AF; }

/* ── CARDS ────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.card-body { padding: 20px; }

/* ── METRIC CARDS ─────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}
.metric-card.gold::before  { background: var(--gold); }
.metric-card.green::before { background: var(--success); }
.metric-card.red::before   { background: var(--danger); }
.metric-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.metric-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  font-family: var(--font-display);
}
.metric-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.metric-change { font-size: 12px; margin-top: 6px; }
.metric-change.up   { color: var(--success); }
.metric-change.down { color: var(--danger); }

/* ── DASHBOARD GRID ───────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.dashboard-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

/* ── TABLES ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  padding: 10px 14px;
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ── BADGES ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-segment {
  color: var(--white);
}

/* Tier badges */
.tier-Platinum    { background: linear-gradient(135deg,#F59E0B,#D97706); color:#fff; }
.tier-Gold        { background: linear-gradient(135deg,#3B82F6,#2563EB); color:#fff; }
.tier-Silver      { background: linear-gradient(135deg,#10B981,#059669); color:#fff; }
.tier-Blue        { background: linear-gradient(135deg,#F97316,#EA580C); color:#fff; }
.tier-Hibernating { background: linear-gradient(135deg,#6B7280,#4B5563); color:#fff; }

/* Status badges */
.badge-draft     { background:#F1F5F9; color:var(--muted); }
.badge-sent      { background:#D1FAE5; color:#065F46; }
.badge-scheduled { background:var(--accent-light); color:var(--accent); }
.badge-failed    { background:#FEE2E2; color:#991B1B; }

/* Channel badges */
.badge-wa    { background:#DCFCE7; color:#166534; }
.badge-email { background:var(--accent-light); color:var(--accent-hover); }
.badge-sms   { background:#FEF3C7; color:#92400E; }

/* ── FORMS ────────────────────────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: var(--white);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea.form-control { resize: vertical; min-height: 100px; }

/* ── BUTTONS ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid transparent;
  text-decoration: none;
  transition: all .18s;
  white-space: nowrap;
}
.btn svg { width:15px; height:15px; fill:currentColor; }
.btn-primary   { background:var(--ink); color:var(--white); }
.btn-primary:hover { background:var(--ink-soft); }
.btn-accent    { background:var(--accent); color:var(--white); }
.btn-accent:hover { background:var(--accent-hover); }
.btn-gold      { background:var(--gold); color:var(--white); }
.btn-gold:hover { background:#D97706; }
.btn-success   { background:var(--success); color:var(--white); }
.btn-danger    { background:var(--danger); color:var(--white); }
.btn-outline   { background:transparent; border-color:var(--border); color:var(--ink); }
.btn-outline:hover { background:var(--surface); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* ── SEGMENT CARDS ────────────────────────────────────── */
.segment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.segment-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.segment-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.segment-card-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
}
.segment-count {
  font-size: 32px;
  font-weight: 700;
  font-family: var(--font-display);
  line-height: 1;
  margin-bottom: 4px;
}
.segment-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.segment-pct {
  font-size: 12px;
  color: var(--muted-light);
  margin-top: 6px;
}

/* ── COHORT TABLE ─────────────────────────────────────── */
.cohort-table { font-size: 12px; }
.cohort-table th, .cohort-table td { padding: 8px 12px; }
.cohort-cell {
  padding: 6px 10px;
  border-radius: 6px;
  font-weight: 600;
  text-align: center;
}

/* ── CHARTS ───────────────────────────────────────────── */
.chart-container { position: relative; }

/* ── PAGINATION ───────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.page-link {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  transition: all .15s;
  border: 1px solid transparent;
}
.page-link:hover { background:var(--surface); color:var(--ink); border-color:var(--border); }
.page-link.active { background:var(--ink); color:var(--white); }
.page-info { flex:1; text-align:right; font-size:12px; color:var(--muted); }

/* ── MODAL ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background:none; border:none; cursor:pointer;
  color:var(--muted); font-size:20px; line-height:1;
}
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ── UTILS ────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.truncate { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ── SEARCH BAR ───────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.search-input-wrap { position: relative; flex: 1; max-width: 320px; }
.search-input-wrap input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}
.search-input-wrap input:focus { border-color: var(--accent); }
.search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

/* ── RFM SCORE PILLS ──────────────────────────────────── */
.rfm-scores { display: flex; gap: 4px; }
.rfm-pill {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  color: var(--white);
}
.rfm-r { background: var(--accent); }
.rfm-f { background: var(--success); }
.rfm-m { background: var(--gold); }

/* ── EMPTY STATE ──────────────────────────────────────── */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-state svg {
  width: 48px; height: 48px;
  fill: var(--border);
  margin-bottom: 12px;
}
.empty-state p { font-size: 14px; }

/* ── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
