:root {
  --leaf: #0f5934;
  --leaf-2: #10b981;
  --bg: #f6f8f6;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --danger: #b91c1c;
  --danger-2: #fee2e2;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 14px;
}

.adm-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px;
  background: linear-gradient(135deg, var(--leaf), #082e1c);
  color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.adm-header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.adm-user { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.adm-link { color: #d1fae5; text-decoration: none; }
.adm-link:hover { text-decoration: underline; }

.adm-main {
  display: grid; grid-template-columns: 1fr; gap: 16px;
  padding: 16px; max-width: 1600px; margin: 0 auto;
}
.adm-main:has(.adm-detail:not(.adm-hidden)) {
  grid-template-columns: 1.4fr 1fr;
}

.adm-list, .adm-detail {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
  /* Without min-width:0 a wide horizontally-scrolling table inside a grid
     cell would force the cell wider than the viewport, producing
     horizontal page scroll on mobile. */
  min-width: 0;
}

.adm-toolbar {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
  flex-wrap: wrap;
}
.adm-toolbar input[type=search] {
  flex: 1; min-width: 200px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.adm-checkbox { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.adm-meta { color: var(--muted); font-size: 12px; }

.adm-table-wrap { overflow-x: auto; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.adm-table th, .adm-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.adm-table th { background: #fafafa; font-weight: 600; color: #374151; }
.adm-table tbody tr { cursor: pointer; }
.adm-table tbody tr:hover { background: #f0fdf4; }
.adm-table tbody tr.selected { background: #d1fae5; }
.adm-empty { text-align: center; color: var(--muted); padding: 24px 0; }

.adm-pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.adm-pill-free     { background: #f3f4f6; color: #374151; }
.adm-pill-standard { background: #dcfce7; color: #166534; }
.adm-pill-pro      { background: #fae8ff; color: #86198f; }
/* Legacy alias — pre-rename payloads may still carry plan="team". */
.adm-pill-team     { background: #fae8ff; color: #86198f; }

/* Inline per-row plan editor in the users table. Tightly styled so it
   doesn't blow up the row height; clicking it skips the detail-pane
   open so the change feels instant. */
.adm-plan-quick {
  font-size: 12px; padding: 3px 6px;
  border: 1px solid var(--border, #e5e7eb); border-radius: 6px;
  background: white; cursor: pointer;
  font-family: inherit;
}
.adm-plan-quick:hover { border-color: #16a34a; }
.adm-plan-quick:focus { outline: 2px solid #16a34a; outline-offset: -1px; }
.adm-plan-quick:disabled { opacity: .5; cursor: wait; }
.adm-pill-active { background: #d1fae5; color: #065f46; }
.adm-pill-inactive { background: #fee2e2; color: #991b1b; }
.adm-pill-admin { background: #fef3c7; color: #92400e; margin-left: 4px; }
.adm-pill-google { background: #e0f2fe; color: #075985; }
.adm-pill-password { background: #f1f5f9; color: #334155; }

.adm-detail-head {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 10px;
}
.adm-detail-head h2 { margin: 0; font-size: 16px; word-break: break-all; }
.adm-section { margin-top: 14px; }
.adm-section h3 { margin: 0 0 8px; font-size: 13px; color: var(--leaf); text-transform: uppercase; letter-spacing: 0.05em; }
.adm-section h4 { margin: 12px 0 6px; font-size: 12px; color: var(--muted); }

.adm-kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.adm-kv dt { color: var(--muted); }
.adm-kv dd { margin: 0; word-break: break-all; }

#adm-edit-form label { display: block; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
#adm-edit-form input[type=text], #adm-edit-form select {
  display: block; width: 100%; margin-top: 2px;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}

.adm-table-sub { width: 100%; border-collapse: collapse; font-size: 12px; }
.adm-table-sub th, .adm-table-sub td {
  text-align: left; padding: 5px 8px; border-bottom: 1px solid #f3f4f6;
}
.adm-table-sub th { background: #fafafa; font-weight: 600; color: #6b7280; }
.adm-events-wrap { max-height: 280px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }

.adm-btn, .adm-btn-primary, .adm-btn-danger, .adm-btn-ghost {
  padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
  border: 1px solid transparent;
}
.adm-btn { background: #fff; border-color: var(--border); color: var(--text); }
.adm-btn:hover { background: #f9fafb; }
.adm-btn-primary { background: var(--leaf); color: #fff; }
.adm-btn-primary:hover { background: #0a4527; }
.adm-btn-danger { background: var(--danger); color: #fff; }
.adm-btn-danger:hover { background: #991b1b; }
.adm-btn-ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,0.4); }
.adm-btn-ghost:hover { background: rgba(255,255,255,0.1); }

.adm-danger {
  background: #fef2f2; border-radius: 8px; padding: 10px;
  border: 1px solid var(--danger-2);
}
.adm-danger button { margin-right: 8px; }

.adm-hidden { display: none !important; }

.adm-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px; background: #111827; color: #fff;
  border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 999;
}
.adm-toast.show { opacity: 0.95; }
.adm-toast.error { background: var(--danger); }

.adm-fatal {
  max-width: 500px; margin: 80px auto; padding: 30px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  text-align: center; color: var(--text);
}
.adm-fatal h2 { color: var(--danger); }
.adm-fatal a { color: var(--leaf); }

/* ─── Responsive ─── */
@media (max-width: 720px) {
  .adm-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .adm-header h1 { font-size: 16px; text-align: center; }
  .adm-user {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    font-size: 12.5px;
  }
  #adm-me-email { word-break: break-all; max-width: 100%; }

  .adm-main {
    padding: 12px;
    gap: 12px;
  }
  /* List + detail stack vertically; otherwise the detail column is
     unreadable at <720px. */
  .adm-main:has(.adm-detail:not(.adm-hidden)) {
    grid-template-columns: 1fr;
  }
  .adm-list, .adm-detail { padding: 12px; }

  .adm-toolbar { gap: 8px; }
  .adm-toolbar input[type=search] {
    flex: 1 1 100%;
    min-width: 0;
  }
  .adm-toolbar .adm-checkbox { flex: 1 1 auto; }

  .adm-table th, .adm-table td {
    padding: 7px 8px;
    font-size: 12.5px;
  }
  .adm-detail-head h2 { font-size: 15px; }
  .adm-section h3 { font-size: 12.5px; }
  .adm-kv {
    grid-template-columns: 80px 1fr;
    font-size: 12.5px;
  }
  .adm-table-sub th, .adm-table-sub td {
    padding: 5px 7px;
    font-size: 11.5px;
  }
  .adm-events-wrap { max-height: 220px; }

  .adm-toast {
    left: 12px; right: 12px;
    transform: none;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .adm-header h1 { font-size: 15px; }
  .adm-user a, .adm-user button { font-size: 12px; padding: 6px 10px; }

  .adm-list, .adm-detail { padding: 10px; }
  .adm-toolbar .adm-btn { flex: 1 1 auto; }
  .adm-toolbar .adm-meta { flex: 1 1 100%; text-align: center; }

  .adm-table th, .adm-table td {
    padding: 6px 7px;
    font-size: 12px;
  }

  .adm-kv { grid-template-columns: 70px 1fr; gap: 4px 8px; }

  /* Stack the destructive buttons so each is full width and clearly
     labelled on a small screen. */
  .adm-danger button {
    margin-right: 0;
    margin-bottom: 8px;
    width: 100%;
  }
  .adm-danger button:last-child { margin-bottom: 0; }
}
