/* =============================================
   CRM Reformas - Main Stylesheet
   ============================================= */

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

/* ---- CSS Variables ---- */
:root {
  --primary:        #6366f1;
  --primary-dark:   #4f46e5;
  --primary-light:  #818cf8;
  --secondary:      #0ea5e9;
  --success:        #10b981;
  --warning:        #f59e0b;
  --danger:         #ef4444;
  --purple:         #a855f7;
  --info:           #06b6d4;

  --bg:             #0f172a;
  --bg-card:        #1e293b;
  --bg-card2:       #162032;
  --bg-input:       #0f1e2e;
  --border:         #2d3f55;
  --border-light:   #374151;

  --text:           #e2e8f0;
  --text-muted:     #94a3b8;
  --text-dim:       #64748b;

  --sidebar-w:      260px;
  --radius:         12px;
  --radius-sm:      8px;
  --shadow:         0 4px 24px rgba(0,0,0,.35);
  --shadow-sm:      0 2px 8px rgba(0,0,0,.2);

  --transition:     all .2s ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary-light); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary); }
img { max-width: 100%; }
button, input, select, textarea { font-family: inherit; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* =============================================
   LAYOUT
   ============================================= */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #141c2e 0%, #0d1626 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .3s ease;
}
.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-brand .brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.sidebar-brand .brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-brand .brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}
.nav-section {
  padding: 8px 16px 4px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 0;
  position: relative;
  transition: var(--transition);
}
.nav-item:hover {
  color: var(--text);
  background: rgba(99,102,241,.1);
}
.nav-item.active {
  color: var(--primary-light);
  background: rgba(99,102,241,.15);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  height: 60%;
  width: 3px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}
.nav-item .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}
.user-info .user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.user-info .user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: capitalize;
}
.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-logout:hover {
  background: rgba(239,68,68,.2);
  color: #fff;
}

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
}
.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.page-content {
  padding: 28px;
  flex: 1;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 0.95rem; }
.btn-icon { padding: 8px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,.4); }
.btn-secondary { background: var(--bg-card2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; transform: translateY(-1px); }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: #d97706; color: #000; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #0891b2; color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg-card2); color: var(--text); border-color: var(--border); }

/* =============================================
   CARDS
   ============================================= */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* =============================================
   STAT CARDS (Dashboard)
   ============================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: var(--stat-color, var(--primary));
}
.stat-icon {
  font-size: 1.6rem;
  margin-bottom: 8px;
}
.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}
.stat-card.primary { --stat-color: var(--primary); }
.stat-card.success { --stat-color: var(--success); }
.stat-card.warning { --stat-color: var(--warning); }
.stat-card.danger  { --stat-color: var(--danger); }
.stat-card.info    { --stat-color: var(--info); }
.stat-card.purple  { --stat-color: var(--purple); }

/* =============================================
   TABLE
   ============================================= */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}
thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg-card2);
  border-bottom: 1px solid var(--border);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.025); }
tbody td {
  padding: 12px 14px;
  color: var(--text);
  vertical-align: middle;
}
.td-muted { color: var(--text-muted); font-size: 0.82rem; }

/* =============================================
   BADGES
   ============================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-primary { background: rgba(99,102,241,.2); color: var(--primary-light); }
.badge-success { background: rgba(16,185,129,.2); color: #34d399; }
.badge-warning { background: rgba(245,158,11,.2); color: #fbbf24; }
.badge-danger  { background: rgba(239,68,68,.2);  color: #f87171; }
.badge-info    { background: rgba(6,182,212,.2);   color: #22d3ee; }
.badge-purple  { background: rgba(168,85,247,.2);  color: #c084fc; }
.badge-secondary { background: rgba(148,163,184,.1); color: var(--text-muted); }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* =============================================
   FORMS
   ============================================= */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  transition: var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-control::placeholder { color: var(--text-dim); }
