/* ============================================================
   PRO-S CRM – Global Stylesheet
   Dark mode, Glassmorphism, Inter Font
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── CSS Variables ─────────────────────────────────────────── */
:root {
  --bg-base:       #0d0f1a;
  --bg-surface:    #13162a;
  --bg-card:       rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --bg-input:      rgba(255,255,255,0.06);
  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(99,102,241,0.6);

  --accent:        #6366f1;
  --accent-light:  #818cf8;
  --accent-glow:   rgba(99,102,241,0.3);
  --accent-green:  #22c55e;
  --accent-orange: #f97316;
  --accent-red:    #ef4444;
  --accent-purple: #8b5cf6;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;

  --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg:  0 10px 40px rgba(0,0,0,0.5);

  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  20px;

  --sidebar-w:  240px;
  --header-h:   64px;
  --transition: 0.2s ease;
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background gradient radials */
body::before {
  content: '';
  position: fixed;
  top: -200px; left: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(99,102,241,0.08) 0%, transparent 70%);
  pointer-events: none; z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  bottom: -150px; right: -150px;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(139,92,246,0.06) 0%, transparent 70%);
  pointer-events: none; z-index: 0;
}

/* ─── Layout ────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; position: relative; z-index: 1; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(13,15,26,0.95);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.75rem;
}
.sidebar-logo .logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent-purple));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo .logo-text { line-height: 1.2; }
.sidebar-logo .logo-name { font-weight: 700; font-size: 1rem; color: var(--text-primary); }
.sidebar-logo .logo-sub  { font-size: 0.72rem; color: var(--text-muted); }

.sidebar-nav { flex: 1; padding: 1rem 0.75rem; overflow-y: auto; }
.nav-section-title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.5rem 0.5rem 0.25rem;
  margin-top: 0.5rem;
}
.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.65rem 0.875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
  user-select: none;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.15));
  color: var(--accent-light);
  border: 1px solid rgba(99,102,241,0.2);
}
.nav-item svg { width:16px; height:16px; flex-shrink:0; }

.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--border);
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* Header */
.top-header {
  height: var(--header-h);
  background: rgba(13,15,26,0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.header-subtitle { font-size: 0.8rem; color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* Page content */
.page-content { flex: 1; padding: 1.5rem; }
.page { display: none; }
.page.active { display: block; }

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
}
.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); display:flex; align-items:center; gap:0.5rem; }
.card-body { padding: 1.25rem 1.5rem; }

