:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #202124;
  background: #f6f7f9;
  --brand: #c51f2d;
  --brand-dark: #971824;
  --brand-soft: #fff0f2;
  --accent: #f7b928;
  --accent-soft: #fff8df;
  --ink: #202124;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #fff;
  --surface-2: #f9fafb;
  --success: #137a48;
  --success-soft: #eaf8f0;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warn: #9b6200;
  --warn-soft: #fff6e0;
  --shadow: 0 10px 30px rgba(25, 30, 40, .06);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f6f7f9;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

a {
  color: inherit;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #18191d;
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

.brand-block {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 2px 8px 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--brand);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 900;
  font-size: 20px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12);
}

.brand {
  font-weight: 850;
  letter-spacing: -.02em;
  font-size: 17px;
}

.brand-sub {
  font-size: 11px;
  color: #aeb4bf;
  margin-top: 2px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #8f96a3;
  padding: 9px 11px 4px;
  font-weight: 800;
}

.nav-link {
  display: flex;
  gap: 10px;
  align-items: center;
  text-decoration: none;
  border-radius: 11px;
  padding: 10px 11px;
  color: #d6dae1;
  font-size: 13px;
  font-weight: 650;
}

.nav-link:hover {
  background: #24262b;
  color: #fff;
}

.nav-link.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 20px rgba(197, 31, 45, .22);
}

.nav-icon {
  width: 21px;
  text-align: center;
  font-size: 15px;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid #2b2d33;
  padding-top: 14px;
}

.sidebar-note {
  font-size: 11px;
  line-height: 1.5;
  color: #9da4af;
  padding: 0 9px 12px;
}

.main-column {
  min-width: 0;
  width: 100%;
}

.topbar {
  height: 64px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 6;
  backdrop-filter: blur(10px);
}

.topbar-title {
  font-weight: 750;
  font-size: 14px;
}

.topbar-meta {
  font-size: 12px;
  color: var(--muted);
}

.wrap {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 22px clamp(16px, 1.8vw, 30px) 34px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.page-head h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -.035em;
  line-height: 1.15;
}

.page-head p {
  margin: 7px 0 0;
  color: var(--muted);
  max-width: 780px;
  font-size: 14px;
  line-height: 1.5;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
  gap: 14px;
}

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

.card {
  background: var(--surface);
  border: 1px solid #e7e9ee;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 5px 20px rgba(25, 30, 40, .045);
}

.card.soft {
  box-shadow: none;
  background: var(--surface-2);
}

.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 126px;
}

.metric-card:after {
  content: "";
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  right: -20px;
  top: -20px;
  background: var(--brand-soft);
}

.metric {
  font-size: 30px;
  font-weight: 850;
  letter-spacing: -.04em;
  line-height: 1.1;
  margin-top: 11px;
}

.metric-label {
  font-weight: 720;
  font-size: 13px;
}

.metric-help {
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
}

.metric.warn {
  color: var(--warn);
}

.metric.danger {
  color: var(--danger);
}

.metric.success {
  color: var(--success);
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.section {
  margin: 28px 0 12px;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}

.section-title h2 {
  font-size: 18px;
  margin: 0;
}

.section-title p {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 0;
}

.table-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
}

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

