:root {
  --bg: #f5f6fb;
  --panel: #ffffff;
  --text: #1f2333;
  --muted: #6b7280;
  --primary: #6c5ce7;
  --primary-dark: #574bcf;
  --border: #e5e7f0;
  --danger: #e74c3c;
  --success: #27ae60;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}

.topnav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 20px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px;
}

.flash-stack { margin-bottom: 18px; }
.flash {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}
.flash-success { background: #e8f8ef; color: #1e7e42; border: 1px solid #bfe9cf; }
.flash-error { background: #fdeceb; color: #b3271b; border: 1px solid #f5c6c1; }
.flash-info { background: #eef1ff; color: #3a3fb0; border: 1px solid #d6dbff; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: center;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .grid-2, .stats-row, .code-detail-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
}

.panel h2 { margin-top: 0; font-size: 17px; }

.form-stack {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.form-stack label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 12px;
  margin-bottom: 6px;
}
.form-stack label:first-child { margin-top: 0; }

.form-stack input[type="text"],
.form-stack input[type="url"],
.form-stack input[type="password"],
.form-stack select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fbfbfe;
  color: var(--text);
}

.form-stack input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  background: #fbfbfe;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

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

.project-list { margin-top: 28px; }
.project-list h2 { margin-bottom: 12px; }

.project-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  display: block;
}
.project-card h3 { margin: 0 0 6px; }
.project-card-meta {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 6px solid var(--primary);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.project-header h1 { margin: 0 0 6px; }

.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}

.codes-table-wrap { margin-top: 26px; }
table.codes-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.codes-table th, table.codes-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.codes-table th { background: #fafafe; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
table.codes-table tr:last-child td { border-bottom: none; }
table.codes-table a { color: var(--primary); text-decoration: none; font-weight: 600; }

.qr-thumb { width: 44px; height: 44px; border-radius: 6px; border: 1px solid var(--border); }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-on { background: #e8f8ef; color: #1e7e42; }
.badge-off { background: #f1f1f4; color: #6b7280; }
.badge-dynamic { background: #ede9fe; color: #6d28d9; }
.badge-static { background: #fef3c7; color: #92400e; }

/* Radio option cards for QR type */
.qr-type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.qr-type-card {
  position: relative;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  background: #fafafa;
  transition: all 0.15s ease;
}
.qr-type-card:hover {
  background: #f4f4f7;
  border-color: #cbd5e1;
}
.qr-type-card input[type="radio"] {
  position: absolute;
  top: 12px;
  right: 12px;
  margin: 0;
}
.qr-type-card.selected,
.qr-type-card:has(input[type="radio"]:checked) {
  border-color: var(--primary);
  background: #fbfbfe;
  box-shadow: 0 0 0 1px var(--primary);
}
.qr-type-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qr-type-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
  margin: 0;
}

.code-detail-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}

.qr-panel { text-align: center; }
.qr-large { width: 100%; max-width: 280px; border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: #fff; }
.qr-actions { margin-top: 14px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.qr-actions .btn { margin-top: 0; }

.short-url-box { margin-top: 18px; text-align: left; }
.short-url-box label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 6px; color: var(--muted); }
.short-url-box input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: #fafafe;
}

.divider { height: 1px; background: var(--border); margin: 22px 0; border: none; }

.muted { color: var(--muted); font-size: 14px; }

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 30, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  width: 92%;
  max-width: 420px;
}
.modal-box h3 { margin-top: 0; }
.modal-close-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.danger-zone {
  margin-top: 26px;
  border: 1px solid #f5c6c1;
  background: #fff7f6;
  border-radius: var(--radius);
  padding: 16px;
}
.danger-zone h3 { margin-top: 0; color: var(--danger); font-size: 14px; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

/* ---- aliases / extra classes actually used in templates ---- */

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 10px;
}

.project-card-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.project-card-desc { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

table.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  margin-top: 10px;
}
table.table th, table.table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
table.table tr:last-child td { border-bottom: none; }
table.table a { color: var(--primary); text-decoration: none; font-weight: 600; }
/* Jinja templates use plain class="table" (no .codes-table prefix) */
.table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table tr:last-child td { border-bottom: none; }
.table a { color: var(--primary); text-decoration: none; font-weight: 600; }

.mini-qr { width: 40px; height: 40px; border-radius: 6px; border: 1px solid var(--border); }

.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 14px;
  font-weight: 500;
}
.checkbox-row input { width: auto; }

/* modal aliases matching template markup (.modal instead of .modal-box, .modal-actions instead of .modal-close-row) */
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  width: 92%;
  max-width: 420px;
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
