:root {
  --primary: #5b3df0;
  --primary-dark: #4a2fd4;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f4f5fa;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --sidebar-width: 230px;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

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

/* ---------- Auth pages ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #5b3df0, #a855f7);
  padding: 20px;
}
.auth-card {
  background: var(--card-bg);
  padding: 40px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.auth-card h1 { margin-top: 0; font-size: 22px; }
.auth-card .muted { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.auth-logo { display: block; width: 64px; height: 64px; margin: 0 auto 16px; }
.brand-logo { width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0; }

label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; margin-top: 20px; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 6px 12px; font-size: 13px; width: auto; margin-top: 0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary { background: #e5e7eb; color: var(--text); }

.alert { padding: 12px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-info { background: #e0e7ff; color: #3730a3; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  background: #111827;
  color: #d1d5db;
  flex-shrink: 0;
  padding: 20px 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
}
.sidebar .brand { padding: 0 20px 20px; font-weight: 700; font-size: 17px; color: #fff; border-bottom: 1px solid #1f2937; margin-bottom: 12px; display: flex; align-items: center; gap: 10px;}
.sidebar .brand-text small { display:block; font-weight: 400; font-size: 12px; color: #9ca3af; margin-top:2px;}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: #d1d5db;
  font-size: 14px;
  font-weight: 500;
}
.sidebar nav a:hover, .sidebar nav a.active { background: #1f2937; color: #fff; }
.sidebar .logout-link { margin-top: 20px; border-top: 1px solid #1f2937; padding-top: 12px;}

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 26px 32px;
  width: calc(100% - var(--sidebar-width));
}
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap:10px;}
.topbar h1 { font-size: 22px; margin: 0; }
.topbar .who { font-size: 13px; color: var(--muted); }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); padding: 18px 20px; border: 1px solid var(--border); }
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card .label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.panel { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); padding: 22px; margin-bottom: 22px; }
.panel h2 { font-size: 16px; margin: 0 0 16px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafafa; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-muted { background: #f3f4f6; color: #6b7280; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; justify-content: space-between; }
.toolbar .filters { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 8px 10px; font-size: 13px; }

.modal-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 26px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-top: 0; font-size: 18px; }
.modal-close { float: right; cursor: pointer; font-size: 20px; color: var(--muted); background:none;border:none; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

/* ---------- Scanner page ---------- */
.scan-wrap { max-width: 480px; margin: 0 auto; text-align: center; }
#qr-reader { width: 100%; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.scan-result { margin-top: 20px; padding: 20px; border-radius: var(--radius); font-size: 16px; font-weight: 600; }
.scan-result.ok { background: #dcfce7; color: #166534; }
.scan-result.err { background: #fee2e2; color: #991b1b; }
.scan-result .name { font-size: 20px; margin-bottom: 6px; }

/* ---------- ID Cards ---------- */
.id-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.id-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  background: linear-gradient(180deg, #eef2ff, #ffffff);
}
.id-card .org { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--primary); }
.id-card .photo { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; margin: 10px auto; background: #ddd; }
.id-card .name { font-weight: 700; font-size: 15px; margin-top: 4px; }
.id-card .meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.id-card .qr-box { display: flex; justify-content: center; margin: 10px 0; }
.id-card .code { font-family: monospace; font-size: 12px; color: var(--muted); }

@media print {
  .no-print { display: none !important; }
  .main { margin-left: 0; width: 100%; }
  .id-card { break-inside: avoid; }
}

@media (max-width: 768px) {
  .sidebar { position: static; width: 100%; }
  .main { margin-left: 0; width: 100%; }
  .app-shell { flex-direction: column; }
}
