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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  padding: 0.9rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(30,58,138,0.35);
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  color: white;
}
.header-logo svg { width: 30px; height: 30px; flex-shrink: 0; }
.header-nav { display: flex; gap: 0.25rem; }
.header-nav a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.45rem 0.9rem;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
}
.header-nav a:hover { background: rgba(255,255,255,0.18); color: white; }
.header-nav a.active { background: rgba(255,255,255,0.22); color: white; }

/* ── Page wrapper ────────────────────────────────────────────────────────── */
.page { max-width: 1100px; margin: 2rem auto; padding: 0 1rem; }
.page-sm { max-width: 720px; margin: 2rem auto; padding: 0 1rem; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07), 0 4px 18px rgba(0,0,0,0.04);
}
.card + .card { margin-top: 1.5rem; }

/* ── Section label ───────────────────────────────────────────────────────── */
.sec-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #94a3b8;
  margin-bottom: 0.8rem;
}

/* ── Type grid ───────────────────────────────────────────────────────────── */
.type-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-bottom: 1.75rem;
}
.type-btn {
  border: 2px solid #e2e8f0;
  background: white;
  border-radius: 10px;
  padding: 0.7rem 0.25rem 0.65rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  color: #475569;
  font-family: inherit;
}
.type-btn:hover { border-color: #93c5fd; background: #eff6ff; color: #1e40af; }
.type-btn.active { border-color: #2563eb; background: #2563eb; color: white; }
.type-btn .t-icon { font-size: 1.35rem; display: block; line-height: 1; margin-bottom: 0.275rem; }
.type-btn .t-label { font-size: 0.68rem; font-weight: 600; }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { margin-bottom: 0.9rem; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #475569;
  margin-bottom: 0.325rem;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.575rem 0.825rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  color: #1e293b;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.11);
}
.field textarea { resize: vertical; min-height: 76px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* ── Preview area ────────────────────────────────────────────────────────── */
.preview-area {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 290px;
  padding: 1.5rem;
  margin-bottom: 1.1rem;
}
#qr-canvas { display: none; border-radius: 4px; max-width: 100%; }
.qr-placeholder { text-align: center; color: #cbd5e1; }
.qr-placeholder svg { width: 72px; height: 72px; margin: 0 auto 0.6rem; display: block; }
.qr-placeholder p { font-size: 0.8rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.dl-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}
.btn-dl {
  padding: 0.575rem 0.5rem;
  border: 1.5px solid #e2e8f0;
  background: white;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-dl:hover:not(:disabled) { border-color: #2563eb; color: #2563eb; background: #eff6ff; }
.btn-dl:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-save {
  width: 100%;
  padding: 0.8rem;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.btn-save:hover:not(:disabled) {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  box-shadow: 0 4px 14px rgba(37,99,235,0.38);
  transform: translateY(-1px);
}
.btn-save:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-outline { background: white; border: 1.5px solid #e2e8f0; color: #475569; }
.btn-outline:hover { border-color: #2563eb; color: #2563eb; }

/* ── URL result box ──────────────────────────────────────────────────────── */
.url-result {
  display: none;
  margin-top: 0.9rem;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 10px;
  padding: 0.9rem;
}
.url-result.show { display: block; }
.url-result-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #15803d;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.35rem;
}
.url-result-link {
  display: block;
  color: #166534;
  font-size: 0.8rem;
  word-break: break-all;
  margin-bottom: 0.6rem;
  text-decoration: none;
  font-weight: 500;
}
.url-result-link:hover { text-decoration: underline; }
.btn-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.375rem 0.8rem;
  background: #16a34a;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-copy:hover { background: #15803d; }

/* ── Recent / history list ───────────────────────────────────────────────── */
.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.75rem;
}
.qr-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem;
  border: 1.5px solid #f1f5f9;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s;
  background: #fafafa;
}
.qr-card:hover { border-color: #2563eb; background: #eff6ff; box-shadow: 0 2px 8px rgba(37,99,235,0.1); }
.qr-card img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 6px;
  background: white;
  padding: 2px;
  flex-shrink: 0;
  border: 1px solid #f1f5f9;
}
.qr-card-info .qi-title {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.qr-card-info .qi-meta { font-size: 0.7rem; color: #94a3b8; margin-top: 0.1rem; }

/* ── Type badge ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.225rem 0.625rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-url      { background: #dbeafe; color: #1e40af; }
.badge-text     { background: #f3e8ff; color: #6b21a8; }
.badge-vcard    { background: #dcfce7; color: #166534; }
.badge-location { background: #fef3c7; color: #92400e; }
.badge-email    { background: #fee2e2; color: #991b1b; }
.badge-phone    { background: #d1fae5; color: #065f46; }
.badge-wifi     { background: #e0f2fe; color: #075985; }
.badge-sms      { background: #fce7f3; color: #9d174d; }

/* ── View page ───────────────────────────────────────────────────────────── */
.view-qr-wrap {
  display: flex;
  justify-content: center;
  background: #f8fafc;
  border-radius: 12px;
  padding: 2rem;
  margin-bottom: 1.25rem;
}
.view-qr-wrap img { max-width: 280px; width: 100%; border-radius: 4px; }
.view-meta { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-bottom: 1.25rem; }
.view-label { font-size: 1.25rem; font-weight: 700; }
.view-date { font-size: 0.8rem; color: #94a3b8; }
.view-content {
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: #475569;
  word-break: break-all;
  font-family: 'SFMono-Regular', Consolas, monospace;
  margin-bottom: 1.25rem;
  max-height: 120px;
  overflow-y: auto;
}
.view-dl-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { color: #94a3b8; font-size: 0.875rem; padding: 0.75rem 0; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .grid-main { grid-template-columns: 1fr !important; }
}
@media (max-width: 480px) {
  .type-grid { grid-template-columns: repeat(4, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .site-header { padding: 0.75rem 1rem; }
}
