:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #182230;
  --muted: #667085;
  --line: #d9e2ec;
  --nav: #151f2e;
  --nav-soft: #202d40;
  --primary: #0f766e;
  --primary-dark: #0b5f58;
  --blue: #2563eb;
  --amber: #d99106;
  --rose: #e11d48;
  --green: #16a34a;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.admin-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--nav), #0f1724);
  color: #e5edf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #c51f28;
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}

.brand strong,
.brand small,
.sidebar-note strong,
.sidebar-note small {
  display: block;
}

.brand small,
.sidebar-note small {
  color: #98a9bd;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: #c8d4e4;
  text-decoration: none;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-soft);
  color: #fff;
}

.nav-icon {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.14);
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-pretitle {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 2px;
  font-size: 30px;
  line-height: 1.1;
}

h2 { font-size: 17px; }
h3 { font-size: 15px; }

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

.backend-pill {
  min-width: 180px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.backend-pill span,
.stat-card span,
.meta-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.backend-pill strong { display: block; margin-top: 2px; }

.card,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 18px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
}

body.is-authenticated .auth-card {
  grid-template-columns: 1fr;
  padding: 10px 14px;
}

body.is-authenticated .auth-form { display: none; }
body.is-authenticated #login-message { margin-top: 0; }

.auth-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus {
  border-color: rgba(15, 118, 110, .55);
  outline: 3px solid rgba(15, 118, 110, .12);
}

.btn,
button {
  min-height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.btn-primary,
button:not(.btn-soft):not(.btn-danger):not(.tab-btn):not(.row-action):not(.secondary):not(.danger) {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover,
button:not(.btn-soft):not(.btn-danger):not(.tab-btn):not(.row-action):not(.secondary):not(.danger):hover {
  background: var(--primary-dark);
}

.btn-soft,
button.secondary {
  background: #e8f5f3;
  color: var(--primary);
}

.btn-danger,
button.danger {
  background: #ffe7ea;
  color: #be123c;
}

button.small,
.row-action {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 110px;
  padding: 16px;
}

.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  line-height: 1;
}

.stat-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.stat-icon {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
}

.stat-icon.teal { background: var(--primary); }
.stat-icon.blue { background: var(--blue); }
.stat-icon.amber { background: var(--amber); }
.stat-icon.rose { background: var(--rose); }

.workspace {
  display: grid;
  grid-template-columns: minmax(430px, .85fr) minmax(520px, 1.15fr);
  gap: 16px;
  align-items: start;
}

.card { padding: 0; overflow: hidden; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfcfe);
}

.card-header.compact { min-height: 74px; }
.card-header .muted { margin-top: 3px; }

.search { max-width: 320px; }
.table-wrap { overflow-x: auto; }

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

.admin-table th,
.admin-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: #f8fafc;
}

.admin-table tr[data-user-id] { cursor: pointer; }
.admin-table tr[data-user-id]:hover { background: #f8fbff; }
.admin-table tr.is-selected { background: #ecfdf9; }
.admin-table strong { display: block; }
.admin-table small { display: block; margin-top: 2px; color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.green { background: #dcfce7; color: #166534; }
.badge.blue { background: #dbeafe; color: #1d4ed8; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.rose { background: #ffe4e6; color: #be123c; }
.badge.slate { background: #e2e8f0; color: #334155; }

.detail { padding: 16px; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.profile-card {
  display: grid;
  gap: 14px;
}

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

.profile-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #0891b2);
  color: #fff;
  font-weight: 900;
}

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

.meta-box,
.device,
.audit {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.meta-box strong,
.device strong,
.audit strong {
  display: block;
}

.meta-box span,
.device span,
.device small,
.audit small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: #eef2f6;
}

.tab-btn {
  min-height: 34px;
  background: transparent;
  color: var(--muted);
}

.tab-btn.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 10px; }

.audit-card { margin-top: 16px; }
.audit-card .admin-table { min-width: 760px; }

.muted { color: var(--muted); }
.danger-text { color: #be123c; font-weight: 800; }
.empty-state { padding: 16px; color: var(--muted); }

@media (max-width: 1180px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .nav-list { display: flex; }
  .sidebar-note { display: none; }
  .workspace { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .main { padding: 16px; }
  .topbar,
  .card-header,
  .profile-head { align-items: stretch; flex-direction: column; }
  .topbar-actions { align-items: stretch; flex-direction: column; }
  .auth-card,
  .auth-form,
  .stats-grid,
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { gap: 10px; }
  .search { max-width: none; }
}
