:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand h1 { font-size: 24px; margin: 12px 0 4px; }
.login-brand p { color: var(--text-muted); font-size: 14px; }

.brand-icon {
  width: 56px; height: 56px;
  background: var(--primary);
  color: #fff;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
}
.brand-icon.sm { width: 36px; height: 36px; font-size: 14px; border-radius: 8px; }

.login-card label {
  display: block;
  margin-bottom: 16px;
}
.login-card label span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.login-card input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  transition: border-color 0.15s;
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

.login-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}
.login-hint a { color: var(--primary); text-decoration: none; font-weight: 500; }
.login-hint a:hover { text-decoration: underline; }

.captcha-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.captcha-row input {
  flex: 1;
  min-width: 0;
}
.captcha-image {
  width: 120px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  background: #f5f0ff;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #1e1b4b;
  color: #c7d2fe;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  font-weight: 600;
  color: #fff;
  font-size: 15px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar nav { padding: 12px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #a5b4fc;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.1); color: #fff; }

.nav-group { margin-top: 8px; }
.nav-group-label {
  padding: 8px 14px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6366f1;
}
.nav-sub { padding-left: 20px; font-size: 13px; }

.page-panel.hidden { display: none; }

.page-placeholder {
  padding: 48px 40px;
  text-align: center;
}
.page-placeholder h3 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 8px;
}
.page-placeholder p {
  color: var(--text-muted);
  font-size: 15px;
}

.uid-cell {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

/* ── API Docs ── */
.api-docs-intro {
  padding: 16px 20px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-muted);
}
.api-docs-intro code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.api-group { margin-bottom: 16px; overflow: hidden; }
.api-group-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.15s;
}
.api-group:not(.is-expanded) .api-group-head {
  border-bottom: none;
}
.api-group-head:hover { background: #eef2f7; }
.api-group-chevron {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.api-group-chevron svg { width: 100%; height: 100%; display: block; }
.api-group:not(.is-expanded) .api-group-chevron { transform: rotate(-90deg); }
.api-group-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.api-group-name { font-size: 16px; font-weight: 600; }
.api-group-count {
  font-size: 12px;
  color: var(--text-muted);
}
.api-group-desc {
  font-size: 13px;
  color: var(--text-muted);
}
.api-group .api-list {
  padding: 8px 0;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 2000px;
  opacity: 1;
}
.api-group:not(.is-expanded) .api-list {
  max-height: 0;
  padding: 0;
  opacity: 0;
}
.api-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.api-item:last-child { border-bottom: none; }
.api-item-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}
.method-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.03em;
}
.method-get { background: #ecfdf5; color: #059669; }
.method-post { background: #eef2ff; color: #4f46e5; }
.method-put { background: #fffbeb; color: #d97706; }
.method-patch { background: #f0f9ff; color: #0284c7; }
.method-delete { background: #fef2f2; color: #dc2626; }

.api-path {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  min-width: 200px;
}
.auth-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-muted);
}
.api-desc { font-size: 14px; margin-bottom: 8px; }
.api-meta {
  font-size: 12px;
  margin-top: 6px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.api-meta span {
  flex-shrink: 0;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 56px;
}
.api-meta code {
  background: var(--bg);
  padding: 4px 8px;
  border-radius: 4px;
  word-break: break-all;
  font-size: 12px;
}
.api-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--warning);
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header h2 { font-size: 20px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.admin-email { font-size: 13px; color: var(--text-muted); }

.content { padding: 24px 28px; flex: 1; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Filters ── */
.filter-bar { padding: 20px; margin-bottom: 20px; }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}
.filter-row label { flex: 1; min-width: 160px; }
.filter-row label span {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.filter-row input,
.filter-row select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
}
.filter-row input:focus,
.filter-row select:focus {
  outline: none;
  border-color: var(--primary);
}
.filter-actions { display: flex; gap: 8px; padding-bottom: 1px; }

.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}
.tab-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
}
.tj-tab-panel.hidden { display: none; }

/* ── Table ── */
.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg); }
th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
td.empty { text-align: center; color: var(--text-muted); padding: 40px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--danger-bg); color: var(--danger); }
.badge-admin { background: var(--primary-light); color: var(--primary); }
.badge-normal { background: #f1f5f9; color: #475569; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.page-btns { display: flex; gap: 8px; }

/* ── Modal ── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; }
.modal-close {
  background: none; border: none; font-size: 24px;
  color: var(--text-muted); cursor: pointer; line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }

.user-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 20px;
  font-weight: 500;
}
.user-status-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.roles-list { margin-bottom: 24px; }
.role-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.role-item-info { flex: 1; }
.role-item-site { font-weight: 500; font-size: 14px; }
.role-item-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.role-item-actions { display: flex; gap: 6px; }
.role-item.empty-role {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  justify-content: center;
}

.role-form label {
  display: block;
  margin-bottom: 14px;
}
.role-form label span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.role-form input,
.role-form select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.role-form small { display: block; margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.form-actions { margin-top: 8px; }

/* ── Switch ── */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #cbd5e1; border-radius: 22px; transition: 0.2s;
}
.slider:before {
  content: ''; position: absolute; height: 16px; width: 16px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: #1e293b;
  color: #fff;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: slideIn 0.25s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@keyframes slideIn {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .filter-row label { min-width: 100%; }
}
