:root {
  --admin-bg: linear-gradient(180deg, #edf3f8 0%, #e7eef5 100%);
  --admin-surface: rgba(255, 255, 255, 0.96);
  --admin-surface-strong: rgba(255, 255, 255, 0.985);
  --admin-border: rgba(206, 219, 231, 0.92);
  --admin-border-strong: rgba(186, 203, 220, 0.96);
  --admin-text: #162235;
  --admin-muted: #66788f;
  --admin-primary: #167c67;
  --admin-primary-strong: #0f6958;
  --admin-primary-soft: #ddf4ec;
  --admin-danger-soft: #fde7e6;
  --admin-danger-text: #bb4d48;
  --admin-shadow: 0 18px 44px rgba(17, 24, 39, 0.08);
  --admin-shadow-strong: 0 24px 56px rgba(17, 24, 39, 0.14);
  --admin-radius-sm: 14px;
  --admin-radius-md: 20px;
  --admin-radius-lg: 28px;
  --admin-rail-width: 304px;
  --admin-shell-gap: 24px;
  --rail-bg: linear-gradient(180deg, #060b14 0%, #0a111d 48%, #060b14 100%);
  --rail-surface: rgba(255, 255, 255, 0.04);
  --rail-border: rgba(255, 255, 255, 0.08);
  --rail-border-strong: rgba(255, 255, 255, 0.12);
  --rail-text: rgba(244, 248, 255, 0.96);
  --rail-muted: rgba(158, 176, 203, 0.78);
  --rail-hover: rgba(255, 255, 255, 0.06);
  --rail-active: linear-gradient(135deg, rgba(21, 126, 105, 0.98), rgba(26, 164, 135, 0.94));
  --rail-active-shadow: 0 16px 30px rgba(14, 110, 92, 0.3);
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--admin-bg);
  color: var(--admin-text);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  padding: 14px;
}

button,
a,
input,
select,
textarea {
  font: inherit;
}

code,
.codeish,
textarea,
input[type='text'],
input[type='number'] {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}

.hidden,
[hidden] {
  display: none !important;
}

body[data-admin-page]:not([data-menu-ready='true']) .admin-menu {
  visibility: hidden;
}

.admin-shell {
  width: min(1680px, 100%);
  margin: 0 auto;
}

.admin-appbar {
  position: sticky;
  top: 12px;
  z-index: 100;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--rail-border);
  border-radius: var(--admin-radius-lg);
  background: var(--rail-bg);
  color: var(--rail-text);
  box-shadow: var(--admin-shadow-strong);
}

.admin-appbar.is-hidden-on-scroll {
  transform: translateY(calc(-100% - 14px));
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.admin-brand {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr);
  align-items: center;
  column-gap: 14px;
  row-gap: 4px;
}

.admin-brand::before {
  content: "";
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: linear-gradient(135deg, #5c4cff, #8968ff);
  box-shadow: 0 14px 28px rgba(102, 79, 255, 0.34);
  grid-row: 1 / span 2;
}

.admin-brand strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--rail-text);
}

.admin-brand small {
  display: block;
  color: var(--rail-muted);
  line-height: 1.45;
}

.admin-menu {
  grid-column: 1 / -1;
  position: relative;
}

.admin-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--rail-border-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--rail-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.admin-menu-toggle-icon {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.admin-menu-toggle-icon span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.admin-menu-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  max-height: min(72vh, 680px);
  padding: 16px;
  border: 1px solid var(--rail-border);
  border-radius: var(--admin-radius-md);
  background: rgba(8, 14, 25, 0.985);
  box-shadow: var(--admin-shadow-strong);
  overflow-y: auto;
  overflow-x: hidden;
}

.admin-menu.is-open .admin-menu-panel {
  display: flex;
}

