:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #16a34a;
  --brand-dark: #15803d;
  --danger: #dc2626;
  --sidebar: #0f172a;
  --sidebar-ink: #cbd5e1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

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

.sidebar {
  width: 220px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand.center { justify-content: center; padding-bottom: 16px; }
.brand strong { display: block; color: #fff; font-size: 15px; }
.brand small { color: #94a3b8; font-size: 11px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand); box-shadow: 0 0 0 4px rgba(22,163,74,.2);
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: var(--sidebar-ink);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }

.logout { border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; }
.logout .user { font-size: 12px; color: #94a3b8; margin-bottom: 8px; padding: 0 4px; }
.logout button {
  width: 100%; padding: 9px; border: 1px solid rgba(255,255,255,.15);
  background: transparent; color: var(--sidebar-ink); border-radius: 8px; cursor: pointer;
}
.logout button:hover { background: rgba(255,255,255,.06); color: #fff; }

.content { flex: 1; padding: 28px 32px; max-width: 1000px; }

/* ---------- Headings ---------- */
.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- Cards ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.card h2 { margin: 0 0 16px; font-size: 15px; }
.card.no-pad { padding: 0; overflow: hidden; }
.center-card { display: flex; flex-direction: column; align-items: center; text-align: center; }

/* ---------- Status ---------- */
.status-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: 5px 12px; border-radius: 999px;
  font-weight: 600; font-size: 12px; background: #eef2f7; color: var(--ink);
}
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef9c3; color: #854d0e; }
.badge.err { background: #fee2e2; color: #991b1b; }
.badge.muted { background: #e5e7eb; color: #4b5563; }
.badge.subtle { background: #f1f5f9; color: #64748b; font-weight: 500; }

.meta { display: grid; gap: 10px; margin: 0 0 18px; }
.meta div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.meta dt { color: var(--muted); margin: 0; }
.meta dd { margin: 0; font-weight: 600; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- QR ---------- */
.qr-box {
  width: 100%; min-height: 240px; display: flex; align-items: center; justify-content: center;
  background: #fafafa; border: 1px dashed var(--line); border-radius: 10px; margin-bottom: 12px; padding: 16px;
}
.qr-box img { width: 240px; height: 240px; image-rendering: pixelated; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; font-size: 13px;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.btn.subtle { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.full { width: 100%; }

/* ---------- Alerts ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #f1f5f9; }
.alert.ok { background: #dcfce7; color: #166534; }
.alert.error { background: #fee2e2; color: #991b1b; }

/* ---------- Forms ---------- */
.form label, .login-card label { display: block; margin-bottom: 16px; font-weight: 600; }
.form input, .form textarea, .login-card input {
  width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; font-weight: 400; background: #fff;
}
.form textarea { resize: vertical; }
.form small { font-weight: 400; margin-top: 4px; display: block; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.toolbar input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; min-width: 220px; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.table th { background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.nowrap { white-space: nowrap; }
.msg { max-width: 420px; word-break: break-word; }
.tag { padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.tag.in { background: #e0f2fe; color: #075985; }
.tag.out { background: #dcfce7; color: #166534; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-card h1 { text-align: center; font-size: 18px; margin: 0 0 20px; }
.login-card button { margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; }
  .logout { border: none; padding-top: 0; display: flex; align-items: center; gap: 10px; }
  .logout .user { margin: 0; }
  .logout button { width: auto; }
  .content { padding: 20px; }
  .grid { grid-template-columns: 1fr; }
}
