:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-dark: #3730a3;
  --ok: #059669;
  --warn: #d97706;
  --bad: #e11d48;
  --sidebar: #0f172a;
  --sidebar-2: #1e293b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --focus: 0 0 0 3px rgba(79, 70, 229, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0 0 0.5rem; letter-spacing: -0.02em; }
p { margin: 0 0 1rem; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--sidebar) 0%, #111827 100%);
  color: #e2e8f0;
  padding: 1.25rem 0.9rem;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.7rem 1.2rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}
.brand:hover { text-decoration: none; color: #fff; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--brand); display: grid; place-items: center;
  font-size: 0.85rem; font-weight: 800;
}
.nav-section { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: #94a3b8; padding: 0.8rem 0.8rem 0.4rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.62rem 0.8rem; border-radius: 10px; color: #cbd5e1;
  text-decoration: none; font-size: 0.95rem;
}
.nav-link:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav-link.is-active { background: #312e81; color: #fff; }
.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; background: rgba(255,255,255,0.9);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.page { padding: 1.5rem; }
.menu-toggle { display: none; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { padding: 1.1rem 1.2rem; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; }

.btn, button.btn, input[type=submit].btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 0; border-radius: 10px; padding: 0.6rem 1rem; font-weight: 600;
  cursor: pointer; font-size: 0.95rem; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:focus, .form-input:focus, select:focus, textarea:focus { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ghost { background: #eef2ff; color: var(--brand-dark); }
.btn-outline { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.form-label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.9rem; }
.form-input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 0.65rem 0.8rem; background: #fff; font: inherit; color: inherit;
}
.form-help { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }
.form-row { margin-bottom: 1rem; }
.check { display: flex; gap: 0.5rem; align-items: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--line); font-size: 0.92rem; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.badge, .badge-active, .badge-inactive, .badge-disabled, .badge-admin, .badge-user, .badge-viewer {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 0.15rem 0.6rem; font-size: 0.75rem; font-weight: 700;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fef3c7; color: #92400e; }
.badge-disabled { background: #ffe4e6; color: #9f1239; }
.badge-admin { background: #e0e7ff; color: #3730a3; }
.badge-user { background: #dbeafe; color: #1e3a8a; }
.badge-viewer { background: #f1f5f9; color: #334155; }

.alert { padding: 0.85rem 1rem; border-radius: 12px; margin-bottom: 1rem; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #ffe4e6; color: #9f1239; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #dbeafe; color: #1e3a8a; }

.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters .form-input, .filters select { width: auto; min-width: 140px; }
.pagination { display: flex; gap: 0.4rem; align-items: center; margin-top: 1rem; }
.pagination a, .pagination span, .pagination button { padding: 0.35rem 0.65rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; }
.pagination .is-current { background: var(--brand); color: #fff; border-color: var(--brand); }
.nav-logout { width: 100%; background: transparent; border: 0; cursor: pointer; text-align: left; font: inherit; }
.sort-link { background: none; border: 0; padding: 0; color: inherit; font: inherit; font-weight: 600; cursor: pointer; text-transform: inherit; letter-spacing: inherit; }
.sort-link:hover { color: var(--brand); }
form.inline-form { display: inline; }

.public-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(circle at top, #e0e7ff, #f8fafc 45%);
}
.public-card { width: min(520px, 100%); }
.logo-row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1rem; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.chart-bar { flex: 1; background: #818cf8; border-radius: 4px 4px 0 0; min-height: 2px; }
.copy-row { display: flex; gap: 0.5rem; }
.copy-row .form-input { flex: 1; }
.toolbar { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.empty { text-align: center; padding: 2rem; color: var(--muted); }
.user-chip { color: #94a3b8; font-size: 0.85rem; }
.danger-text { color: var(--bad); word-break: break-all; }
.url { word-break: break-all; }
.print-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.print-item { border: 1px solid #cbd5e1; padding: 12px; text-align: center; break-inside: avoid; }
.print-item img, .print-item svg { width: 140px; height: 140px; display: block; margin: 0 auto 0.4rem; }
.qr-preview svg { width: 220px; height: 220px; display: block; }

@media (max-width: 960px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-105%); z-index: 40; transition: transform .2s ease; }
  .sidebar.is-open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .page, .topbar { padding-left: 1rem; padding-right: 1rem; }
}
@media (max-width: 640px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .print-grid { grid-template-columns: repeat(2, 1fr); }
}
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}