/* ─── Stats bars ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: all var(--transition);
}
.stat-card:hover { background: var(--bg-card-hover); transform: translateY(-2px); }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; margin-bottom: 0.3rem; }
.stat-label { font-size: 0.78rem; color: var(--text-secondary); }
.stat-card.danger  .stat-value { color: var(--accent-red); }
.stat-card.warning .stat-value { color: var(--accent-orange); }
.stat-card.success .stat-value { color: var(--accent-green); }
.stat-card.info    .stat-value { color: var(--accent-light); }

/* ─── Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
thead th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky; top: 0;
  background: var(--bg-surface);
}
thead th:hover { color: var(--text-secondary); }
thead th.sorted { color: var(--accent-light); }
tbody tr {
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background var(--transition);
}
tbody tr:hover { background: var(--bg-card-hover); }
tbody td { padding: 0.7rem 1rem; vertical-align: middle; color: var(--text-secondary); white-space: nowrap; }
tbody td:first-child { color: var(--text-primary); font-weight: 500; }

/* Status badge for days */
.days-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}
.days-badge.danger  { background: rgba(239,68,68,0.15);  color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.days-badge.warning { background: rgba(249,115,22,0.15); color: #fb923c; border: 1px solid rgba(249,115,22,0.3); }
.days-badge.success { background: rgba(34,197,94,0.15);  color: #4ade80; border: 1px solid rgba(34,197,94,0.3); }
.days-badge.neutral { background: rgba(148,163,184,0.1); color: #94a3b8; border: 1px solid rgba(148,163,184,0.2); }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  font-family: 'Inter', sans-serif;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-purple));
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn-secondary { background: var(--bg-card-hover); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { color: var(--text-primary); background: rgba(255,255,255,0.1); }
.btn-danger { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.25); }
.btn-success { background: rgba(34,197,94,0.15); color: #4ade80; border: 1px solid rgba(34,197,94,0.2); }
.btn-success:hover:not(:disabled) { background: rgba(34,197,94,0.25); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.77rem; }
.btn-icon { width:30px; height:30px; padding:0; display:inline-flex; align-items:center; justify-content:center; border-radius: var(--radius-sm); }

/* ─── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 0.4rem; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  padding: 0.6rem 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.form-input::placeholder { color: var(--text-muted); }
.form-select { appearance: none; cursor: pointer; }
.form-select option { background: var(--bg-surface); }
.form-textarea { resize: vertical; min-height: 120px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ─── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 700px;
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
.modal-lg { max-width: 900px; }
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex; gap: 0.75rem; justify-content: flex-end;
}
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); transition: color var(--transition);
  width:28px; height:28px; display:flex; align-items:center; justify-content:center;
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-card-hover); }

/* ─── Search & Filters ──────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 380px; }
.search-wrap svg { position:absolute; left:0.75rem; top:50%; transform:translateY(-50%); color:var(--text-muted); width:15px; height:15px; pointer-events:none; }
.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  padding: 0.55rem 0.875rem 0.55rem 2.25rem;
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--border-focus); }
.search-input::placeholder { color: var(--text-muted); }

/* ─── Badges & Chips ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-purple { background: rgba(139,92,246,0.2); color: #a78bfa; }
.badge-green  { background: rgba(34,197,94,0.2);  color: #86efac; }
.badge-red    { background: rgba(239,68,68,0.2);   color: #fca5a5; }
.badge-orange { background: rgba(249,115,22,0.2);  color: #fdba74; }
.badge-blue   { background: rgba(59,130,246,0.2);  color: #93c5fd; }

/* ─── Toggle Switch ─────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: rgba(255,255,255,0.1);
  border-radius: 50px;
  transition: .2s;
  border: 1px solid var(--border);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 2px; bottom: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }

/* ─── Pagination ─────────────────────────────────────────────  */
.pagination { display: flex; align-items: center; gap: 0.5rem; justify-content: center; margin-top: 1rem; }
.page-info { color: var(--text-muted); font-size: 0.8rem; }

/* ─── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.alert-success { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.25); color:#4ade80; }
.alert-error   { background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.25);  color:#f87171; }
.alert-info    { background: rgba(99,102,241,0.12); border: 1px solid rgba(99,102,241,0.25); color:#a5b4fc; }

/* ─── Code/Tag ──────────────────────────────────────────────── */
.var-tag {
  display: inline-flex;
  align-items: center;
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.3);
  color: #a5b4fc;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  margin: 2px;
}
.var-tag:hover { background: rgba(99,102,241,0.3); transform: translateY(-1px); }

/* ─── Toast Notifications ───────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1.25rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 0.625rem;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  max-width: 340px;
  pointer-events: auto;
}
.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error   { border-color: rgba(239,68,68,0.3); }
.toast-icon.success { color: #4ade80; }
.toast-icon.error   { color: #f87171; }
.toast-icon.info    { color: #a5b4fc; }

/* ─── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }

/* ─── Loading spinner ───────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.loading-row td { text-align: center; padding: 2rem; color: var(--text-muted); }

/* ─── Email log ─────────────────────────────────────────────── */
.log-status-ok  { color: #4ade80; }
.log-status-err { color: #f87171; }

/* ─── Animations ────────────────────────────────────────────── */
@keyframes fadeIn     { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp    { from { transform:translateY(20px); opacity:0; } to { transform:translateY(0); opacity:1; } }
@keyframes slideInRight { from { transform:translateX(100px); opacity:0; } to { transform:translateX(0); opacity:1; } }
@keyframes fadeOut      { from { opacity:1; } to { opacity:0; } }
@keyframes spin       { to { transform: rotate(360deg); } }

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); width: 240px; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
