:root {
  --admin-bg: #f8f9fa;
  --admin-sidebar-bg: #1a1c23;
  --admin-sidebar-text: #a0aec0;
  --admin-sidebar-active: #fff;
  --admin-sidebar-active-bg: #7e3af2;
  --admin-header-bg: #ffffff;
  --admin-card-bg: #ffffff;
  --admin-text-primary: #24262d;
  --admin-text-secondary: #707275;
  --admin-accent: #7e3af2;
  --admin-success: #0e9f6e;
  --admin-warning: #ff5a1f;
  --admin-danger: #e02424;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--admin-bg);
  color: var(--admin-text-primary);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

.admin-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.admin-sidebar {
  width: 250px;
  background-color: var(--admin-sidebar-bg);
  color: var(--admin-sidebar-text);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.sidebar-toggle {
  border: 0;
  background: transparent;
  color: #fff;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  margin-right: 0.5rem;
  cursor: pointer;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-toggle-header {
  color: var(--admin-text-primary);
  margin-right: 0.75rem;
  background: #f1f3f7;
}

.sidebar-toggle-header:hover {
  background: #e6eaf0;
}

.sidebar-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-item {
  display: block;
  padding: 0.75rem 1.5rem;
  color: var(--admin-sidebar-text);
  text-decoration: none;
  transition: color 0.2s, background-color 0.2s;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-item:hover,
.nav-item.active {
  color: var(--admin-sidebar-active);
  background-color: rgba(126, 58, 242, 0.1);
  /* faded accent */
  border-left: 3px solid var(--admin-accent);
}

.nav-item svg {
  width: 20px;
  height: 20px;
}

body.sidebar-collapsed .admin-sidebar {
  width: 72px;
}

body.sidebar-collapsed .sidebar-header {
  justify-content: center;
  gap: 0.25rem;
}

body.sidebar-collapsed .sidebar-header i {
  margin-right: 0;
}

body.sidebar-collapsed .sidebar-header .sidebar-toggle {
  margin-right: 0;
}

body.sidebar-collapsed .sidebar-title {
  display: none;
}

body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 0.75rem;
}

body.sidebar-collapsed .nav-item span {
  display: none;
}

body.sidebar-collapsed .nav-item i {
  font-size: 1.1rem;
}

/* Main Content */
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.admin-header {
  height: 64px;
  background-color: var(--admin-header-bg);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 10;
}

.header-search {
  position: relative;
  width: 100%;
  max-width: 500px;
}

.header-search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.5rem;
  border-radius: 0.375rem;
  border: 1px solid #e2e8f0;
  background-color: #f7fafc;
  color: var(--admin-text-primary);
  font-size: 0.875rem;
}

.header-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.profile-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background-color: #ddd;
}

/* Content Area */
.admin-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

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

.stat-card {
  background-color: var(--admin-card-bg);
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: rgba(126, 58, 242, 0.1);
  color: var(--admin-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 1rem;
}

.stat-icon.green {
  background-color: rgba(14, 159, 110, 0.1);
  color: var(--admin-success);
}

.stat-icon.orange {
  background-color: rgba(255, 90, 31, 0.1);
  color: var(--admin-warning);
}

.stat-info h4 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--admin-text-secondary);
}

.stat-info p {
  margin: 0.25rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--admin-text-primary);
}

/* Charts Section */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background-color: var(--admin-card-bg);
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  min-height: 300px;
}

.chart-header {
  margin-bottom: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--admin-text-primary);
}