select.form-control option { background: var(--bg-card); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
}
.form-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-check input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
}

/* =============================================
   ALERTS / FLASH
   ============================================= */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  margin-bottom: 20px;
  font-weight: 500;
}
.alert-success { background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.3); color: #34d399; }
.alert-error   { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: #f87171; }
.alert-info    { background: rgba(6,182,212,.12);   border: 1px solid rgba(6,182,212,.3);  color: #22d3ee; }
.alert-warning { background: rgba(245,158,11,.12);  border: 1px solid rgba(245,158,11,.3); color: #fbbf24; }

/* =============================================
   MODAL
   ============================================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: min(500px, 95vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: modalIn .25s ease;
}
@keyframes modalIn {
  from { transform: scale(.95) translateY(-10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }

/* =============================================
   PAGE HEADER
   ============================================= */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header-title h1 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
}
.page-header-title p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 3px;
}
.page-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* =============================================
   FILTERS BAR
   ============================================= */
.filters-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.filters-bar .form-control { max-width: 200px; padding: 7px 12px; font-size: 0.83rem; }
.filter-label { font-size: 0.78rem; color: var(--text-muted); align-self: center; font-weight: 600; }

/* =============================================
   LEAD DETAIL
   ============================================= */
.lead-detail-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1024px) {
  .lead-detail-grid { grid-template-columns: 1fr; }
}
.detail-field { margin-bottom: 14px; }
.detail-field label {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
  color: var(--text-dim);
  display: block;
  margin-bottom: 3px;
}
.detail-field span {
  font-size: 0.9rem;
  color: var(--text);
}

/* Timeline / History */
.timeline { list-style: none; padding: 0; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-left: 2px solid var(--border);
  margin-left: 8px;
  padding-left: 16px;
  position: relative;
}
.timeline-item::before {
  content: '';
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--primary);
  position: absolute;
  left: -6px; top: 14px;
}
.timeline-content { font-size: 0.83rem; }
.timeline-date { font-size: 0.73rem; color: var(--text-muted); }

/* Note cards */
.note-card {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 10px;
}
.note-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.note-user { font-size: 0.78rem; font-weight: 600; color: var(--primary-light); }
.note-date { font-size: 0.73rem; color: var(--text-dim); }
.note-content { font-size: 0.85rem; color: var(--text); }

/* Document list */
.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: var(--transition);
}
.doc-item:hover { border-color: var(--primary); }
.doc-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.83rem;
}
.doc-icon { font-size: 1.2rem; }
.doc-name { font-weight: 500; color: var(--text); }
.doc-meta { font-size: 0.73rem; color: var(--text-muted); }
.doc-actions { display: flex; gap: 6px; }

/* =============================================
   LOGIN PAGE
   ============================================= */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 50%, rgba(99,102,241,.15) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(14,165,233,.1) 0%, transparent 50%),
              var(--bg);
  padding: 20px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 25px 60px rgba(0,0,0,.5);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .logo-icon {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  margin: 0 auto 12px;
  box-shadow: 0 8px 24px rgba(99,102,241,.4);
}
.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}
.login-logo p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}
.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* =============================================
   COMMISSION CARD
   ============================================= */
.commission-card {
  background: linear-gradient(135deg, rgba(16,185,129,.15), rgba(6,182,212,.1));
  border: 1px solid rgba(16,185,129,.3);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 20px;
}
.commission-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.87rem;
}
.commission-total {
  border-top: 1px solid rgba(16,185,129,.3);
  padding-top: 12px;
  margin-top: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #34d399;
}

/* =============================================
   UTILITY
   ============================================= */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary-light); }

.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mt-4 { margin-top: 28px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.mb-4 { margin-bottom: 28px; }
.gap-2 { gap: 10px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 0.9rem; }

/* =============================================
   HAMBURGER (mobile)
   ============================================= */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .hamburger { display: block; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .filters-bar .form-control { max-width: 100%; }
}
