/* === text-relay-server admin · Tabler-inspired UI === */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e5e9f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --primary: #206bc4;
  --primary-hover: #1a5aa8;
  --primary-soft: #e7f0fa;
  --success: #2fb344;
  --success-soft: #e6f8e9;
  --warn: #f59f00;
  --warn-soft: #fff4dc;
  --danger: #d63939;
  --danger-soft: #fceaea;
  --info: #4299e1;
  --info-soft: #e6f1fb;
  --purple: #ae3ec9;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 2px 6px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.10);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-w: 248px;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273349;
  --surface-3: #334155;
  --border: #334155;
  --border-strong: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --primary: #4f8cff;
  --primary-hover: #6699ff;
  --primary-soft: rgba(79, 140, 255, 0.14);
  --success: #2fb344;
  --success-soft: rgba(47, 179, 68, 0.16);
  --warn: #f5a623;
  --warn-soft: rgba(245, 166, 35, 0.16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.16);
  --purple: #c084fc;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.loading { padding: 80px; text-align: center; color: var(--text-muted); font-size: 14px; }
.empty { padding: 48px 16px; text-align: center; color: var(--text-faint); }
/* === Layout === */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar .brand .logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #4d8cff);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.sidebar .brand .logo svg { width: 18px; height: 18px; }
.sidebar .brand .title { font-size: 15px; font-weight: 600; letter-spacing: 0.2px; }
.sidebar .brand .sub { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13.5px;
  transition: background-color 0.12s ease, color 0.12s ease;
  user-select: none;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav-section {
  margin-top: 12px;
  padding: 8px 12px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
}

.user-block {
  margin-top: auto;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 12px;
}
.user-block .user-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.user-block .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #4f8cff, #ae3ec9);
  color: #fff; display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
}
.user-block .name { font-weight: 500; color: var(--text); }
.user-block .role { color: var(--text-faint); font-size: 11px; }

/* === Main / topbar === */
.main { padding: 0; overflow: visible; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .page-title { font-size: 16px; font-weight: 600; }
.topbar .breadcrumbs { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.topbar .spacer { flex: 1; }
.topbar .icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: grid; place-items: center;
  transition: 0.12s ease;
}
.topbar .icon-btn:hover { background: var(--surface-2); color: var(--text); }
.topbar .icon-btn svg { width: 16px; height: 16px; }
.page-body { padding: 24px 28px 64px; max-width: 1480px; }

/* === Cards === */
.card, .section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 18px;
}
.card-header, .section h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-header .actions { margin-left: auto; display: flex; gap: 8px; }
.card-header svg { width: 16px; height: 16px; color: var(--text-muted); }
.section h3 {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 10px;
}
/* === Stat cards === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.stat-card .stat-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.4px;
}
.stat-card .stat-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
}
.stat-card .stat-icon svg { width: 16px; height: 16px; }
.stat-card .stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-card .stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat-card .stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-card .stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-card .num {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1.1;
}
.stat-card .label { color: var(--text-muted); font-size: 12.5px; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  transition: 0.12s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(0.95); }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-warn:hover:not(:disabled) { filter: brightness(0.95); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.95); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-quiet { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; }
/* === Inputs === */
.input, input[type=text], input[type=password], input[type=search], input[type=number],
input[type=datetime-local], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 11px;
  font-size: 13px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  outline: none;
  min-width: 0;
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type=text].full, input[type=password].full {
  width: 100%;
  margin-bottom: 10px;
}
textarea {
  width: 100%;
  min-height: 160px;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  resize: vertical;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  appearance: none;
}

/* === Toolbar === */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar .input, .toolbar select { min-width: 130px; height: 36px; }
.toolbar input[type=search], .toolbar input[type=text], .toolbar input[type=number] { height: 36px; }
.toolbar .search-wrap { position: relative; flex: 1 1 240px; min-width: 220px; max-width: 340px; }
.toolbar .search-wrap input { width: 100%; padding-left: 32px; height: 36px; }
.toolbar .search-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--text-faint); pointer-events: none;
}
.toolbar .spacer { flex: 1; }

/* === Tables === */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

/* === Badges === */
.badge, .tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok, .tag.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.error, .tag.error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.muted, .tag.unchecked { background: var(--surface-2); color: var(--text-muted); }
.badge.expired, .tag.expired { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.disabled, .tag.disabled { background: rgba(174, 62, 201, 0.14); color: var(--purple); border-color: transparent; }
.badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  display: inline-block;
}
/* === Misc text utils === */
.mono {
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  word-break: break-all;
}
.dim { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
}
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.flex-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* === Bars (mini chart) === */
.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 130px;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}
.bar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #4d8cff);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.bar-fill.error { background: linear-gradient(90deg, var(--danger), #ff7373); }
.bar { display: inline-block; height: 8px; background: var(--primary); border-radius: 4px; vertical-align: middle; }
.bar.error { background: var(--danger); }

/* === Modal === */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 50px 16px;
  z-index: 1000;
  overflow: auto;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 480px;
  max-width: 720px;
  width: 100%;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.modal-header h2 svg { width: 18px; height: 18px; flex-shrink: 0; }
h2 svg, h3 svg { width: 16px; height: 16px; flex-shrink: 0; }
.modal h3 {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 10px;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: 0.12s ease;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* === Toasts === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 11px 16px;
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  font-size: 13px;
  animation: toastIn 0.18s ease;
  pointer-events: auto;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.info { border-left-color: var(--info); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* === Login / setup card === */
.center-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface-2) 100%);
}
.center-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  margin: 0;
}
.center-card .brand-logo {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #4d8cff);
  color: #fff;
  display: grid; place-items: center;
  margin: 0 auto 14px;
  box-shadow: var(--shadow);
}
.center-card .brand-logo svg { width: 24px; height: 24px; }
.center-card h2 {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin: 0 0 6px;
}
.center-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 22px;
}
.center-card .form-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
}

/* === Pagination & misc === */
.checkbox-cell { width: 36px; }
.checkbox-cell input[type=checkbox],
.row-sel { cursor: pointer; }
.row-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.batch-ops-bar {
  background: var(--primary-soft);
  border: 1px solid transparent;
  padding: 10px 14px;
  border-radius: var(--radius);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
  color: var(--primary);
  font-size: 13px;
}
.batch-ops-bar .btn { background: var(--surface); color: var(--text); }
.batch-ops-bar input { background: var(--surface); }
.qr-img {
  background: #fff;
  padding: 10px;
  border-radius: var(--radius);
  max-width: 280px;
  border: 1px solid var(--border);
}
.list-wrap {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* === Responsive === */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar, .page-body { padding-left: 16px; padding-right: 16px; }
  .modal { min-width: 0; }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
