:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #111a2e;
  --text: #e6ecff;
  --muted: rgba(230, 236, 255, 0.72);
  --primary: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 10px;
  --ring: rgba(147, 197, 253, 0.7);
  --surface: rgba(17, 26, 46, 0.78);
  --surface-strong: rgba(17, 26, 46, 0.92);
  --surface-soft: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  background: radial-gradient(1200px 700px at 20% -10%, rgba(37, 99, 235, 0.22), transparent 60%),
              radial-gradient(900px 500px at 90% 0%, rgba(34, 197, 94, 0.10), transparent 55%),
              linear-gradient(180deg, #071024, #050914);
  color: var(--text);
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: #9cc4ff; }
a:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 8px; }

.container {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0;
}
.narrow { width: min(520px, calc(100% - 32px)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(9, 15, 29, 0.75);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  gap: 12px;
}
.brand { font-weight: 700; letter-spacing: 0.2px; }
.right { display: flex; align-items: center; gap: 12px; }
.user { color: var(--muted); font-size: 14px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(8px);
}

.row { display: flex; gap: 14px; }
.row > * { flex: 1; }

label { display: grid; gap: 6px; margin-bottom: 12px; font-size: 13px; color: rgba(230, 236, 255, 0.9); }
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}
.inline-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
}
input, select, textarea {
  width: 100%;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
  font-size: 14px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: rgba(147, 197, 253, 0.65);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.18);
}
input::placeholder, textarea::placeholder { color: rgba(230, 236, 255, 0.45); }
select {
  appearance: none;
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(230, 236, 255, 0.75) 50%),
    linear-gradient(135deg, rgba(230, 236, 255, 0.75) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
select option { background: #0b1220; color: var(--text); }

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms ease, filter 140ms ease, background 140ms ease, border-color 140ms ease;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(0.98); }
.btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
.btn-secondary { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.16); }
.btn-secondary:hover { background: rgba(255, 255, 255, 0.10); }
.btn-danger { background: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.flash {
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}
.flash-error { border-color: rgba(239, 68, 68, 0.35); }
.flash-success { border-color: rgba(34, 197, 94, 0.35); }
.admin-scope-note {
  margin-bottom: 12px;
}
.credential-meta {
  color: rgba(230, 236, 255, 0.86);
  font-size: 13px;
  margin: 4px 0 12px;
}

.muted { color: var(--muted); font-size: 14px; margin-top: 12px; }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.toolbar .grow { flex: 1; }
.field-with-action {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.field-with-action input {
  min-width: 0;
}
.field-copy-btn {
  white-space: nowrap;
}
.toolbar-main {
  display: grid;
  grid-template-columns: 1fr 180px 240px auto auto;
  align-items: center;
  gap: 10px;
}
.toolbar-main:has(#owner) {
  grid-template-columns: 1fr 170px 220px 260px auto auto;
}
.toolbar-main .grow { width: 100%; }

.table {
  width: 100%;
  border-collapse: collapse;
}
.table-wrap { overflow-x: auto; }
.table th, .table td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 10px 10px;
  vertical-align: top;
}
.table th { color: rgba(230, 236, 255, 0.92); font-weight: 700; }

.user-picker-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.user-picker-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
}
.user-picker-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
}
.user-picker-main { display: grid; gap: 3px; }
.user-picker-name { font-weight: 700; font-size: 14px; color: rgba(230, 236, 255, 0.95); }
.user-picker-sub { font-size: 12px; color: var(--muted); word-break: break-word; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.dot { width: 10px; height: 10px; border-radius: 999px; }
.user-admin-stack {
  display: grid;
  gap: 12px;
  min-width: 0;
}
.user-admin-stack > .panel {
  min-width: 0;
}
.shared-access-guide h3,
.shared-access-summary h3 {
  margin: 0 0 12px;
}
.shared-access-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.shared-access-step {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}
.shared-access-step .muted {
  margin-top: 6px;
  font-size: 13px;
}
.shared-access-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}
.summary-card {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
}
.summary-card strong {
  font-size: 28px;
  line-height: 1;
}
.summary-card span {
  color: rgba(230, 236, 255, 0.88);
  font-size: 14px;
}
.summary-card-info {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(37, 99, 235, 0.10);
}
.summary-card-warn {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
}
.shared-access-summary-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.shared-access-summary-actions .muted {
  margin: 0;
  max-width: 720px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.status-ok {
  color: #d7ffe4;
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.12);
}
.status-info {
  color: #dbeafe;
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(37, 99, 235, 0.14);
}
.status-warn {
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.12);
}
.shared-access-detail {
  min-width: 0;
  color: rgba(230, 236, 255, 0.84);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.user-admin-table {
  max-height: min(42vh, 420px);
  overflow: auto;
  max-width: 100%;
}
.user-admin-grid {
  min-width: 1080px;
}
.user-admin-grid .user-admin-email,
.user-admin-grid .user-admin-name,
.user-admin-grid .user-admin-detail {
  overflow-wrap: anywhere;
}
.user-admin-grid .user-admin-role select {
  min-width: 0;
}
.user-admin-grid .user-admin-permission .inline-check {
  align-items: flex-start;
}
.user-admin-grid .user-admin-permission .btn,
.user-admin-grid .user-admin-actions .btn {
  width: 100%;
}
.user-admin-grid .user-admin-actions {
  min-width: 132px;
}
.user-admin-grid .user-admin-actions .muted {
  margin: 0;
}
.user-admin-grid .user-admin-actions > * {
  display: block;
  margin: 0 0 8px;
}
.user-admin-grid .user-admin-actions > *:last-child {
  margin-bottom: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  opacity: 0;
  transition: opacity 160ms ease;
}
.modal-backdrop.open { opacity: 1; }
.modal {
  width: min(920px, 100%);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  transform: translateY(10px) scale(0.99);
  transition: transform 160ms ease;
  max-height: calc(100vh - 36px);
  overflow: auto;
  overscroll-behavior: contain;
}
.modal:has(.user-admin-stack) {
  width: min(1180px, calc(100vw - 36px));
  overflow-x: hidden;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal h2 { margin: 0 0 12px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 13px; }

.toasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 10px;
  z-index: 50;
  width: min(420px, calc(100vw - 28px));
}
.toast {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(17, 26, 46, 0.92);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-title { font-weight: 800; margin-bottom: 2px; }
.toast-msg { color: rgba(230, 236, 255, 0.9); word-break: break-word; }
.toast-close {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}
.toast-error { border-color: rgba(239, 68, 68, 0.35); }
.toast-success { border-color: rgba(34, 197, 94, 0.35); }
.toast-info { border-color: rgba(59, 130, 246, 0.35); }

@media (max-width: 1024px) {
  .container { width: min(980px, calc(100% - 28px)); }
  .toolbar-main { grid-template-columns: 1fr 180px 220px auto auto; }
  .toolbar-main:has(#owner) { grid-template-columns: 1fr 160px 200px 220px auto auto; }
}

@media (max-width: 768px) {
  .container { width: calc(100% - 24px); }
  .topbar .container { flex-direction: column; align-items: flex-start; }
  .right { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .toolbar-main { grid-template-columns: 1fr; }
  .toolbar-main .btn { width: 100%; }
  .field-with-action { grid-template-columns: 1fr; }
  .field-copy-btn { width: 100%; }
  .row { flex-direction: column; }
  .shared-access-steps,
  .shared-access-summary { grid-template-columns: 1fr; }
  .shared-access-summary-actions { flex-direction: column; }
  .shared-access-summary-actions .btn { width: 100%; }
  .user-admin-table { max-height: none; }
  .modal { width: 100%; }
  .modal .actions { flex-direction: column; }
  .modal .actions .btn { width: 100%; }
}

@media (max-width: 480px) {
  .panel { padding: 14px; }
  .topbar .container { padding: 12px 0; }
  .brand { font-size: 15px; }
  .user { font-size: 13px; }
  .table th, .table td { padding: 10px 8px; }
  .modal { padding: 14px; border-radius: 14px; }
  .toasts { right: 10px; bottom: 10px; width: min(420px, calc(100vw - 20px)); }
  .toast { padding: 11px; }
  .user-picker-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