.admin-menu-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-menu-group-title {
  padding: 0 10px;
  color: var(--rail-muted);
  font-size: 0.71rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.admin-menu-group.is-current .admin-menu-group-title {
  color: rgba(173, 255, 228, 0.88);
}

.admin-menu-group-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-menu-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: transparent;
  color: var(--rail-text);
  text-decoration: none;
  font-weight: 600;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.admin-menu-link:hover {
  background: var(--rail-hover);
  border-color: rgba(255, 255, 255, 0.04);
  transform: translateY(-1px);
}

.admin-menu-link[aria-current='page'] {
  background: var(--rail-active);
  border-color: rgba(97, 255, 215, 0.16);
  color: #f7fffb;
  box-shadow: var(--rail-active-shadow);
}

.admin-menu-link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.admin-menu-link-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.admin-menu-link-text {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-account {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.admin-account-meta {
  display: none;
}

.admin-account-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.tenant-switch {
  display: none;
  align-items: center;
  gap: 8px;
  color: var(--rail-muted);
}

.tenant-switch:not(.hidden) {
  display: inline-flex;
}

.tenant-switch span {
  font-size: 0.78rem;
  font-weight: 700;
}

.tenant-switch select {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--admin-border-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--admin-text);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: linear-gradient(135deg, #15806a, #1ca88a);
  color: #f5fffb;
  box-shadow: 0 14px 24px rgba(18, 125, 105, 0.22);
}

.button.secondary {
  background: rgba(22, 124, 103, 0.08);
  border-color: rgba(22, 124, 103, 0.16);
  color: var(--admin-primary-strong);
}

.button.ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--rail-border-strong);
  color: var(--rail-text);
}

.button.compact {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 12px;
}

.page-shell {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-hero,
.panel,
.surface-card,
.tool-card {
  background: var(--admin-surface-strong);
  border: 1px solid var(--admin-border);
  border-radius: var(--admin-radius-md);
  box-shadow: var(--admin-shadow);
}

.page-hero {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.page-hero h1 {
  margin: 6px 0 8px;
  font-size: clamp(1.85rem, 7vw, 3rem);
  line-height: 1;
  letter-spacing: -0.03em;
}

.page-hero-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #5b6dff;
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted {
  color: var(--admin-muted);
  line-height: 1.6;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(22, 124, 103, 0.08);
  color: var(--admin-primary-strong);
  border: 1px solid rgba(22, 124, 103, 0.14);
  font-weight: 700;
}

.field {
  display: grid;
  gap: 8px;
}

.field > span,
.field label,
label.field > span {
  color: var(--admin-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
label.field input,
label.field select,
label.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--admin-border-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--admin-text);
}

.field textarea,
label.field textarea {
  min-height: 120px;
  resize: vertical;
}

@media (max-width: 1179.98px) {
  .admin-account {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  .page-hero-actions {
    width: 100%;
  }
}

@media (min-width: 1180px) {
  body {
    padding: 18px;
  }

  .admin-shell {
    position: relative;
    min-height: calc(100vh - 36px);
  }

  .admin-appbar {
    position: fixed;
    top: 18px;
    left: 18px;
    width: var(--admin-rail-width);
    height: calc(100vh - 36px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
    padding: 22px 18px;
    margin: 0;
    border-radius: 30px;
    overflow: hidden;
  }

  .admin-brand {
    flex: 0 0 auto;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--rail-border);
  }

  .admin-menu {
    grid-column: auto;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
  }

  .admin-menu-toggle {
    display: none;
  }

  .admin-menu-panel {
    display: flex;
    position: static;
    flex: 1 1 auto;
    max-height: none;
    padding: 4px 2px 4px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .admin-menu-panel::-webkit-scrollbar {
    width: 8px;
  }

  .admin-menu-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border-radius: 999px;
  }

  .admin-account {
    flex: 0 0 auto;
    margin-top: auto;
    padding: 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--rail-border);
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .admin-account-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .admin-account-meta strong {
    color: var(--rail-text);
    font-size: 0.92rem;
  }

  .admin-account-meta small {
    color: var(--rail-muted);
    line-height: 1.5;
  }

  .admin-account-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .tenant-switch {
    flex-direction: column;
    align-items: stretch;
  }

  .button.ghost {
    width: 100%;
  }

  .page-shell {
    margin-left: calc(var(--admin-rail-width) + var(--admin-shell-gap));
    min-height: calc(100vh - 36px);
  }

  .page-hero {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .page-hero-actions {
    align-items: flex-end;
    min-width: 260px;
  }
}
