/* === tokens === */
:root {
  --bg: #1e1f22;
  --bg-elev: #2b2d31;
  --bg-elev-2: #313338;
  --border: #1a1b1e;
  --border-soft: #3f4147;
  --text: #f2f3f5;
  --text-dim: #b5bac1;
  --text-mute: #80848e;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --success: #23a55a;
  --danger: #f23f43;
  --danger-hover: #d83a3e;
  --warn: #f0b232;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --transition: 120ms ease;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, "Cascadia Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f6;
    --bg-elev: #ffffff;
    --bg-elev-2: #f9fafb;
    --border: #e5e7eb;
    --border-soft: #d1d5db;
    --text: #111827;
    --text-dim: #4b5563;
    --text-mute: #6b7280;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  }
}

/* === base === */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--text-dim); }
.muted.small { color: var(--text-mute); font-size: 0.85rem; }
.small { font-size: 0.85rem; }
.mono { font-family: var(--font-mono); }
a.link { color: var(--accent); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* === layout === */
.topbar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; color: var(--text); text-decoration: none;
}
.brand-mark {
  width: 26px; height: 26px;
  background: var(--accent);
  border-radius: 8px;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 6px;
  background:
    linear-gradient(to bottom, #fff 0 2px, transparent 2px 5px, #fff 5px 7px, transparent 7px 10px, #fff 10px 12px);
}
.topbar-nav { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--bg-elev);
  border-radius: 999px;
  font-size: 0.85rem;
}
.user-chip img { border-radius: 50%; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  display: flex; flex-direction: column;
  gap: 20px;
}
.centered { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.centered-block { display: flex; justify-content: center; padding-top: 48px; }

.page-head {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  flex-wrap: wrap;
}
.role-head .role-head-meta { display: flex; align-items: center; gap: 16px; }
.role-head .role-logos { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.role-head .role-logos img {
  height: auto;
  max-height: 56px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* === cards === */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.inline { display: inline; }
.inline-flash { padding: 8px 12px; }
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  justify-content: space-between;
}
.search-wrap { flex: 1; min-width: 220px; }
.search-wrap input { width: 100%; }
.sort-select { width: auto; min-width: 140px; }

/* === audit log === */
.audit-list .audit-row {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.audit-main {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.audit-ts { white-space: nowrap; }
.audit-action { font-size: 0.65rem; }
.audit-role { text-decoration: none; }
.audit-role:hover { text-decoration: underline; }
.audit-details pre {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 4px 0 0;
  overflow: auto;
  max-height: 240px;
}

/* === auth === */
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-elev);
  padding: 32px;
  border-radius: var(--radius-lg);
  text-align: center;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.auth-logo {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: 14px;
  margin: 0 auto;
  position: relative;
}
.auth-logo::after {
  content: "";
  position: absolute; inset: 14px;
  background:
    linear-gradient(to bottom, #fff 0 3px, transparent 3px 8px, #fff 8px 11px, transparent 11px 16px, #fff 16px 19px);
  border-radius: 2px;
}

/* === forms === */
input:not([type]), input[type="text"], input[type="search"], input[type="url"],
input[type="email"], input[type="number"], input[type="tel"], input[type="password"],
input[type="file"], select, textarea {
  width: 100%;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:not([type]):focus, input[type="text"]:focus, input[type="search"]:focus,
input[type="url"]:focus, input[type="email"]:focus, input[type="number"]:focus,
input[type="tel"]:focus, input[type="password"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
input[readonly] { background: var(--bg); color: var(--text-dim); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
label > span:first-child { color: var(--text-dim); font-weight: 500; }
.checkbox-inline { flex-direction: row; align-items: center; gap: 6px; cursor: pointer; }
.checkbox-inline input { width: auto; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-family: var(--font-mono); font-size: 0.85rem; }

/* === buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: color-mix(in srgb, var(--bg-elev-2) 70%, var(--text) 8%); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; border-color: var(--border-soft); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-mute); background: var(--bg-elev-2); }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-lg { padding: 12px 20px; font-size: 1rem; }

.badge {
  display: inline-block;
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
  margin-left: 4px;
}
.badge-warn {
  background: color-mix(in srgb, var(--warn) 22%, transparent);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 50%, transparent);
}

/* === flash === */
.flash {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  border: 1px solid var(--border-soft);
  background: var(--bg-elev);
}
.flash-success { border-color: color-mix(in srgb, var(--success) 50%, transparent); background: color-mix(in srgb, var(--success) 12%, var(--bg-elev)); }
.flash-error { border-color: color-mix(in srgb, var(--danger) 50%, transparent); background: color-mix(in srgb, var(--danger) 12%, var(--bg-elev)); }
.flash-info { border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-elev)); }

/* === lists === */
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  transition: background var(--transition);
}
.list-row:hover { background: color-mix(in srgb, var(--bg-elev-2) 70%, var(--text) 6%); }
.list-row-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.list-row-main strong { font-weight: 600; }
.list-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.members .list-row { padding: 8px 12px; }
.member-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: 0 0 32px; }

/* === dashboard cards === */
.grid.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.role-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-decoration: none; color: var(--text);
  padding: 14px;
  background: var(--bg-elev);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: transform var(--transition), border-color var(--transition);
}
.role-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.role-logo {
  width: 100%;
  height: auto;
  max-height: 80px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  object-position: left center;
}
.role-logo.placeholder {
  width: 100%;
  height: 80px;
  display: grid; place-items: center;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 700;
  font-size: 1.5rem;
}
.role-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.role-meta h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === empty state === */
.empty {
  text-align: center;
  padding: 48px 20px;
  background: var(--bg-elev);
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius-lg);
  color: var(--text-dim);
}

/* === logo upload === */
.logo-form { display: flex; flex-direction: column; gap: 16px; }
.logo-slots { display: grid; grid-template-columns: 1fr; gap: 16px; }
.logo-slot { gap: 8px; }
.logo-preview {
  width: 100%;
  min-height: 80px;
  padding: 8px;
  background: var(--bg-elev-2);
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius);
  display: grid; place-items: center;
  overflow: hidden;
}
.logo-preview img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
}

@media (max-width: 520px) {
  .container { padding: 16px; }
  .topbar { padding: 12px 16px; }
  h1 { font-size: 1.35rem; }
}

/* === modal === */
.modal {
  border: none;
  background: transparent;
  padding: 0;
  color: var(--text);
  width: min(440px, 92vw);
  max-height: 90vh;
}
.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; }
.modal-body { max-height: 60vh; overflow: auto; }

#search-results, #members-list {
  max-height: 60vh; overflow: auto;
  scrollbar-width: thin;
}
#search-results::-webkit-scrollbar, #members-list::-webkit-scrollbar { width: 6px; }
#search-results::-webkit-scrollbar-thumb, #members-list::-webkit-scrollbar-thumb {
  background: var(--border-soft); border-radius: 3px;
}

/* loading dot */
.dot-loader::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-mute);
  margin-left: 6px;
  animation: pulse 1s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* fade-in for newly added rows */
.list-row.fade-in {
  animation: fadeIn 200ms ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
