:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --fg: #1c1c1e;
  --muted: #6e6e73;
  --border: #d2d2d7;
  --accent: #0071e3;
  --danger: #d70015;
  --card-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --fg: #f5f5f7;
    --muted: #98989d;
    --border: #3a3a3c;
    --accent: #409cff;
    --danger: #ff453a;
    --card-bg: #2c2c2e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.auth-page {
  max-width: 360px;
  margin: 80px auto;
  padding: 0 20px;
  text-align: center;
}

h1 { font-size: 1.6rem; }

a { color: var(--accent); }

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.nav .brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--fg);
}

.nav nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.nav-email {
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

@media (max-width: 480px) {
  .nav-email { max-width: 44vw; }
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.card {
  display: block;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  text-decoration: none;
  color: inherit;
}

.card h2 { margin: 0 0 6px; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.empty { color: var(--muted); }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

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

/* Below this width, tables reflow into a stack of labeled cards instead of
   scrolling sideways -- the admin tables are dense with per-row forms, and
   horizontal scrolling while trying to tap small controls is a poor mobile
   experience. Each <td> needs a matching data-label attribute in the view. */
@media (max-width: 680px) {
  table, thead, tbody, tr, th, td { display: block; width: 100%; }
  thead { display: none; }

  tbody tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
    background: var(--card-bg);
  }

  tbody td {
    border-bottom: none;
    padding: 8px 0;
  }

  tbody td:not(:last-child) {
    border-bottom: 1px solid var(--border);
  }

  tbody td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--muted);
    margin-bottom: 4px;
  }

  .inline-form input, .inline-form select {
    flex: 1 1 auto;
    min-width: 0;
  }
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  margin-top: 12px;
}

.stacked-form label { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }

input, select, button {
  font-size: 1rem;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
}

button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: none;
  margin-top: 6px;
}

.inline-form {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0;
}

.link-button {
  min-height: 44px;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  font-size: 0.9rem;
}

.link-button.danger { color: var(--danger); }

.error { color: var(--danger); }
