:root {
  --background: 220 20% 6%;
  --foreground: 0 0% 98%;
  --card: 220 18% 10%;
  --card-foreground: 0 0% 98%;
  --primary: 24 84% 53%;
  --primary-foreground: 0 0% 100%;
  --muted-foreground: 220 9% 64%;
  --border: 220 14% 18%;
  --warning: 38 90% 55%;
  --info: 217 85% 65%;
  --danger: 0 78% 58%;
  --success: 145 63% 42%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: "DM Sans", "Segoe UI", sans-serif;
}

.card,
.alert {
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
}

.alert-stack {
  display: grid;
  gap: 0.75rem;
}

.alert {
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
}

.alert-success {
  border-color: hsla(var(--success), 0.45);
}

.alert-warning {
  border-color: hsla(var(--warning), 0.45);
}

.alert-danger {
  border-color: hsla(var(--danger), 0.45);
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: radial-gradient(circle at 50% -20%, hsl(var(--card)), hsl(var(--background)) 70%);
}

.auth-wrapper {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin: 0 auto;
}

.auth-brand {
  text-align: center;
}

.auth-brand-logo {
  display: block;
  width: min(100%, 220px);
  height: auto;
  margin: 0 auto;
}

.auth-brand p {
  margin: 0.25rem 0 0;
  font-size: 1.1rem;
}

