:root {
  color-scheme: light;
  --white: #fff;
  --ink: #15171b;
  --ink-strong: #0f1112;
  --muted: #5d687a;
  --muted-soft: #9098a5;
  --line: #e6e8eb;
  --line-strong: #d6dade;
  --canvas: #f4f7fc;
  --soft: #f7f8fa;
  --selected: #eff1f2;
  --green: #4e985f;
  --amber: #b77935;
  --red: #a94f44;
  --sidebar-width: 242px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, ui-sans-serif, system-ui, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button, a, select { color: inherit; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 9px 12px;
  transform: translateY(-150%);
  border-radius: 6px;
  background: var(--ink-strong);
  color: white;
  font-size: 12px;
}
.skip-link:focus { transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100dvh;
}

.admin-sidebar {
  position: sticky;
  z-index: 3;
  top: 0;
  display: flex;
  height: 100dvh;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--white);
}

.window-lights { display: flex; height: 29px; align-items: center; padding: 0 7px; gap: 7px; }
.window-lights i { width: 12px; height: 12px; border-radius: 50%; }
.window-lights i:nth-child(1) { background: #ff5f57; }
.window-lights i:nth-child(2) { background: #febc2e; }
.window-lights i:nth-child(3) { background: #28c840; }

.admin-brand {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 7px;
  align-items: center;
  min-height: 52px;
  padding: 0 10px;
  gap: 10px;
  text-decoration: none;
}
.admin-brand img { width: 30px; height: 30px; border-radius: 7px; box-shadow: 0 6px 16px rgba(16, 24, 38, 0.12); }
.admin-brand span { font-size: 16px; font-weight: 760; letter-spacing: -0.02em; }
.admin-brand > i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

.admin-nav { display: grid; padding: 16px 7px; gap: 4px; }
.nav-label { margin: 8px 5px 3px; color: #8993a2; font-size: 8px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.nav-label.admin-label { margin-top: 25px; }
.admin-nav a {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  gap: 9px;
  border-radius: 6px;
  color: #56637a;
  font-size: 12px;
  font-weight: 560;
  text-decoration: none;
}
.admin-nav a:hover { background: var(--soft); color: var(--ink); }
.admin-nav a.active { background: var(--selected); color: var(--ink-strong); font-weight: 700; }
.admin-nav svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.database-card {
  margin: auto 9px 13px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}
.database-card > div { display: flex; align-items: center; gap: 8px; }
.database-card strong { font-size: 10px; }
.database-card p { margin: 7px 0 0 15px; color: var(--muted); font-size: 9px; line-height: 1.45; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #a6adb7; }
.status-dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(78, 152, 95, 0.1); }
.status-dot.error { background: var(--red); }

.admin-account {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  min-height: 55px;
  padding: 8px 11px;
  gap: 9px;
  border-top: 1px solid var(--line);
}
.account-avatar { display: grid; width: 26px; height: 26px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--soft); font-size: 9px; font-weight: 750; }
.admin-account strong, .admin-account small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-account strong { font-size: 10px; }
.admin-account small { margin-top: 2px; color: var(--muted-soft); font-size: 8px; }

.admin-main { min-width: 0; min-height: 100dvh; }
.admin-topbar {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}
.admin-topbar > div:first-child { display: flex; align-items: center; gap: 9px; }
.admin-topbar > div:first-child svg { width: 18px; height: 18px; fill: none; stroke: #64728a; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.admin-topbar strong { font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.live-state { display: flex; align-items: center; gap: 6px; padding: 0 7px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; }
.live-state i { width: 6px; height: 6px; border-radius: 50%; background: #aab1ba; }
.live-state[data-state="live"] { color: var(--green); }
.live-state[data-state="live"] i { background: var(--green); box-shadow: 0 0 0 3px rgba(78, 152, 95, 0.09); }
.live-state[data-state="error"] { color: var(--red); }
.live-state[data-state="error"] i { background: var(--red); }

.refresh-button, .workspace-link {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0 11px;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--white);
  font-size: 10px;
  font-weight: 650;
  text-decoration: none;
}
.refresh-button { cursor: pointer; }
.refresh-button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.refresh-button:hover, .workspace-link:hover { border-color: #aeb5bd; }
.refresh-button:disabled { cursor: wait; opacity: 0.58; }
.workspace-link { border-color: var(--ink-strong); background: var(--ink-strong); color: white; }

.dashboard-content { width: min(1480px, 100%); margin: 0 auto; padding: 40px clamp(20px, 3vw, 46px) 60px; }
.dashboard-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; }
.dashboard-heading h1 { margin: 0; font-size: clamp(27px, 3vw, 38px); font-weight: 720; letter-spacing: -0.035em; }
.dashboard-heading > div > p { max-width: 620px; margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.updated-at { margin: 0 0 3px; color: var(--muted-soft); font-size: 9px; white-space: nowrap; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-top: 32px; border: 1px solid var(--line); border-radius: 9px; background: var(--white); box-shadow: 0 14px 36px rgba(50, 63, 82, 0.045); }
.metric-grid article { min-width: 0; padding: 18px 20px 17px; border-right: 1px solid var(--line); }
.metric-grid article:last-child { border-right: 0; }
.metric-grid span, .metric-grid small { display: block; color: var(--muted); font-size: 9px; }
.metric-grid strong { display: block; margin-top: 12px; font-size: clamp(24px, 3vw, 34px); line-height: 1; letter-spacing: -0.04em; }
.metric-grid small { margin-top: 8px; color: var(--muted-soft); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 286px; align-items: start; margin-top: 18px; gap: 18px; }
.users-panel, .activity-panel { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--white); box-shadow: 0 14px 36px rgba(50, 63, 82, 0.04); }
.panel-heading { display: flex; min-height: 64px; align-items: center; justify-content: space-between; padding: 0 18px; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-heading > div:first-child { display: flex; align-items: baseline; gap: 9px; }
.panel-heading h2 { margin: 0; font-size: 12px; }
.panel-heading span { color: var(--muted-soft); font-size: 9px; }
.table-controls { display: flex; align-items: center; gap: 7px; }
.search-control { display: grid; grid-template-columns: 16px minmax(120px, 180px); min-height: 34px; align-items: center; padding: 0 9px; gap: 6px; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfd; }
.search-control svg { width: 15px; height: 15px; fill: none; stroke: #7c8797; stroke-width: 1.7; stroke-linecap: round; }
.search-control input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 10px; }
.search-control input::placeholder { color: #9ca4ae; }
.filter-control select { min-height: 34px; padding: 0 25px 0 9px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: #fbfcfd; color: #596679; font-size: 9px; }
.search-control:focus-within, .filter-control select:focus { border-color: #8ba5c3; box-shadow: 0 0 0 3px rgba(111, 147, 200, 0.1); }

.table-scroll { width: 100%; overflow-x: auto; outline: none; }
.table-scroll:focus-visible { box-shadow: inset 0 0 0 2px #8ba5c3; }
table { width: 100%; min-width: 830px; border-collapse: collapse; table-layout: fixed; }
th { height: 37px; padding: 0 12px; border-bottom: 1px solid var(--line); background: #fafbfc; color: #8a94a2; font-size: 8px; font-weight: 750; letter-spacing: 0.05em; text-align: left; text-transform: uppercase; }
td { height: 61px; padding: 8px 12px; border-bottom: 1px solid #eef0f2; color: #536075; font-size: 9px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover:not(.state-row) { background: #fbfcfd; }
th:nth-child(1) { width: 29%; }
th:nth-child(2), th:nth-child(3) { width: 14%; }
th:nth-child(4) { width: 9%; }
th:nth-child(5), th:nth-child(6) { width: 10%; }
th:nth-child(7) { width: 14%; }
.user-cell { display: grid; grid-template-columns: 32px minmax(0, 1fr); align-items: center; gap: 9px; }
.user-avatar { display: grid; width: 31px; height: 31px; overflow: hidden; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--soft); color: #556175; font-size: 10px; font-weight: 750; }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-copy { min-width: 0; }
.user-copy strong, .user-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy strong { color: var(--ink); font-size: 10px; }
.user-copy span { margin-top: 3px; color: var(--muted-soft); font-size: 8px; }
.role-chip, .status-chip { display: inline-flex; min-height: 21px; align-items: center; padding: 0 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: #616d7e; font-size: 8px; font-weight: 700; text-transform: capitalize; }
.role-stack { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.status-chip { min-height: 18px; padding: 0 5px; color: var(--green); }
.status-chip.pending { border-color: #ead8b8; background: #fffaf0; color: #a56a12; }
.role-chip.admin { border-color: #c9d9ec; background: #f2f7fd; color: #52739a; }
.status-chip.disabled, .status-chip.deleted { border-color: #ead7d2; background: #fff8f6; color: var(--red); }
.source-cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-cell small { display: block; margin-top: 3px; color: var(--muted-soft); }
.state-row td { height: 180px; color: var(--muted); text-align: center; }
.loading-line { display: inline-block; width: 38px; height: 5px; margin-right: 8px; border-radius: 5px; background: linear-gradient(90deg, #e7eaee, #f7f8fa, #e7eaee); background-size: 200% 100%; animation: loading 1.4s linear infinite; vertical-align: middle; }

.activity-panel { min-height: 360px; }
.activity-list { margin: 0; padding: 6px 0; list-style: none; }
.activity-list li { position: relative; display: grid; padding: 13px 18px 13px 35px; border-bottom: 1px solid #f0f1f3; }
.activity-list li:last-child { border-bottom: 0; }
.activity-list li::before { position: absolute; top: 18px; left: 18px; width: 6px; height: 6px; border-radius: 50%; background: var(--green); content: ""; }
.activity-list strong, .activity-list span, .activity-list time { display: block; }
.activity-list strong { color: var(--ink); font-size: 9px; }
.activity-list span { margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.activity-list time { margin-top: 5px; color: var(--muted-soft); font-size: 8px; }
.activity-list .activity-state { min-height: 130px; place-content: center; padding: 20px; color: var(--muted); font-size: 9px; text-align: center; }
.activity-list .activity-state::before { display: none; }

.dashboard-error { margin: 14px 0 0; padding: 11px 13px; border: 1px solid #ead7d2; border-radius: 6px; background: #fff8f6; color: var(--red); font-size: 10px; }
.access-state { width: min(520px, calc(100% - 40px)); margin: 15vh auto 0; padding: 45px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); text-align: center; box-shadow: 0 22px 60px rgba(47, 61, 80, 0.08); }
.access-state img { width: 44px; height: 44px; border-radius: 9px; }
.access-state h1 { margin: 22px 0 0; font-size: 26px; letter-spacing: -0.03em; }
.access-state p { margin: 11px auto 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.access-state a { display: inline-flex; min-height: 37px; margin-top: 24px; align-items: center; padding: 0 14px; border-radius: 6px; background: var(--ink-strong); color: white; font-size: 10px; font-weight: 700; text-decoration: none; }
.toast { position: fixed; z-index: 20; right: 22px; bottom: 22px; max-width: 340px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--ink-strong); color: white; box-shadow: 0 14px 35px rgba(20, 26, 36, 0.18); font-size: 10px; }

@keyframes loading { to { background-position: -200% 0; } }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .activity-panel { min-height: 0; }
  .activity-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .activity-list li:nth-child(odd) { border-right: 1px solid #f0f1f3; }
}

@media (max-width: 820px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .window-lights, .database-card, .admin-account { display: none; }
  .admin-brand { position: absolute; top: 8px; left: 10px; min-height: 40px; padding: 0; }
  .admin-brand img { width: 28px; height: 28px; }
  .admin-brand span, .admin-brand > i { display: none; }
  .admin-nav { display: flex; min-height: 56px; align-items: center; justify-content: flex-end; padding: 8px 10px 8px 50px; gap: 4px; overflow-x: auto; }
  .admin-nav .nav-label { display: none; }
  .admin-nav a { min-width: max-content; min-height: 34px; grid-template-columns: 17px auto; padding: 0 9px; }
  .admin-topbar { top: 0; padding: 0 12px; }
  .admin-topbar > div:first-child { display: none; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .dashboard-content { padding-top: 30px; }
}

@media (max-width: 660px) {
  .workspace-link { display: none; }
  .live-state { margin-right: auto; }
  .dashboard-heading { display: block; }
  .updated-at { margin-top: 14px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid article:nth-child(even) { border-right: 0; }
  .metric-grid article:not(:last-child) { border-bottom: 1px solid var(--line); }
  .panel-heading { display: block; padding: 15px 13px; }
  .table-controls { margin-top: 12px; flex-wrap: wrap; }
  .search-control { flex: 1 1 100%; grid-template-columns: 16px minmax(0, 1fr); }
  .filter-control { flex: 1 1 calc(50% - 4px); }
  .filter-control select { width: 100%; }
  .activity-list { grid-template-columns: 1fr; }
  .activity-list li:nth-child(odd) { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
