:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182032;
  --border: #253047;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }

/* Toast */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  max-width: 360px;
  animation: fadeIn 0.16s ease-out;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #17233b 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.brand-lockup h1 { margin: 0; font-size: 20px; }
.brand-lockup p { margin: 2px 0 0; font-size: 12.5px; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark.sm { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }

/* App Shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-title { font-weight: 700; font-size: 16px; }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(16, 185, 129, 0.7); }
.dot.err { background: var(--red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.7); }

.nav-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}
.nav-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 14px 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.metric-label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.metric-val { font-size: 21px; font-weight: 700; font-family: var(--mono); }
.accent-green { color: var(--green); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.panel-header h2 { margin: 0; font-size: 17px; }
.panel-header p { margin: 3px 0 0; }
.panel-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 660px; }
th, td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-accent { background: rgba(59, 130, 246, 0.16); color: #93c5fd; }
.badge-green { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
.badge-amber { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }
.badge-red { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.badge-muted { background: rgba(148, 163, 184, 0.14); color: var(--muted); }
.badge-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #222d45; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-xs { padding: 2px 8px; font-size: 11.5px; border-radius: 6px; }
.btn-full { width: 100%; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13.5px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.input-sm { width: auto; padding: 6px 10px; font-size: 13px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: #fca5a5; font-size: 12.5px; background: rgba(239, 68, 68, 0.12); padding: 8px 10px; border-radius: 8px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.check-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.service-checklist {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Member Self-Service */
.perm-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.perm-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.perm-card .label { font-size: 12px; color: var(--muted); }
.perm-card .val { font-size: 15px; font-weight: 600; margin-top: 4px; }
.sub-heading { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.service-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.service-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12.5px;
  cursor: pointer;
}
.service-chip:hover { border-color: var(--primary); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.btn-icon:hover { color: var(--text); }
.modal-body { padding: 18px 20px 22px; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 8px;
  background: #fff;
  padding: 6px;
}
.copy-box {
  display: flex;
  gap: 8px;
  width: 100%;
}
.copy-box input { font-family: var(--mono); font-size: 12px; }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
  .container { padding: 14px 12px 40px; }
}
