/* ═══════════════════════════════════════════════════════════════════════
   BrandsPro CRM — Main Stylesheet
   Mobile-first, App-like design
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; height: auto; }
* { -webkit-tap-highlight-color: transparent; }

/* ── CSS Variables ─────────────────────────────────────────────────────── */
:root {
  --accent:        #6366f1;
  --accent-light:  #6366f122;
  --accent-mid:    #6366f155;
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --bottom-nav-h:  64px;
  --radius:        12px;
  --shadow:        0 1px 8px rgba(0,0,0,.08);
  --shadow-lg:     0 8px 30px rgba(0,0,0,.12);
  --border:        #e2e8f0;
  --text-muted:    #64748b;
  --dark:          #0f172a;
  --card-bg:       #ffffff;
}

/* ══════════════════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════════════════ */

.crm-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.crm-sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: linear-gradient(160deg, #0f172a 0%, #1e1b4b 60%, #1e1b4b 100%);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  z-index: 200;
  position: relative;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-logo {
  width: 36px; height: 36px; object-fit: contain; border-radius: 8px; flex-shrink: 0;
}
.sidebar-icon-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.sidebar-studio-name {
  font-size: 13px; font-weight: 800; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-crm-label {
  font-size: 10px; color: rgba(255,255,255,.4); letter-spacing: .5px;
}
.sidebar-close-btn {
  display: none; margin-left: auto; background: none; border: none;
  color: rgba(255,255,255,.5); font-size: 18px; cursor: pointer;
  padding: 4px; line-height: 1;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  color: rgba(255,255,255,.6);
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  margin-bottom: 2px;
  cursor: pointer;
}
.sidebar-nav-item:hover {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.9);
}
.sidebar-nav-item.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-mid);
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { white-space: nowrap; }

.sidebar-footer {
  padding: 14px 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sidebar-user { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.sidebar-user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; flex-shrink: 0;
}
.sidebar-user-name { font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,.4); }
.sidebar-logout {
  color: rgba(255,255,255,.4); font-size: 18px; line-height: 1;
  transition: .15s; flex-shrink: 0;
}
.sidebar-logout:hover { color: #ef4444; }

/* ── Overlay ─────────────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
  z-index: 190;
}

/* ── Main content area ───────────────────────────────────────────────────── */
.crm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.crm-topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.topbar-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px; height: 36px;
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; padding: 8px; flex-shrink: 0;
}
.topbar-menu-btn span {
  display: block; height: 2px; background: #475569; border-radius: 2px; transition: .2s;
}
.topbar-title {
  font-size: 16px; font-weight: 800; color: #1e293b; flex: 1;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-date { font-size: 12px; color: var(--text-muted); }
.topbar-logout-mobile { display: none; font-size: 18px; color: var(--text-muted); cursor: pointer; }

/* ── Content ─────────────────────────────────────────────────────────────── */
.crm-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 20px;
}

/* ── Mobile bottom nav ───────────────────────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 180;
  box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 4px;
  transition: .15s;
  min-width: 0;
}
.bottom-nav-item.active {
  color: var(--accent);
}
.bottom-nav-item.active .bottom-nav-icon {
  background: var(--accent-light);
  border-radius: 8px;
  padding: 4px 12px;
}
.bottom-nav-icon { font-size: 20px; line-height: 1; }
.bottom-nav-label { font-size: 10px; font-weight: 600; white-space: nowrap; }

/* ══════════════════════════════════════════════════════════════════════════
   FLASH MESSAGES
   ══════════════════════════════════════════════════════════════════════════ */