.auth-card {
  padding: 2.5rem 2rem;
  box-shadow: 0 10px 40px -10px hsla(0, 0%, 0%, 0.5), 0 0 0 1px hsl(var(--border));
  border: none;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-header h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.auth-header p,
.muted {
  color: hsl(var(--muted-foreground));
}

.form-grid {
  display: grid;
  gap: 1rem;
}

.form-grid label span {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  display: block;
}

.form-grid input {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.7rem 1rem;
  background: hsla(var(--foreground), 0.04);
  color: hsl(var(--foreground));
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-grid select {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.7rem 1rem;
  background: hsl(220 18% 8%);
  color: hsl(var(--foreground));
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-grid select option,
.lead-filter-grid select option {
  background: hsl(220 18% 8%);
  color: hsl(var(--foreground));
}

.form-grid input:focus,
.form-grid select:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsla(var(--primary), 0.2);
}

.relative {
  position: relative;
}

.pr-11 {
  padding-right: 2.75rem !important;
}

.password-toggle-button {
  position: absolute;
  inset: 0 0 0 auto;
  width: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
}

.password-toggle-button:hover {
  color: hsl(var(--foreground));
}

.icon-sm {
  width: 1.25rem;
  height: 1.25rem;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: hsl(var(--muted-foreground));
}

.checkbox-row input {
  width: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.button-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.button-success {
  background: hsl(var(--success));
  color: white;
}

.button-success:hover {
  background: hsl(145 63% 48%);
}

.button-secondary {
  background: hsla(var(--foreground), 0.06);
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
}

.button-secondary:hover {
  background: hsla(var(--foreground), 0.1);
}

.button-compact {
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 700;
}

.button-compact svg {
  width: 1rem;
  height: 1rem;
}

.button-md {
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.2;
}

.button-md svg {
  width: 1.15rem;
  height: 1.15rem;
}

.button-large {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.5rem;
  border-radius: 8px;
  width: 100%;
}

.auth-link {
  color: hsl(var(--primary));
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.admin-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.admin-sidebar {
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
}

.sidebar-brand {
  color: hsl(var(--foreground));
  text-decoration: none;
}

.sidebar-brand-text {
  font-weight: 800;
  letter-spacing: 0.02em;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1.25rem 0.75rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: hsl(var(--muted-foreground));
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: hsla(var(--primary), 0.1);
  color: hsl(var(--primary));
}

.nav-item.active {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.nav-item svg,
.sidebar-footer svg {
  width: 1.25rem;
  height: 1.25rem;
}

.sidebar-footer {
  padding: 1.25rem 1rem;
  border-top: 1px solid hsl(var(--border));
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: linear-gradient(135deg, hsl(var(--primary)), #f9a826);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: hsl(var(--foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.7rem;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.logout-icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
}

.logout-icon-button:hover {
  background: hsla(var(--danger), 0.1);
  color: hsl(var(--danger));
}

.admin-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.content-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  background: hsla(var(--background), 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid hsl(var(--border));
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.header-right,
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.breadcrumb {
  padding: 0.4rem 0.75rem;
  background: hsla(var(--foreground), 0.04);
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  font-size: 0.8rem;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  color: hsl(var(--muted-foreground));
  text-decoration: none;
}

.breadcrumb-item.active {
  color: hsl(var(--foreground));
  font-weight: 600;
}

.breadcrumb-item svg {
  width: 1rem;
  height: 1rem;
}

.breadcrumb-separator {
  color: hsl(var(--muted-foreground));
  opacity: 0.4;
}

.admin-main {
  padding: 2rem;
}

.page-alerts {
  margin-bottom: 1.25rem;
}

.mobile-nav-toggle,
.admin-sidebar-overlay {
  display: none;
}

.mobile-nav-toggle {
  align-items: center;
  padding: 0.45rem 0.7rem;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  background: hsla(var(--foreground), 0.04);
  color: hsl(var(--foreground));
}

.mobile-nav-toggle-icon {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
}

.mobile-nav-toggle-icon span {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.operations-page-header {
  margin-bottom: 1.5rem;
}

.page-heading-row,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.operations-page-header h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.7rem, 3vw, 2.15rem);
  line-height: 1.05;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}

.stat-card {
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.operations-flow-card {
  background: linear-gradient(180deg, hsl(var(--card)), hsl(220 18% 9%));
}

.pill-sm {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.pill-sm.warning { background: hsla(var(--warning), 0.14); color: hsl(var(--warning)); }
.pill-sm.info { background: hsla(var(--info), 0.14); color: hsl(var(--info)); }
.pill-sm.neutral { background: hsla(var(--foreground), 0.08); color: hsl(var(--muted-foreground)); }
.pill-sm.success { background: hsla(var(--success), 0.14); color: hsl(var(--success)); }
.pill-sm.danger { background: hsla(var(--danger), 0.14); color: hsl(var(--danger)); }

.operations-flow-description {
  margin: 0;
  line-height: 1.45;
}

.table-card,
.form-card {
  padding: 1.25rem;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-toolbar {
  margin-bottom: 1.5rem;
}

.client-directory-alert {
  margin-bottom: 1rem;
}

.card-search-form {
  position: relative;
  width: min(100%, 24rem);
}

.card-search-icon {
  position: absolute;
  inset-block: 0;
  left: 1rem;
  display: flex;
  align-items: center;
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}

.card-search-icon svg {
  width: 1.15rem;
  height: 1.15rem;
}

.card-search-input {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.62rem 0.85rem 0.62rem 3rem;
  background: hsl(220 18% 9%);
  color: hsl(var(--foreground));
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card-search-input:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsla(var(--primary), 0.18);
}

.contents {
  display: contents;
}

.user-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.user-search {
  display: grid;
  gap: 0.35rem;
  width: min(100%, 420px);
}

.user-search span {
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  font-weight: 700;
}

.user-search input {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.62rem 0.85rem;
  background: hsla(var(--foreground), 0.04);
  color: hsl(var(--foreground));
}

.user-search input:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsla(var(--primary), 0.18);
}

.lead-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
  align-items: end;
}

.lead-filter-grid label {
  display: grid;
  gap: 0.35rem;
}

.lead-filter-field {
  align-self: end;
}

.lead-filter-grid span,
.form-grid label span {
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  font-weight: 700;
}

.lead-filter-grid input,
.lead-filter-grid select {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.62rem 0.85rem;
  background: hsla(var(--foreground), 0.04);
  color: hsl(var(--foreground));
}

.crm-select {
  position: relative;
  width: 100%;
}

.crm-select-label {
  display: block;
  color: hsl(var(--muted-foreground));
  font-size: 0.82rem;
  font-weight: 700;
}

.crm-select-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  padding: 0.62rem 0.75rem;
  background: hsl(220 16% 12%);
  color: hsl(var(--foreground));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.crm-select-button:hover {
  border-color: hsl(var(--muted-foreground));
}

.crm-select-button:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsla(var(--primary), 0.2);
}

.crm-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-select-chevron {
  width: 1rem;
  height: 1rem;
  color: hsl(var(--muted-foreground));
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.crm-select-chevron.is-open {
  transform: rotate(180deg);
}

.crm-select-menu {
  position: absolute;
  z-index: 50;
  width: 100%;
  margin-top: 0.25rem;
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
  background: hsl(var(--card));
  box-shadow: 0 20px 45px hsla(0, 0%, 0%, 0.42);
  overflow: hidden;
}

.crm-select-options {
  max-height: 15rem;
  overflow: auto;
  padding: 0.25rem 0;
  scrollbar-width: thin;
  scrollbar-color: hsla(var(--muted-foreground), 0.55) hsl(var(--card));
}

.crm-select-options::-webkit-scrollbar {
  width: 10px;
}

.crm-select-options::-webkit-scrollbar-track {
  background: hsl(var(--card));
}

.crm-select-options::-webkit-scrollbar-thumb {
  background: linear-gradient(
    180deg,
    hsla(var(--muted-foreground), 0.75),
    hsla(var(--muted-foreground), 0.5)
  );
  border: 2px solid hsl(var(--card));
  border-radius: 999px;
}

.crm-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.crm-select-option.is-focused {
  background: hsla(var(--foreground), 0.05);
  color: hsl(var(--foreground));
}

.crm-select-option.is-selected {
  background: hsla(var(--primary), 0.1);
  color: hsl(var(--primary));
  font-weight: 700;
}

.crm-select-check {
  width: 1rem;
  height: 1rem;
  color: hsl(var(--primary));
  flex-shrink: 0;
}

.filter-actions {
  display: flex;
  align-items: center;
  align-self: end;
  gap: 0.5rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.table th,
.table td {
  padding: 0.9rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: hsl(var(--muted-foreground));
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.table-sort-link {
  color: inherit;
  text-decoration: none;
}

.table-sort-link:hover {
  color: hsl(var(--foreground));
}

.table tr:last-child td {
  border-bottom: 0;
}

.strong-cell {
  color: hsl(var(--foreground));
  font-weight: 700;
}

.table-title-link {
  color: hsl(var(--foreground));
  font-weight: 700;
  text-decoration: none;
}

.table-title-link:hover {
  color: hsl(var(--primary));
}

.table-subtext {
  margin-top: 0.2rem;
  font-size: 0.82rem;
}

.text-right {
  text-align: right !important;
}

.empty-table-cell {
  color: hsl(var(--muted-foreground));
  padding: 2rem !important;
  text-align: center !important;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid hsl(var(--border));
  border-radius: 7px;
  color: hsl(var(--muted-foreground));
  text-decoration: none;
}

.icon-link:hover {
  border-color: hsla(var(--primary), 0.45);
  color: hsl(var(--primary));
}

.icon-link svg {
  width: 1rem;
  height: 1rem;
}

.pagination-row {
  margin-top: 1rem;
}

.form-card {
  display: grid;
  gap: 1rem;
  max-width: 920px;
}

.form-section {
  display: grid;
  gap: 1rem;
}

.form-section h3 {
  margin: 0;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 1rem;
}

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

.switch-row {
  display: flex !important;
  align-items: center;
  align-self: end;
  gap: 0.65rem;
  min-height: 2.8rem;
}

.switch-row input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
}

.form-error {
  display: block;
  margin-top: 0.4rem;
  color: hsl(var(--danger));
  font-size: 0.8rem;
}

.form-note {
  margin: -0.25rem 0 1rem;
}

.detail-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.detail-badges {
  display: flex;
  align-items: start;
  gap: 0.5rem;
}

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

.detail-card {
  padding: 1.25rem;
}

.detail-card h3 {
  margin: 0 0 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
}

.detail-list {
  display: grid;
  gap: 0.85rem;
  margin: 0;
}

.detail-list div {
  display: grid;
  gap: 0.25rem;
}

.detail-list dt {
  color: hsl(var(--muted-foreground));
  font-size: 0.8rem;
  font-weight: 700;
}

.detail-list dd {
  margin: 0;
}

.mobile-heading-action {
  display: none;
}

@media (max-width: 1023px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 280px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
  }

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

  .admin-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    border: 0;
    z-index: 20;
  }

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

  .mobile-nav-toggle {
    display: inline-flex;
  }

  .content-header {
    padding: 0 1rem;
  }

  .admin-main {
    padding: 1rem;
  }

  .breadcrumb {
    display: none;
  }

  .header-right {
    gap: 0;
  }

  .mobile-heading-action {
    display: inline-flex;
  }

  .user-toolbar,
  .card-toolbar,
  .lead-filter-grid,
  .detail-heading,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .lead-filter-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .user-search {
    width: 100%;
  }

  .card-search-form {
    width: 100%;
  }

  .two-columns {
    grid-template-columns: 1fr;
  }
}
