:root {
  color-scheme: dark;
  --bg: #150f23;
  --sidebar: #1f1633;
  --surface: #211833;
  --surface-2: #281d3d;
  --border: #3b2e50;
  --border-soft: rgba(255, 255, 255, .08);
  --text: #fff;
  --muted: #aaa2b5;
  --purple: #8c7ae6;
  --lime: #c2ef4e;
  --pink: #fa7faa;
  --coral: #ffb287;
  --danger: #ff758f;
  --radius: 14px;
  font-family: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
a { color: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }
[hidden] { display: none !important; }

.admin-app { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px 20px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.admin-brand { display: inline-flex; align-items: center; gap: 10px; width: fit-content; text-decoration: none; font-size: 20px; font-weight: 700; letter-spacing: -.04em; }
.admin-brand > span:last-child > span { color: var(--lime); }
.admin-brand-mark { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid #6a5fc1; border-radius: 9px; transform: rotate(8deg); }
.admin-brand-mark span { width: 11px; height: 11px; display: block; border: 2px solid var(--lime); border-radius: 3px; transform: rotate(37deg); }
.workspace-label, .section-label, .topbar-kicker { margin: 0; color: var(--muted); font: 500 10px/1.4 "JetBrains Mono", monospace; letter-spacing: .14em; text-transform: uppercase; }
.workspace-label { margin: 48px 12px 12px; }
.admin-nav { display: grid; gap: 5px; }
.admin-nav a { min-height: 44px; padding: 10px 12px; display: flex; align-items: center; gap: 12px; color: #c6bfce; border: 1px solid transparent; border-radius: 10px; text-decoration: none; font-size: 14px; font-weight: 500; }
.admin-nav a:hover { color: #fff; background: rgba(255,255,255,.05); }
.admin-nav a.is-active { color: #fff; background: #302445; border-color: #44345e; box-shadow: inset 3px 0 0 var(--lime); }
.nav-icon { width: 22px; text-align: center; color: var(--lime); font-size: 19px; }
.sidebar-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.admin-identity { display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; gap: 10px; }
.admin-avatar { width: 38px; height: 38px; display: grid; place-items: center; background: #45336a; border: 1px solid #6c58a1; border-radius: 11px; color: var(--lime); font-size: 12px; font-weight: 700; }
.admin-identity strong, .admin-identity small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-identity strong { font-size: 13px; }
.admin-identity small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.back-link { min-height: 44px; margin-top: 12px; display: flex; align-items: center; color: var(--muted); text-decoration: none; font-size: 12px; }
.back-link:hover { color: #fff; }

.admin-main { min-width: 0; padding: 34px clamp(24px, 4vw, 64px) 64px; background: radial-gradient(circle at 82% 0%, rgba(106,95,193,.16), transparent 30%), var(--bg); }
.admin-topbar { max-width: 1240px; margin: 0 auto 48px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.admin-topbar h1 { margin: 8px 0 0; font-size: clamp(26px, 3vw, 38px); line-height: 1; letter-spacing: -.04em; }
.topbar-kicker { color: var(--lime); }
.system-state { min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 999px; color: #c6bfce; font-size: 12px; background: rgba(31,22,51,.75); }
.system-state span { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 14px rgba(194,239,78,.7); }

.access-state { min-height: 55vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.access-state h2 { margin: 24px 0 8px; font-size: 24px; }
.access-state p { max-width: 460px; margin: 0; color: var(--muted); line-height: 1.6; }
.loading-orbit { width: 48px; height: 48px; border: 2px solid var(--border); border-top-color: var(--lime); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.access-error { padding: 48px 20px; }
.access-code { color: var(--lime); font: 500 clamp(70px, 10vw, 120px)/1 "JetBrains Mono", monospace; letter-spacing: -.08em; opacity: .18; }
.access-error .section-label { margin-top: -18px; color: var(--pink); }
.access-error h2 { font-size: clamp(25px, 4vw, 42px); }
.access-actions { margin-top: 28px; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.button { min-height: 44px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; text-decoration: none; font-size: 13px; font-weight: 600; }
.button-primary { background: var(--lime); color: #1b1329; box-shadow: inset 0 1px 3px rgba(0,0,0,.18); }
.button-secondary { background: #2b203e; border: 1px solid var(--border); }

.admin-dashboard { max-width: 1240px; margin: 0 auto; }
.dashboard-section + .dashboard-section { margin-top: 58px; }
.section-head { margin-bottom: 22px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.section-head h2 { margin: 5px 0 0; font-size: 24px; letter-spacing: -.03em; }
.section-head h2 span { color: var(--muted); font-size: 14px; font-weight: 400; }
.section-label { color: var(--purple); }
.icon-button { min-width: 44px; min-height: 44px; border: 1px solid var(--border); border-radius: 11px; color: #fff; background: #261b39; cursor: pointer; font-size: 20px; }
.icon-button:hover { background: #34264a; }
.icon-button:disabled { opacity: .45; cursor: wait; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { min-height: 170px; padding: 20px; position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: linear-gradient(145deg, rgba(255,255,255,.045), rgba(255,255,255,.012)); box-shadow: 0 16px 40px rgba(8,4,15,.16); }
.metric-card::after { content: ""; width: 90px; height: 90px; position: absolute; right: -30px; bottom: -35px; border-radius: 50%; background: currentColor; opacity: .08; filter: blur(3px); }
.metric-top { display: flex; justify-content: space-between; gap: 12px; color: #bdb5c7; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.metric-icon { width: 28px; height: 28px; display: grid; place-items: center; margin-top: -6px; border: 1px solid currentColor; border-radius: 8px; color: inherit; }
.metric-card strong { margin: 24px 0 8px; display: block; color: #fff; font: 500 38px/1 "JetBrains Mono", monospace; }
.metric-card small { color: var(--muted); font-size: 11px; }
.metric-purple { color: var(--purple); }
.metric-green { color: var(--lime); }
.metric-pink { color: var(--pink); }
.metric-coral { color: var(--coral); }

.users-head { align-items: center; }
.search-field { width: min(320px, 100%); min-height: 44px; padding: 0 13px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 11px; color: var(--muted); background: #211733; }
.search-field:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(140,122,230,.14); }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; color: #fff; background: transparent; font-size: 13px; }
.search-field input::placeholder { color: #7f7689; }
.table-shell { min-height: 180px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(31,22,51,.66); box-shadow: 0 20px 50px rgba(5,2,10,.18); }
table { width: 100%; border-collapse: collapse; }
th { height: 48px; padding: 0 16px; color: #8f8799; border-bottom: 1px solid var(--border); text-align: left; font: 500 10px/1 "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; }
td { min-height: 64px; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); color: #d9d4df; font-size: 12px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.026); }
.user-cell { display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: center; gap: 10px; }
.user-avatar { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid #4b3a64; border-radius: 10px; background: #2a1f3c; color: var(--purple); font-size: 11px; font-weight: 700; }
.user-cell strong, .user-cell small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-cell strong { color: #fff; font-size: 13px; font-weight: 500; }
.user-cell small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.role-badge, .provider-badge, .session-badge { min-height: 26px; padding: 0 9px; display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; font-size: 10px; }
.role-admin { color: var(--lime); border-color: rgba(194,239,78,.28); background: rgba(194,239,78,.08); }
.role-user { color: #b8afc2; }
.provider-list { display: flex; flex-wrap: wrap; gap: 5px; }
.provider-badge { color: var(--coral); }
.session-badge { gap: 6px; }
.session-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--lime); }
.session-zero::before { background: #6d6476; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-button { min-height: 36px; padding: 0 11px; border: 1px solid var(--border); border-radius: 9px; color: #ddd7e4; background: #291e3b; cursor: pointer; font-size: 10px; }
.row-button:hover { color: #fff; border-color: #66527f; background: #37284d; }
.row-button-danger:hover { color: #fff; border-color: rgba(255,117,143,.45); background: rgba(255,117,143,.1); }
.row-button:disabled { opacity: .4; cursor: not-allowed; }
.empty-state { min-height: 210px; padding: 36px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.empty-state > span { color: var(--purple); font-size: 30px; }
.empty-state strong { margin-top: 12px; color: #fff; }
.empty-state p { margin: 5px 0 0; font-size: 12px; }
.table-shell[aria-busy="true"] { opacity: .65; }
.load-more { min-height: 44px; margin: 14px auto 0; padding: 0 18px; display: block; border: 1px solid var(--border); border-radius: 11px; color: #fff; background: #291e3b; cursor: pointer; font-size: 12px; font-weight: 600; }
.load-more:hover { border-color: var(--purple); background: #37284d; }
.load-more:disabled { opacity: .5; cursor: wait; }

.admin-toast { min-height: 44px; max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; position: fixed; right: 20px; bottom: 20px; z-index: 10; border: 1px solid #5b4773; border-radius: 11px; color: #fff; background: #2d2141; box-shadow: 0 18px 45px rgba(0,0,0,.35); font-size: 12px; }
.admin-toast.is-error { border-color: rgba(255,117,143,.5); background: #442136; }
.visually-hidden { width: 1px; height: 1px; padding: 0; margin: -1px; position: absolute; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1080px) {
  .admin-app { grid-template-columns: 205px minmax(0, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  th, td { padding-inline: 11px; }
  .row-actions { flex-direction: column; }
}

@media (max-width: 760px) {
  .admin-app { display: block; }
  .admin-sidebar { position: static; width: 100%; height: auto; padding: 16px; display: grid; grid-template-columns: 1fr auto; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
  .workspace-label, .sidebar-foot { display: none; }
  .admin-nav { display: flex; }
  .admin-nav a { min-height: 44px; padding: 8px 11px; }
  .admin-nav a span:last-child { display: none; }
  .admin-main { padding: 24px 16px 48px; }
  .admin-topbar { margin-bottom: 32px; }
  .system-state { width: 44px; padding: 0; justify-content: center; font-size: 0; }
  .section-head, .users-head { align-items: flex-start; }
  .users-head { flex-direction: column; }
  .search-field { width: 100%; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 145px; padding: 16px; }
  .metric-card strong { margin-top: 20px; font-size: 31px; }
  .metric-top span:first-child { max-width: 90px; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody { padding: 8px; }
  tbody tr { padding: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 10px; border-bottom: 1px solid var(--border); }
  tbody tr:last-child { border-bottom: 0; }
  td { min-height: 0; padding: 0; border: 0; }
  td::before { content: attr(data-label); margin-bottom: 7px; display: block; color: #817789; font: 500 9px/1 "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; }
  td:first-child, td:last-child { grid-column: 1 / -1; }
  td:first-child::before, td:last-child::before { display: none; }
  .row-actions { flex-direction: row; justify-content: stretch; }
  .row-button { min-height: 44px; flex: 1; }
  .admin-toast { right: 16px; bottom: 16px; }
}

@media (max-width: 430px) {
  .admin-topbar h1 { font-size: 25px; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 132px; }
  .metric-card strong { margin-top: 16px; }
  .access-actions { width: 100%; flex-direction: column; }
  .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .loading-orbit { animation: none; }
}
