:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.wrap-sm { max-width: 440px; margin: 0 auto; padding: 2rem 1.25rem; }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav-brand span { color: var(--primary); }
.nav-links { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: center; }
.nav-links a { color: var(--muted); font-size: 0.95rem; }
.nav-links a:hover { color: var(--text); }

h1 { font-size: 1.5rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.stat .n { font-size: 1.5rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 0.85rem; }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="file"],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  margin-bottom: 0.9rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}
textarea { min-height: 80px; resize: vertical; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff !important;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none !important;
}
.btn:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); }
.btn-block { width: 100%; text-align: center; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }

.alert {
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}
.alert-error { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); color: #fecaca; }
.alert-success { background: rgba(34, 197, 94, 0.12); border: 1px solid var(--success); color: #bbf7d0; }
.alert-warn { background: rgba(245, 158, 11, 0.12); border: 1px solid var(--warning); color: #fde68a; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: rgba(255,255,255,0.02); }
.mono { font-family: ui-monospace, Consolas, monospace; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
}
.badge-active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-inactive { background: rgba(139, 155, 180, 0.15); color: var(--muted); }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}
.filters .field { margin: 0; }
.filters label { margin-bottom: 0.25rem; }
.filters input, .filters select { margin-bottom: 0; }

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.pagination a, .pagination span {
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }

.auth-box { margin-top: 10vh; }
.auth-box .logo {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}
.auth-box .logo span { color: var(--primary); }

.qr-wrap {
  text-align: center;
  margin: 1rem 0;
  padding: 1rem;
  background: #fff;
  border-radius: 12px;
  display: inline-block;
}
.qr-wrap img { display: block; width: 200px; height: 200px; }
.secret-box {
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.08em;
  background: var(--bg);
  border: 1px dashed var(--border);
  padding: 0.75rem;
  border-radius: 8px;
  word-break: break-all;
  text-align: center;
  margin: 0.75rem 0 1rem;
}

.recovery-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-family: ui-monospace, Consolas, monospace;
  margin: 1rem 0;
}
.recovery-codes code {
  background: var(--bg);
  padding: 0.5rem;
  border-radius: 6px;
  text-align: center;
  border: 1px solid var(--border);
}

.public-msg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}
.public-msg h1 { font-size: 1.35rem; }
.public-msg p { color: var(--muted); }

@media (max-width: 600px) {
  .truncate { max-width: 120px; }
  .recovery-codes { grid-template-columns: 1fr; }
}