.table th,
.table td {
  padding: 13px 14px;
  border-bottom: 1px solid #edf0f2;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

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

.table th {
  background: #fafbfc;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #667085;
  font-weight: 800;
  white-space: nowrap;
}

.table tbody tr:hover {
  background: #fcfcfd;
}

.cell-title {
  font-weight: 750;
  color: #272a2f;
}

.cell-sub {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
}

.empty-cell {
  text-align: center !important;
  padding: 34px !important;
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  word-break: break-all;
  white-space: pre-wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #475467;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .025em;
}

.badge.success {
  background: var(--success-soft);
  color: var(--success);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.warning {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.brand {
  background: var(--brand-soft);
  color: var(--brand);
}

button,
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 13px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  transition: .15s ease;
}

.btn:hover,
button:hover {
  transform: translateY(-1px);
  background: var(--brand-dark);
  color: #fff;
}

.btn.secondary,
button.secondary {
  background: #fff;
  color: #344054;
  border-color: #d0d5dd;
}

.btn.ghost {
  background: transparent;
  color: #d6dae1;
  border-color: #34373e;
  width: 100%;
}

.btn.danger,
button.danger {
  background: var(--danger);
  color: #fff;
}

.btn.warning {
  background: var(--warn);
  color: #fff;
}

.btn.disabled {
  opacity: .5;
  pointer-events: none;
}

.filters button,
.filters .btn {
  height: 43px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin-top: auto;
}

.inline-form {
  display: inline;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

label {
  font-size: 12px;
  font-weight: 720;
  display: block;
  margin: 10px 0 6px;
  color: #344054;
}

.field-help {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.4;
}

input,
select,
textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  padding: 10px 11px;
  background: #fff;
  color: #202124;
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: .15s;
}

textarea {
  resize: vertical;
  min-height: 92px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(197, 31, 45, .10);
}

.checkbox-inline {
  width: auto;
}

.filters {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.filters.audit {
  grid-template-columns: minmax(220px, 1fr) auto;
}

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

.danger-zone {
  border-color: #f4c7c3;
  background: #fffafa;
}

.flash {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  background: var(--success-soft);
  border: 1px solid #bde7cf;
  color: #12633d;
  font-size: 13px;
  font-weight: 650;
}

.flash.err {
  background: var(--danger-soft);
  border-color: #fac5bf;
  color: #912018;
}

.callout {
  display: flex;
  gap: 11px;
  border: 1px solid #f1d891;
  background: var(--accent-soft);
  padding: 13px 14px;
  border-radius: 13px;
  color: #664500;
  font-size: 12px;
  line-height: 1.5;
}

.callout.brand {
  background: var(--brand-soft);
  border-color: #f6c9ce;
  color: #781520;
}

.callout-icon {
  font-size: 18px;
  line-height: 1;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
}

.detail-title {
  font-size: 24px;
  font-weight: 850;
  letter-spacing: -.03em;
}

.detail-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  margin-top: 16px;
}

.stat-item {
  background: #fff;
  padding: 14px;
}

.stat-value {
  font-size: 20px;
  font-weight: 820;
}

.stat-label {
  color: var(--muted);
  font-size: 10px;
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.pagination {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
  align-items: center;
}

.pagination-label {
  padding: 0 6px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, .65fr);
  gap: 16px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.admin-login {
  margin: 0;
  background: #f4f5f7;
  color: var(--ink);
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, .9fr) minmax(460px, 1.1fr);
}

.login-brand {
  position: relative;
  overflow: hidden;
  background: #18191d;
  color: #fff;
  padding: clamp(38px, 7vw, 92px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-brand:after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: var(--brand);
  right: -150px;
  bottom: -170px;
}

.login-brand:before {
  content: "";
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--accent);
  right: 80px;
  bottom: 35px;
  opacity: .95;
}

.login-brand h1 {
  font-size: 42px;
  letter-spacing: -.05em;
  margin: 18px 0 10px;
  position: relative;
  z-index: 1;
}

.login-brand p {
  max-width: 460px;
  color: #c6cbd4;
  line-height: 1.65;
  font-size: 14px;
  position: relative;
  z-index: 1;
}

.login-brand .brand-chip {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  background: #24262b;
  border: 1px solid #353841;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 11px;
  color: #e8eaee;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-box {
  width: min(460px, 100%);
  background: #fff;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(28, 31, 36, .10);
}

.login-box h2 {
  margin: 0;
  font-size: 27px;
  letter-spacing: -.035em;
}

.login-box .muted {
  margin: 7px 0 20px;
  line-height: 1.5;
}

.login-box input {
  padding: 12px;
}

.login-box button {
  margin-top: 18px;
  width: 100%;
  padding: 12px;
}

.login-error {
  padding: 11px 12px;
  background: var(--danger-soft);
  color: #912018;
  border: 1px solid #fac5bf;
  border-radius: 10px;
  font-size: 12px;
  margin: 12px 0;
}

.security-note {
  margin-top: 17px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

/* Tablet & Smaller Desktop Adjustments */
@media(max-width:1050px) {
  .admin-shell {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .wrap {
    padding: 18px 20px;
  }

  .topbar {
    padding: 0 20px;
  }

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

/* Optimized Mobile & Tablet Viewport Fixes */
@media(max-width:760px) {
  .admin-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  /* Make mobile sidebar a clean, compact top navigation or horizontal scrollable bar */
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    max-height: none;
    padding: 10px 14px;
    gap: 8px;
    z-index: 50;
    border-bottom: 1px solid #2b2d33;
  }

  .brand-block {
    padding: 2px 4px 6px;
    justify-content: space-between;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    font-size: 15px;
    border-radius: 9px;
  }

  .brand {
    font-size: 15px;
  }

  .brand-sub {
    font-size: 10px;
  }

  /* Transform nav groups into smooth horizontal scrolling pills for mobile/tablet */
  .nav-group {
    display: flex;
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .nav-group::-webkit-scrollbar {
    display: none;
  }

  .nav-label {
    display: none;
    /* Hide heavy section labels on mobile to save vertical space */
  }

  .nav-link {
    flex: 0 0 auto;
    padding: 7px 12px;
    font-size: 12px;
    border-radius: 8px;
    min-height: unset;
    background: #24262b;
    white-space: nowrap;
  }

  .nav-link.active {
    background: var(--brand);
    color: #fff;
  }

  .nav-icon {
    width: 16px;
    font-size: 13px;
  }

  .sidebar-footer,
  .sidebar-note {
    display: none;
    /* Clean up bottom fluff on small screens */
  }

  .topbar {
    position: sticky;
    top: 53px;
    /* Stacks nicely right below the horizontal mobile nav */
    height: auto;
    min-height: 50px;
    padding: 8px 14px;
    z-index: 40;
  }

  .topbar-meta {
    display: none;
  }

  .wrap {
    padding: 14px 12px 32px;
  }

  .page-head {
    display: block;
    margin-bottom: 16px;
  }

  .page-head h1 {
    font-size: 22px;
  }

  .page-head p {
    font-size: 13px;
  }

  .page-actions {
    margin-top: 10px;
  }

  .filters,
  .filters.audit {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
  }

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

  .detail-hero {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Compact Login Screen Fix for Mobile */
  .admin-login {
    display: block;
    min-height: 100vh;
    background: #f4f5f7;
  }

  .login-brand {
    min-height: auto;
    padding: 20px 16px;
  }

  .login-brand h1 {
    font-size: 22px;
    margin: 6px 0 4px;
  }

  .login-brand p {
    display: none;
    /* Hide heavy description on small screens */
  }

  .login-panel {
    padding: 12px 16px 28px;
  }

  .login-box {
    width: 100%;
    padding: 20px 16px;
    border-radius: 16px;
  }

  .login-box h2 {
    font-size: 22px;
  }

  .pagination {
    justify-content: center;
    flex-wrap: wrap;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

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

/* Extra small devices (phones below 480px) */
@media(max-width:480px) {
  .stat-strip {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    gap: 6px;
  }

  .environment-pill {
    padding: 5px 8px;
    font-size: 9.5px;
  }
}

/* R8 reusable modern admin refinements */
.page-head-copy {
  min-width: 0;
  flex: 1;
}

.metric-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric-icon {
  position: relative;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 12px;
}

.monitoring-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.danger-callout {
  background: var(--danger-soft);
  border-color: #fac5bf;
  color: #912018;
  margin: 0 0 16px;
}

.health-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.table-wrap {
  box-shadow: 0 4px 18px rgba(25, 30, 40, .04);
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.topbar {
  box-shadow: 0 1px 0 rgba(16, 24, 40, .02);
}

@media(max-width:1050px) {
  .monitoring-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media(max-width:760px) {
  .monitoring-metrics {
    grid-template-columns: 1fr;
  }

  .wrap {
    padding: 14px 12px 28px;
  }

  .page-head {
    margin-bottom: 16px;
  }

  .page-head h1 {
    font-size: 23px;
  }
}

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

@media(max-width:1250px) {
  .dashboard-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media(max-width:900px) {
  .dashboard-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media(max-width:520px) {
  .dashboard-metrics {
    grid-template-columns: 1fr;
  }
}

/* R8 modern admin shell */
.skip-link {
  position: fixed;
  left: 16px;
  top: -80px;
  z-index: 100;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 800;
}

.skip-link:focus {
  top: 12px;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
}

.nav-icon svg {
  display: block;
}

.nav-link {
  min-height: 42px;
  border-radius: 12px;
}

.nav-link.active {
  box-shadow: inset 0 0 0 1px rgba(185, 28, 43, .08);
}

.sidebar-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.topbar-copy {
  min-width: 0;
}

.topbar-eyebrow {
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  margin-bottom: 2px;
}

.topbar-title {
  font-size: 15px;
  letter-spacing: -.015em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.environment-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
}

.environment-pill .status-dot {
  width: 7px;
  height: 7px;
}

.flash {
  display: flex;
  gap: 5px;
  align-items: baseline;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.table tbody tr {
  transition: background-color .15s ease;
}

.table tbody tr:hover {
  background: #fafbfc;
}

.btn,
.nav-link,
input,
select,
textarea {
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease, transform .15s ease;
}

.btn:active {
  transform: translateY(1px);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #d66b77;
  box-shadow: 0 0 0 3px rgba(185, 28, 43, .08);
}

.action-cell {
  min-width: 240px;
}

.action-cell form {
  min-width: 220px;
}

.settings-card {
  display: flex;
  flex-direction: column;
}

.settings-card .actions {
  margin-top: auto;
  padding-top: 14px;
}

.settings-key {
  margin: 10px 0 4px;
  font-size: 13px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 11px 12px;
  margin: 14px 0 8px;
}

.switch-row input {
  margin: 0;
}

.table pre {
  margin: 0;
  max-width: 360px;
  max-height: 120px;
  overflow: auto;
}

.table-wrap {
  overflow: auto;
}

.table {
  min-width: 760px;
}

.table-wrap .table {
  width: 100%;
}

@media(max-width:760px) {
  .table {
    min-width: 680px;
  }

  .action-cell {
    min-width: 210px;
  }
}