/* ============================================================
   Solar CRM — Main Stylesheet
   Theme: Industrial Solar — deep navy + amber + white
   Font: DM Sans (body) + Space Grotesk (headings)
   ============================================================ */

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #21262d;
  --border:      #30363d;
  --solar:       #f7b731;
  --solar-dark:  #d4960e;
  --solar-glow:  rgba(247,183,49,0.15);
  --text:        #e6edf3;
  --text2:       #8b949e;
  --text3:       #6e7681;
  --green:       #3fb950;
  --red:         #f85149;
  --blue:        #58a6ff;
  --purple:      #bc8cff;
  --sidebar-w:   250px;
  --topbar-h:    60px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --transition:  0.2s ease;
}

/* ── LIGHT THEME ────────────────────────────────────────── */
body.light-mode {
  --bg:          #f0f2f5;
  --bg2:         #ffffff;
  --bg3:         #f6f8fa;
  --border:      #d0d7de;
  --solar:       #d4960e;
  --solar-dark:  #b07a08;
  --solar-glow:  rgba(212,150,14,0.12);
  --text:        #1a1f2e;
  --text2:       #4b5563;
  --text3:       #6b7280;
  --green:       #1a7f37;
  --red:         #cf222e;
  --blue:        #0969da;
  --purple:      #8250df;
  --shadow:      0 4px 24px rgba(0,0,0,0.10);
}
body.light-mode ::-webkit-scrollbar-track { background: var(--bg3); }
body.light-mode ::-webkit-scrollbar-thumb { background: var(--border); }
body.light-mode .crm-table th { background: #f0f2f5; }
body.light-mode .crm-table tr:hover td { background: #f6f8fa; }
body.light-mode .detail-item:nth-child(even) { background: rgba(0,0,0,.02); }
body.light-mode .form-group input,
body.light-mode .form-group select,
body.light-mode .form-group textarea { background: #fff; color: var(--text); }
body.light-mode .filter-bar input,
body.light-mode .filter-bar select { background: #fff; color: var(--text); }
body.light-mode .badge-green   { background: rgba(26,127,55,.12);  color: var(--green); }
body.light-mode .badge-yellow  { background: rgba(212,150,14,.12); color: var(--solar); }
body.light-mode .badge-red     { background: rgba(207,34,46,.12);  color: var(--red); }
body.light-mode .badge-blue    { background: rgba(9,105,218,.12);  color: var(--blue); }
body.light-mode .badge-purple  { background: rgba(130,80,223,.12); color: var(--purple); }
body.light-mode .badge-gray    { background: #eaeef2; color: var(--text2); }
body.light-mode .stat-card::before { background: var(--solar); }
body.light-mode .stat-icon { background: rgba(212,150,14,.1); color: var(--solar); }
body.light-mode .nav-link.active { background: rgba(212,150,14,.1); }
body.light-mode .sidebar { border-right-color: var(--border); }
body.light-mode .topbar  { background: #fff; border-bottom-color: var(--border); }
body.light-mode .user-pill { background: var(--bg3); }

/* ── THEME TOGGLE BUTTON ────────────────────────────────── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px 5px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  transition: all var(--transition);
  white-space: nowrap;
}
.theme-toggle:hover { border-color: var(--solar); color: var(--solar); }
.theme-toggle .toggle-icon { font-size: 14px; }

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; }

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── SIDEBAR ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.sidebar-logo {
  height: 38px;
  width: auto;
  object-fit: contain;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 12px 20px 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.nav-link i { width: 16px; text-align: center; font-size: 14px; }
.nav-link:hover { color: var(--text); background: var(--bg3); }
.nav-link.active {
  color: var(--solar);
  background: var(--solar-glow);
  border-left-color: var(--solar);
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--solar);
  color: #000;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; display: block; line-height: 1.2; }
.user-role { font-size: 10px; color: var(--text3); display: block; text-transform: capitalize; }
.user-info { flex: 1; }
.logout-btn { color: var(--text3); font-size: 15px; transition: color var(--transition); }
.logout-btn:hover { color: var(--red); }

/* ── MAIN WRAPPER ──────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── TOPBAR ────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.sidebar-toggle {
  background: none; border: none; color: var(--text2);
  font-size: 18px; cursor: pointer; display: none;
  padding: 4px 6px; border-radius: 4px;
}
.sidebar-toggle:hover { color: var(--text); background: var(--bg3); }
.topbar-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px; font-weight: 600;
  flex: 1;
}
.topbar-date { font-size: 12px; color: var(--text3); }

/* ── PAGE CONTENT ──────────────────────────────────────── */
.page-content { padding: 28px 28px; flex: 1; }

/* ── FLASH ─────────────────────────────────────────────── */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px;
  margin: 0 28px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  position: relative;
}
.flash-success { background: rgba(63,185,80,.15); border: 1px solid rgba(63,185,80,.3); color: var(--green); }
.flash-error   { background: rgba(248,81,73,.15);  border: 1px solid rgba(248,81,73,.3);  color: var(--red); }
.flash-close {
  background: none; border: none; color: inherit;
  font-size: 18px; cursor: pointer; margin-left: auto; line-height: 1;
}

/* ── CARDS ─────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.card-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 16px;
}

/* ── STAT CARDS ────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--solar); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--solar);
}
.stat-icon {
  width: 40px; height: 40px;
  background: var(--solar-glow);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--solar);
  font-size: 17px;
  margin-bottom: 12px;
}
.stat-label { font-size: 12px; color: var(--text3); margin-bottom: 4px; }
.stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-sub { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ── TABLE ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.crm-table th {
  background: var(--bg3);
  color: var(--text2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.crm-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.crm-table tr:last-child td { border-bottom: none; }
.crm-table tr:hover td { background: var(--bg3); }
.crm-table .actions { display: flex; gap: 6px; }

/* ── BADGES / STATUS ───────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green   { background: rgba(63,185,80,.15);  color: var(--green); }
.badge-yellow  { background: rgba(247,183,49,.15); color: var(--solar); }
.badge-red     { background: rgba(248,81,73,.15);  color: var(--red); }
.badge-blue    { background: rgba(88,166,255,.15); color: var(--blue); }
.badge-purple  { background: rgba(188,140,255,.15);color: var(--purple); }
.badge-gray    { background: var(--bg3); color: var(--text2); }

/* ── BUTTONS ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
}
.btn-primary   { background: var(--solar); color: #000; }
.btn-primary:hover { background: var(--solar-dark); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--solar); color: var(--solar); }
.btn-danger    { background: rgba(248,81,73,.15); color: var(--red); border: 1px solid rgba(248,81,73,.3); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

/* ── FORMS ─────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  transition: border-color var(--transition);
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--solar);
  box-shadow: 0 0 0 3px var(--solar-glow);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group select option { background: var(--bg3); }
.form-section {
  border-left: 3px solid var(--solar);
  padding-left: 14px;
  margin: 24px 0 12px;
}
.form-section h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--solar);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.form-section p { font-size: 12px; color: var(--text3); }

/* ── PAGE HEADER ───────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  font-weight: 700;
}
.page-header p { font-size: 13px; color: var(--text3); margin-top: 2px; }

/* ── SEARCH / FILTER BAR ───────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
}
.filter-bar input,
.filter-bar select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.filter-bar input:focus,
.filter-bar select:focus { border-color: var(--solar); }
.filter-bar input { min-width: 220px; }

/* ── PERMISSION GRID (users page) ──────────────────────── */
.perm-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.perm-check { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.perm-check input[type=checkbox] { accent-color: var(--solar); width: 14px; height: 14px; }

/* ── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px; font-weight: 700;
}
.modal-close {
  background: none; border: none; color: var(--text3);
  font-size: 20px; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 24px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── PAGINATION ────────────────────────────────────────── */
.pagination {
  display: flex; gap: 6px; align-items: center;
  justify-content: flex-end; margin-top: 16px;
}
.pagination a, .pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  transition: all var(--transition);
}
.pagination a:hover { border-color: var(--solar); color: var(--solar); }
.pagination .current { background: var(--solar); color: #000; border-color: var(--solar); }

/* ── CHARTS ────────────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 8px;
}
.chart-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.chart-box h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── LOGIN PAGE ────────────────────────────────────────── */
body.login-body {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  min-height: 100vh;
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .icon {
  width: 54px; height: 54px;
  background: var(--solar);
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: #000;
  font-size: 24px;
  margin-bottom: 10px;
}
.login-logo h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 20px; font-weight: 700;
}
.login-logo p { font-size: 12px; color: var(--text3); }
.login-error {
  background: rgba(248,81,73,.15);
  border: 1px solid rgba(248,81,73,.3);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

/* ── DETAIL VIEW ───────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0;
}
.detail-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-item:nth-child(even) { background: rgba(255,255,255,.02); }
.detail-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.detail-value { font-size: 14px; font-weight: 500; }

/* ── RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr; }
}