:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273548;
  --border: #334155;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #818cf8;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

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

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

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 10;
}

.sidebar-logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 32px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo span { color: var(--accent); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  transition: all .15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.main {
  margin-left: 240px;
  flex: 1;
  padding: 32px;
  max-width: 1200px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 32px; font-weight: 700; margin-top: 4px; }
.stat-value.accent { color: var(--accent-light); }
.stat-value.green { color: var(--green); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); text-decoration: none; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; text-decoration: none; color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 13px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border .15s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.toggle-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="checkbox"].toggle {
  width: 40px;
  height: 22px;
  appearance: none;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  position: relative;
  transition: background .2s;
}
input[type="checkbox"].toggle::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: left .2s;
}
input[type="checkbox"].toggle:checked { background: var(--accent); }
input[type="checkbox"].toggle:checked::after { left: 21px; }

/* QR code list */
.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.qr-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color .15s;
}
.qr-card:hover { border-color: var(--accent); }

.qr-card-header { display: flex; align-items: flex-start; justify-content: space-between; }
.qr-card-name { font-weight: 600; font-size: 15px; }
.qr-card-url { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  gap: 4px;
}
.badge-green { background: rgba(34,197,94,.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,.15); color: var(--red); }
.badge-purple { background: rgba(99,102,241,.15); color: var(--accent-light); }

.qr-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qr-scan-count { font-size: 22px; font-weight: 700; color: var(--accent-light); }
.qr-scan-label { font-size: 12px; color: var(--text-muted); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 500; border-bottom: 1px solid var(--border); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

/* Auth pages */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  box-shadow: var(--shadow);
}

.auth-logo {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
}

.auth-logo span { color: var(--accent); }
.auth-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

.error-box {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 16px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-title { font-size: 22px; font-weight: 700; }
.page-sub { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

/* Chart container */
.chart-wrap { height: 200px; position: relative; }

/* Divider */
.divider { height: 1px; background: var(--border); margin: 24px 0; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

/* QR image */
.qr-img-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.qr-img-wrap img {
  width: 180px;
  height: 180px;
  border-radius: 8px;
  background: white;
  padding: 8px;
}

/* Rule list */
.rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 12px;
}
.rule-info { flex: 1; min-width: 0; }
.rule-title { font-size: 13px; font-weight: 500; }
.rule-url { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