.crm-flash {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; margin: 12px 20px 0;
  border-radius: 10px; font-size: 13px; font-weight: 600;
}
.crm-flash-success { background: #d1fae5; color: #065f46; border-left: 4px solid #10b981; }
.crm-flash-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid #ef4444; }
.crm-flash-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid #3b82f6; }
.flash-close { margin-left: auto; background: none; border: none; cursor: pointer; font-size: 16px; opacity: .5; line-height: 1; }

/* ══════════════════════════════════════════════════════════════════════════
   REUSABLE COMPONENTS
   ══════════════════════════════════════════════════════════════════════════ */

/* Cards */
.crm-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title { font-size: 15px; font-weight: 800; color: #1e293b; }
.card-body { padding: 20px; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 18px; font-weight: 800; color: #1e293b; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: attr(data-icon);
  position: absolute;
  right: 14px; top: 14px;
  font-size: 28px; opacity: .12;
}
.stat-value { font-size: 26px; font-weight: 900; color: #1e293b; line-height: 1.1; }
.stat-label { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.stat-sub   { font-size: 11px; color: #10b981; font-weight: 600; margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 9px;
  font-size: 13px; font-weight: 700;
  cursor: pointer; transition: .15s;
  border: none; text-decoration: none; white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #fff; box-shadow: 0 2px 8px var(--accent-mid); }
.btn-primary:hover   { opacity: .88; }
.btn-secondary { background: #fff; color: #374151; border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger    { background: #fee2e2; color: #ef4444; border: 1.5px solid #fecaca; }
.btn-danger:hover { background: #fca5a5; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 7px; }
.btn-icon { padding: 7px; border-radius: 7px; }

/* Badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; color: #fff;
  white-space: nowrap;
}

/* Tables */
.crm-table-wrap { overflow-x: auto; }
.crm-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.crm-table thead th {
  background: var(--accent); color: #fff;
  padding: 11px 14px;
  font-size: 11px; font-weight: 700;
  text-align: left; white-space: nowrap;
  letter-spacing: .3px;
}
.crm-table tbody tr { border-bottom: 1px solid #f1f5f9; transition: .12s; }
.crm-table tbody tr:hover { background: #faf9ff; }
.crm-table tbody td { padding: 11px 14px; vertical-align: middle; }

/* Forms */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label { font-size: 12px; font-weight: 700; color: #475569; }
.form-field input, .form-field select, .form-field textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: #1e293b;
  background: #fff;
  transition: .15s;
  width: 100%;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  outline: none;
}
.form-field textarea { min-height: 80px; resize: vertical; }
.form-actions { display: flex; gap: 10px; padding-top: 16px; flex-wrap: wrap; }

/* Search bar */
.crm-search-bar {
  display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap;
}
.crm-search-bar input {
  flex: 1; min-width: 200px;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px; font-size: 13px;
  background: #fff;
}
.crm-search-bar input:focus { border-color: var(--accent); outline: none; }

/* Status tabs */
.crm-tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px;
}
.crm-tab {
  padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 700;
  background: #f1f5f9; color: var(--text-muted);
  border: 1px solid var(--border); text-decoration: none; transition: .15s;
}
.crm-tab.active, .crm-tab:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Pagination */
.crm-pagination {
  display: flex; gap: 6px; justify-content: center;
  padding: 16px 0; flex-wrap: wrap;
}
.crm-pagination a {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  background: #fff; color: #475569;
  border: 1.5px solid var(--border); transition: .15s;
}
.crm-pagination a.active, .crm-pagination a:hover {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Empty state */
.crm-empty {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.crm-empty-icon { font-size: 52px; margin-bottom: 12px; opacity: .4; }
.crm-empty p { font-size: 14px; }

/* Action bar row */
.crm-action-row {
  display: flex;
  gap: 8px;
}

/* Mobile card list (replaces tables on mobile) */
.crm-mobile-list { display: none; }
.crm-mobile-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-left: 4px solid var(--accent);
}
.crm-mobile-card-body { flex: 1; min-width: 0; }
.crm-mobile-card-title { font-size: 14px; font-weight: 700; color: #1e293b; margin-bottom: 4px; }
.crm-mobile-card-meta  { font-size: 12px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.crm-mobile-card-actions { display: flex; gap: 6px; margin-top: 10px; }

/* Checklist */
.crm-checklist { display: flex; flex-direction: column; gap: 8px; }
.crm-checklist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #f9fafb;
  border-radius: 9px; border: 1.5px solid var(--border);
  cursor: pointer; transition: .15s;
}
.crm-checklist-item.done { background: #ecfdf5; border-color: #6ee7b7; }
.crm-check-box {
  width: 20px; height: 20px; border-radius: 6px;
  border: 2px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: .15s; font-size: 12px;
}
.crm-checklist-item.done .crm-check-box {
  background: #10b981; border-color: #10b981; color: #fff;
}
.crm-check-label { font-size: 13px; font-weight: 600; flex: 1; }
.crm-check-date  { font-size: 11px; color: var(--text-muted); }

/* Dashboard specific */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
}
.dash-pipeline {
  display: flex; flex-direction: column; gap: 8px;
}
.pipeline-stage {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #fff;
  border-radius: 9px; border-left: 4px solid;
  box-shadow: var(--shadow);
}
.pipeline-count { font-size: 20px; font-weight: 900; width: 32px; }
.pipeline-label { font-size: 13px; font-weight: 600; flex: 1; }
.pipeline-bar-wrap { width: 80px; height: 6px; background: #f1f5f9; border-radius: 3px; overflow: hidden; }
.pipeline-bar { height: 100%; border-radius: 3px; transition: width .5s; }

/* Login page */
.crm-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a, #1e1b4b, #312e81);
  padding: 20px;
}
.login-box {
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo-icon {
  font-size: 40px;
  margin-bottom: 8px;
}
.login-studio-name {
  font-size: 18px;
  font-weight: 800;
  color: #1e293b;
}
.login-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-field label { font-size: 12px; font-weight: 700; color: #475569; }
.login-field input {
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  transition: .2s;
}
.login-field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-light); }
.login-btn {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 4px;
  transition: .15s;
  box-shadow: 0 4px 14px var(--accent-mid);
}
.login-btn:hover { opacity: .9; }
.login-error { background: #fee2e2; color: #991b1b; padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE ≤ 768px
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Hide desktop sidebar, show topbar menu button */
  .crm-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .crm-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close-btn { display: flex; }

  .sidebar-overlay.open { display: block; }

  .topbar-menu-btn { display: flex; }
  .topbar-date { display: none; }
  .topbar-logout-mobile { display: flex; }

  /* Show mobile bottom nav */
  .mobile-bottom-nav {
    display: flex;
    align-items: stretch;
  }

  /* Add bottom padding so content isn't hidden */
  .crm-content {
    padding: 14px;
    padding-bottom: calc(var(--bottom-nav-h) + 16px);
  }

  /* Tables → cards on mobile */
  .crm-table-wrap { display: none; }
  .crm-mobile-list { display: block; }

  /* Dashboard grid → stack */
  .dash-grid { grid-template-columns: 1fr; }

  /* Stat grid 2-col on mobile */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 22px; }

  /* Form grids → 1 col */
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }

  /* Page header stack */
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-title  { font-size: 16px; }

  /* Card header stack */
  .card-header { flex-direction: column; align-items: flex-start; }

  /* Search bar full width */
  .crm-search-bar input { min-width: 100%; }

  .login-box { padding: 32px 22px; }
}

/* ── Tablet: 769–1024px ──────────────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .crm-sidebar { width: 200px; }
  .sidebar-studio-name { font-size: 12px; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .dash-grid { grid-template-columns: 1fr 280px; }
}

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .crm-sidebar, .crm-topbar, .mobile-bottom-nav, .crm-tabs, .crm-search-bar, .btn, .page-header { display: none !important; }
  .crm-main { overflow: visible; }
  .crm-content { padding: 0; }
}
