/* ─── MD3 Color tokens — dark default (matches main platform) ─── */
:root,
[data-theme="dark"] {
  --md-sys-color-primary: rgb(176 198 255);
  --md-sys-color-on-primary: rgb(21 46 96);
  --md-sys-color-primary-container: rgb(46 69 120);
  --md-sys-color-on-primary-container: rgb(217 226 255);
  --md-sys-color-secondary: rgb(167 200 255);
  --md-sys-color-tertiary: rgb(243 189 110);
  --md-sys-color-error: rgb(255 179 176);
  --md-sys-color-background: rgb(18 19 24);
  --md-sys-color-on-background: rgb(226 226 233);
  --md-sys-color-surface: rgb(18 19 24);
  --md-sys-color-on-surface: rgb(226 226 233);
  --md-sys-color-surface-variant: rgb(68 70 79);
  --md-sys-color-on-surface-variant: rgb(197 198 208);
  --md-sys-color-outline: rgb(143 144 153);
  --md-sys-color-outline-variant: rgb(68 70 79);
  --md-sys-color-surface-container-low: rgb(26 27 32);
  --md-sys-color-surface-container: rgb(30 31 37);
  --md-sys-color-surface-container-high: rgb(40 41 47);
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  color-scheme: dark;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  min-height: 100vh;
}

a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

/* ─── Nav bar ────────────────────────────────────────────── */
.admin-nav {
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
}

.admin-nav-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.admin-nav-btn {
  background: transparent;
  border: none;
  border-radius: 9999px;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.375rem 0.875rem;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.admin-nav-btn:hover {
  background-color: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
  text-decoration: none;
}

/* ─── Layout ─────────────────────────────────────────────── */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ─── Header ─────────────────────────────────────────────── */
.admin-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.admin-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--md-sys-color-on-background);
}

.admin-header .subtitle {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

.admin-header .date {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ─── Sections ───────────────────────────────────────────── */
.section {
  margin-bottom: 2.5rem;
}

.section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 1rem;
}

/* ─── Stats grid ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
}

.stat-card {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  padding: 0.875rem 1rem;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ─── Loading / error states ─────────────────────────────── */
.loading {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
  padding: 0.5rem 0;
}

.error-message {
  color: var(--md-sys-color-error);
  font-size: 0.8125rem;
  padding: 0.75rem 1rem;
  background: color-mix(in srgb, var(--md-sys-color-error) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-error) 30%, transparent);
  border-radius: 6px;
}

/* ─── Auth notice ────────────────────────────────────────── */
.auth-notice {
  max-width: 480px;
  margin: 4rem auto;
  text-align: center;
}

.auth-notice h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--md-sys-color-on-background);
}

.auth-notice p {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
  margin-bottom: 0.5rem;
}

.auth-notice a {
  color: var(--md-sys-color-primary);
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 9999px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-primary) 90%, white);
}

.btn-secondary {
  background: transparent;
  color: var(--md-sys-color-on-surface);
  border-color: var(--md-sys-color-outline);
}

.btn-secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.btn-danger {
  background: var(--md-sys-color-error);
  color: rgb(32 0 0);
}

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-error) 90%, white);
}

.btn-danger-outline {
  background: transparent;
  color: var(--md-sys-color-error);
  border-color: color-mix(in srgb, var(--md-sys-color-error) 50%, transparent);
}

.btn-danger-outline:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-error) 10%, transparent);
}

.btn-small {
  font-size: 0.75rem;
  padding: 0.3rem 0.75rem;
}

/* ─── Users table ────────────────────────────────────────── */
.users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.users-count {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 8px;
  overflow: hidden;
}

.users-table th,
.users-table td {
  text-align: left;
  padding: 0.6rem 0.875rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.users-table th {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface-container);
}

.users-table tbody tr:last-child td {
  border-bottom: none;
}

.users-table .user-actions {
  text-align: right;
  white-space: nowrap;
}

.users-table .user-actions .btn + .btn {
  margin-left: 0.4rem;
}

.user-row-deleted td {
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}

.user-deleted-label {
  color: var(--md-sys-color-on-surface-variant);
}

.users-empty {
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
  padding: 1rem;
}

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.875rem;
}

.pagination-info {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.modal h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.875rem;
  color: var(--md-sys-color-on-surface);
}

.modal p {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.5;
  margin-bottom: 0.875rem;
}

.modal .field {
  display: block;
  margin-bottom: 0.875rem;
}

.modal .field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 0.3rem;
}

.modal .field-readonly {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface);
  padding: 0.5rem 0.75rem;
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 6px;
}

.modal input[type="email"],
.modal input[type="text"],
.modal select {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

.modal input:focus,
.modal select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
}

.modal-error {
  color: var(--md-sys-color-error);
  font-size: 0.8125rem;
  padding: 0.6rem 0.75rem;
  background: color-mix(in srgb, var(--md-sys-color-error) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-error) 30%, transparent);
  border-radius: 6px;
  margin-bottom: 0.875rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
