:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222d;
  --border: #2a2f3d;
  --text: #e8e9ed;
  --text-dim: #9599a8;
  --accent: #4f7cff;
  --accent-hover: #6a92ff;
  --green: #2ecc71;
  --red: #e74c3c;
  --yellow: #f1c40f;
  --radius: 10px;
  font-size: 15px;
}

* { 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);
  line-height: 1.5;
  overflow-x: hidden;
}

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

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.container-narrow { max-width: 440px; margin: 0 auto; padding: 24px; }
.container, .container-narrow { width: 100%; box-sizing: border-box; }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.card + .card { margin-top: 20px; }

.table-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.table-scroll table { border: none; border-radius: 0; margin: 0; }
.table-scroll table th:first-child, .table-scroll table td:first-child { padding-left: 12px; }
.table-scroll table th:last-child, .table-scroll table td:last-child { padding-right: 12px; }

h1, h2, h3 { font-weight: 700; margin: 0 0 16px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p.muted, span.muted { color: var(--text-dim); }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}

input[type=text], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  text-align: center;
}
.btn:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #262b38; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #ff6b5b; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert-error { background: rgba(231,76,60,0.15); border: 1px solid rgba(231,76,60,0.4); color: #ff8a7a; }
.alert-success { background: rgba(46,204,113,0.15); border: 1px solid rgba(46,204,113,0.4); color: #6ee59a; }


th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-active { background: rgba(46,204,113,0.18); color: #6ee59a; }
.badge-inactive { background: rgba(231,76,60,0.18); color: #ff8a7a; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel) 0%, #14161f 100%);
  box-shadow: 0 1px 0 rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.topbar .brand .brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff;
  flex-shrink: 0;
}
.topbar .brand .brand-icon svg { width: 18px; height: 18px; display: block; }

.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: 0;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.86rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.topbar nav a svg,
.topbar svg {
  width: 16px;
  height: 16px;
  max-width: 16px;
  max-height: 16px;
  flex-shrink: 0;
  display: block;
}
/* Global safety net: any inline SVG icon rendered via the icon() helper
   must never exceed its intended box, regardless of ambient font-size. */
svg { max-width: 100%; }
.topbar nav a:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.topbar nav a.active { color: #fff; background: var(--accent); }
.topbar nav a.logout-link {
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  border-radius: 0 8px 8px 0;
  color: var(--text-dim);
}
.topbar nav a.logout-link:hover { color: #ff8a7a; background: rgba(231,76,60,0.1); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-box .value { font-size: 1.8rem; font-weight: 800; }
.stat-box .label { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }

.toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    margin-bottom: 18px;
}
.toolbar form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.toolbar input,
.toolbar select,
.toolbar button {
    width: 100%;
}
.toolbar input, .toolbar select { margin: 0; width: auto; }

.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.small { font-size: 0.8rem; }
.text-right { text-align: right; }
.qr-thumb { width: 40px; height: 40px; border-radius: 6px; background: #fff; padding: 2px; }
.pagination { display: flex; gap: 6px; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); font-size: 0.85rem; }
.pagination .current { background: var(--accent); border-color: var(--accent); }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  min-width: 0;
}
.dashboard-grid .card { margin-top: 0; min-width: 0; }
