:root {
  --bg-body: #0b1324;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --primary: #8b5cf6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #334155;
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.35);
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, sans-serif;
}

body {
  background-color: var(--bg-body);
  color: var(--text-primary);
  display: flex;
  min-height: 100dvh;
  width: 100%;
  overflow: hidden;
}

body.sidebar-open {
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.25rem;
  height: 100dvh;
  position: sticky;
  top: 0;
  align-self: flex-start;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 1000;
}

.brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.75rem;
  letter-spacing: 0.02em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  margin-bottom: 0.25rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.nav-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.nav-label {
  flex: 1;
  white-space: nowrap;
}

.nav-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  transform: translateX(4px);
}

.nav-link.active {
  background-color: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.spacer {
  flex: 1;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(6px);
  display: none;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-overlay.is-visible {
  display: block;
  opacity: 1;
}

/* Side Drawer Component */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  transition: opacity 0.3s;
  opacity: 0;
}

.side-drawer {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  max-width: 450px;
  height: 100dvh;
  background: var(--bg-card);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  z-index: 1001;
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
}

.side-drawer.open {
  right: 0;
}

.drawer-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.drawer-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.close-drawer {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background 0.2s;
  line-height: 1;
}

.close-drawer:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

/* Main Content */
.main {
  flex: 1;
  padding: 2.5rem 2.75rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  height: 100dvh;
  scrollbar-gutter: stable;
}

.content-container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.page-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.page-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.menu-toggle {
  display: none;
}

.icon-button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.title {
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.user-info {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Cards & Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  background-color: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.card-title {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  table-layout: fixed;
}

th {
  text-align: left;
  padding: 1rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: top;
}

.table-cell--truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-cell--wrap {
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

tr:hover {
  background-color: rgba(255, 255, 255, 0.015);
}

/* Forms & Buttons */
.btn {
  background-color: var(--accent);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(139, 92, 246, 0.2);
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.pagination-controls .btn {
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.35);
}

.pagination-controls .btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.input {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--bg-dark);
  border: 1px solid var(--border);
  color: white;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.input::placeholder {
  color: rgba(148, 163, 184, 0.7);
}

.input.input-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 0;
}

.search-field {
  position: relative;
  width: 100%;
  max-width: 420px;
  flex: 1;
  min-width: 220px;
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.6;
  pointer-events: none;
}

.search-input {
  padding-left: 2.6rem;
  margin-bottom: 0;
}

.filters-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.filters-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.leads-table-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.leads-table {
  min-width: 860px;
}

.lead-source-badge {
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid rgba(139, 92, 246, 0.25);
  display: inline-flex;
  align-items: center;
}

.stage-badge {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
}

.leads-cards {
  display: none;
  flex-direction: column;
  gap: 1rem;
}

.lead-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-soft);
}

.lead-card__title {
  font-weight: 600;
  font-size: 1rem;
}

.lead-card__meta {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.lead-card__row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.lead-card__label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.lead-card__value {
  font-size: 0.9rem;
  text-align: right;
  word-break: break-word;
}

.lead-card__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.pagination-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.state-block {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-secondary);
}

.state-error {
  color: #fca5a5;
}

.state-actions {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.08) 25%, rgba(148, 163, 184, 0.2) 50%, rgba(148, 163, 184, 0.08) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

.tab-bar {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--bg-card);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-item {
  padding: 0.4rem 0.9rem;
  border-radius: 0.45rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.tab-item.active {
  background: rgba(139, 92, 246, 0.18);
  color: var(--text-primary);
}

.tab-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  justify-content: center;
  align-items: center;
  z-index: 1002;
  padding: 1.5rem;
}

.modal-content {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: min(560px, 100%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  max-height: 85dvh;
  overflow-y: auto;
}

.modal-label {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.modal-row {
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Login Page specific */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 100dvh;
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  background: var(--bg-card);
  border-radius: 1rem;
}

/* Kanban */
.kanban-board {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  align-items: flex-start;
  max-width: 100%;
  /* Prevent overflow of parent, force internal scroll */
}

.kanban-col-wrapper {
  min-width: 300px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1rem;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-soft);
}

.kanban-col {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.kanban-header {
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  padding-top: 0.25rem;
}

.kanban-card {
  background: var(--bg-dark);
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  cursor: grab;
  transition: transform 0.2s, box-shadow 0.2s;
  word-break: break-word;
}

.kanban-card:hover {
  box-shadow: 0 8px 16px rgba(2, 6, 23, 0.4);
}

.kanban-card:active {
  cursor: grabbing;
  transform: rotate(1deg);
}

.kanban-card.dragging {
  opacity: 0.6;
}

.kanban-card .meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.kanban-col.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25);
}

.tag {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #334155;
  margin-right: 4px;
}


/* --- MOBILE UX OVERHAUL --- */

/* Hide Bottom Nav on Desktop by default */
.bottom-nav {
  display: none;
}

@media (max-width: 1279px) {
  .sidebar {
    width: 220px;
    padding: 1.25rem 1rem;
  }

  .brand {
    font-size: 1.2rem;
  }

  .nav-link {
    padding: 0.7rem 0.85rem;
  }

  .main {
    padding: 2rem;
  }
}

@media (max-width: 1024px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {

  /* Hide Desktop Sidebar */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, 320px);
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 20px 0 40px rgba(2, 6, 23, 0.5);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  /* Adjust Main Content for Mobile */
  .main {
    padding: 1.25rem 1rem 8.5rem;
    height: 100dvh;
  }

  .content-container {
    max-width: 100%;
    gap: 1.25rem;
  }

  .search-field {
    max-width: 100%;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  /* Login Page Mobile Optimization */
  .login-box {
    width: 90%;
    padding: 1.5rem;
    margin-top: -10vh;
    /* Visual centering */
  }

  .input,
  .btn {
    height: 52px;
    /* Large touch target */
    font-size: 16px;
    /* Stop iOS zoom */
  }

  /* Dashboard Grid */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .leads-table-container {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  .table-wrapper {
    display: none;
  }

  .leads-cards {
    display: flex;
  }

  .pagination-controls {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
  }

  /* Mobile Kanban (Horizontal Snap) */
  .kanban-board {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    max-width: 100%;
    /* Ensure mobile scrolling works */
    scroll-snap-type: x mandatory;
    gap: 1rem;
    padding-right: 1.5rem;
    /* Peek next card */
    padding-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-col-wrapper {
    min-width: 85vw;
    max-width: 85vw;
    scroll-snap-align: center;
    background: var(--bg-card);
  }

  /* Bottom Navigation Bar */
  .bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    /* Fixed height */
    background: rgba(30, 41, 59, 0.95);
    /* var(--bg-card) with opacity */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 900;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  }

  .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    gap: 6px;
    flex: 1;
    height: 100%;
    border-radius: 0;
    margin: 0;
    padding: 0;
  }

  .nav-item:hover {
    background: transparent;
  }

  .nav-item.active {
    color: var(--accent);
  }

  .nav-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .nav-item span {
    font-size: 1.5rem;
    line-height: 1;
  }
}