:root {
  --bg: #f4efe6;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --border: rgba(63, 44, 24, 0.14);
  --text: #20160f;
  --muted: #6f5c4a;
  --primary: #0e7490;
  --primary-dark: #155e75;
  --affinity: #7c3aed;
  --affinity-dark: #6d28d9;
  --affinity-soft: rgba(124, 58, 237, 0.12);
  --accent: #d97706;
  --danger: #b91c1c;
  --shadow: 0 18px 40px rgba(53, 38, 24, 0.12);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(14, 116, 144, 0.16), transparent 28%),
    radial-gradient(circle at bottom right, rgba(217, 119, 6, 0.18), transparent 26%),
    linear-gradient(180deg, #faf7f2 0%, #efe6db 100%);
}

.login-body {
  display: grid;
  place-items: center;
}

.login-shell,
.error-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card,
.error-card {
  width: min(100%, 480px);
  padding: 40px;
  border-radius: 32px;
  background: var(--surface);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-badge,
.eyebrow,
.brand-subtitle,
.filter-label,
.stat-label {
  font-family: 'Inter', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.74rem;
  color: var(--muted);
}

.login-title,
.page-title,
.error-title {
  margin: 10px 0 10px;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1;
}

.login-copy,
.page-copy,
.panel-copy {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 22px;
  border-right: 1px solid var(--border);
  background: rgba(32, 22, 15, 0.92);
  color: #f9f4ee;
  min-height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 700;
}

.brand-copy {
  min-width: 0;
}

.sidebar-subtitle {
  color: rgba(249, 244, 238, 0.6);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 36px;
}

.sidebar-section {
  margin: 18px 10px 6px;
  font-family: 'Inter', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  color: rgba(249, 244, 238, 0.48);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  color: rgba(249, 244, 238, 0.82);
  text-decoration: none;
  transition: 0.2s ease;
}

.sidebar-link:hover,
.sidebar-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-link-affinity {
  color: #eadcff;
  background: rgba(124, 58, 237, 0.18);
}

.sidebar-link-affinity:hover,
.sidebar-link-affinity.active {
  background: rgba(124, 58, 237, 0.34);
  color: #fff;
}

.sidebar-footer {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
  margin: 0 10px 10px;
  color: rgba(249, 244, 238, 0.72);
  font-size: 0.92rem;
}

.app-main {
  padding: 32px;
  min-width: 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-inline,
.results-header {
  align-items: center;
}

.header-actions,
.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card,
.panel-card,
.modal-panel {
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 22px;
}

.stat-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  margin-bottom: 14px;
  background: rgba(14, 116, 144, 0.12);
  color: var(--primary-dark);
}

.stat-value {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
  line-height: 1;
}

.stat-value-small {
  font-size: 1rem;
  line-height: 1.4;
}

.panel-card {
  padding: 22px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-title {
  margin: 0;
  font-size: 1.25rem;
}

.filter-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
}

.filter-item {
  min-width: 180px;
}

.filter-item-wide {
  flex: 1 1 320px;
}

.filter-summary {
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(14, 116, 144, 0.08);
}

.badge-soft {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(217, 119, 6, 0.14);
  color: #8a4b07;
  font-size: 0.82rem;
}

.form-control,
.form-select {
  min-height: 46px;
  border-radius: 14px;
  border-color: rgba(63, 44, 24, 0.16);
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(14, 116, 144, 0.55);
  box-shadow: 0 0 0 0.2rem rgba(14, 116, 144, 0.12);
}

.btn {
  border-radius: 14px;
  font-weight: 600;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: 0;
}

.btn-outline-primary {
  color: var(--primary-dark);
  border-color: rgba(14, 116, 144, 0.35);
}

.btn-affinity {
  color: #fff;
  background: linear-gradient(135deg, var(--affinity), var(--affinity-dark));
  border: 0;
}

.btn-outline-affinity {
  color: var(--affinity-dark);
  border-color: rgba(124, 58, 237, 0.34);
}

.btn-outline-danger {
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.3);
}

.affinity-pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--affinity-soft);
  color: var(--affinity-dark);
  font-weight: 700;
}

.affinity-products-preview {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.affinity-products-select {
  min-height: 240px;
}

.table > :not(caption) > * > * {
  padding: 0.95rem 0.75rem;
  background: transparent;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border-radius: 12px;
  border: 1px solid var(--border);
}

.error-code {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(185, 28, 28, 0.1);
  color: var(--danger);
  font-family: 'IBM Plex Mono', monospace;
}

.error-list {
  margin: 18px 0;
  color: var(--muted);
}

.empty-state {
  padding: 28px;
  border-radius: 18px;
  margin-bottom: 18px;
  background: rgba(14, 116, 144, 0.06);
  border: 1px dashed rgba(14, 116, 144, 0.22);
}

.empty-state-inline {
  margin-top: 18px;
  margin-bottom: 0;
}

.empty-state-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.empty-state-copy {
  margin: 0;
  color: var(--muted);
}

.portal-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

.portal-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.portal-title {
  margin-bottom: 6px;
}

.portal-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.portal-panel {
  padding: 24px;
}

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
    gap: 24px;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    overflow: visible;
  }

  .sidebar-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .sidebar-section {
    grid-column: 1 / -1;
    margin-top: 8px;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  .app-main {
    padding: 20px;
  }
}

@media (max-width: 640px) {
  .login-card,
  .error-card,
  .panel-card {
    padding: 20px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .page-header,
  .panel-head,
  .filter-row,
  .portal-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar-header {
    align-items: flex-start;
  }

  .sidebar-nav {
    grid-template-columns: 1fr;
  }

  .sidebar-link {
    width: 100%;
  }
}