/* Tables */
.table-card {
  background-color: var(--admin-card-bg);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  padding: 0.75rem 1.5rem;
  /* Reduced vertical padding */
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.admin-table th {
  background-color: #f7fafc;
  font-weight: 600;
  color: var(--admin-text-secondary);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.admin-table td {
  font-size: 0.875rem;
  color: var(--admin-text-primary);
}

.status-badge {
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-badge.success {
  background-color: rgba(14, 159, 110, 0.1);
  color: var(--admin-success);
}

.status-badge.warning {
  background-color: rgba(255, 90, 31, 0.1);
  color: var(--admin-warning);
}

.form-floating>.form-control-plaintext::placeholder,
.form-floating>.form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating>.form-control-plaintext:focus::placeholder,
.form-floating>.form-control:focus::placeholder {
  text-align: start;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background-color: var(--admin-bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background-color: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  padding: 2rem;
}

.login-header {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
  color: var(--admin-text-primary);
}

.captcha-box {
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.25rem 0.5rem;
}

.captcha-box img {
  display: block;
  height: 40px;
}

/* AI response formatting */
.ai-response-container {
  color: #2d3748;
  font-size: 1.05rem;
  line-height: 1.65;
}

.ai-response-container h2 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--admin-text-primary);
}

.ai-response-container h3 {
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.ai-response-container ul {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
}

.ai-response-container li {
  margin-bottom: 0.4rem;
}

.ai-response-container hr {
  border: 0;
  border-top: 1px solid #e2e8f0;
  margin: 1rem 0;
}

.ai-response-container strong {
  color: var(--admin-accent);
}

.recent-analysis-link:hover {
  border: 1px solid var(--admin-accent);
  box-shadow: 0 4px 12px rgba(126, 58, 242, 0.15);
  background-color: #cddc39;
}

.admin-table-responsive {
  overflow-x: auto;
}

.table-name {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.table-avatar {
  width: 32px;
  height: 32px;
  background: #e2e8f0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--admin-text-secondary);
}

.table-actions {
  white-space: nowrap;
}

.status-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.status-card-link .card {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.status-card-link:hover .card {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
}

.dashboard-chart-card {
  height: 100%;
}

.dashboard-chart-body {
  height: 100%;
  min-height: 220px;
}

.dashboard-chart-canvas {
  width: 100% !important;
  height: 100% !important;
}

.status-filter-clear {
  background-color: var(--admin-accent);
  color: #fff;
  border: 1px solid var(--admin-accent);
}

.status-filter-clear:hover,
.status-filter-clear:focus {
  background-color: #6a2fd6;
  color: #fff;
  border-color: #6a2fd6;
}

.btn-pdf-download {
  background-color: #673AB7;
  color: #fff;
  border: solid 1px #673AB7;
}

.btn-pdf-download:hover,
.btn-pdf-download:focus {
  background-color: #5e35b1;
  color: #fff;
  border-color: #5e35b1;
}

/* Responsive layout */
@media (max-width: 1024px) {
  .admin-sidebar {
    width: 220px;
  }

  .admin-header {
    padding: 0 1.25rem;
  }

  .admin-content {
    padding: 1.5rem;
  }

  .charts-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  }

  .customer-page-row > [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .customer-form-col {
    order: 2;
    margin-top: 1rem;
  }

  .customer-list-col {
    order: 1;
  }

  .ai-analysis-row > [class*="col-md-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .ai-analysis-card {
    padding: 1.5rem;
  }

  .ai-analysis-upload {
    padding: 2rem;
  }

  .recent-analyses-card {
    margin-top: 1rem;
  }

  .admin-table {
    min-width: 720px;
  }
}

@media (max-width: 768px) {
  .admin-wrapper {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .admin-sidebar {
    width: 100%;
  }

  body.sidebar-collapsed .admin-sidebar {
    width: 100%;
  }

  .sidebar-toggle-header {
    display: inline-flex;
  }

  .sidebar-header {
    height: 56px;
    font-size: 1.25rem;
  }

  .sidebar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }

  .nav-item {
    flex: 0 0 auto;
    padding: 0.5rem 0.75rem;
    border-left: 0;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }

  .nav-item:hover,
  .nav-item.active {
    border-left: 0;
    border-bottom: 2px solid var(--admin-accent);
  }

  .admin-header {
    height: auto;
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .header-profile {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .header-profile form {
    margin-left: auto;
  }

  .header-search {
    max-width: none;
    flex: 1 1 100%;
  }

  .admin-content {
    padding: 1rem;
  }

  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
  }

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

  .chart-card {
    min-height: 240px;
  }

  .table-card {
    overflow-x: auto;
  }

  .admin-table {
    min-width: 600px;
  }
}

@media (max-width: 480px) {
  .admin-header {
    padding: 0.75rem;
  }

  .header-profile {
    gap: 0.5rem;
  }

  .profile-img {
    width: 28px;
    height: 28px;
  }

  .admin-content {
    padding: 0.75rem;
  }

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

  .admin-table {
    min-width: 520px;
  }

  .login-body {
    padding: 1rem;
  }

  .login-card {
    margin: 0 0.5rem;
    padding: 1.25rem;
  }

  .captcha-box img {
    max-width: 100%;
    height: auto;
  }
}