:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.page {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.page.active {
  display: flex;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}

.card-header {
  padding: 32px 32px 16px;
  text-align: center;
}

.card-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.card-header p {
  font-size: 14px;
  color: var(--text-secondary);
}

.card-header.success {
  padding: 40px 32px 20px;
}

.icon-check {
  width: 64px;
  height: 64px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 16px;
}

.card-body {
  padding: 16px 32px 32px;
}

.card-footer {
  padding: 16px 32px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.card-footer a {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
}

.card-footer a:hover {
  text-decoration: underline;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 120px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  background: #a5b4fc;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
  width: auto;
}

.message {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.message.error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.message.success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.submitted-time {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Admin styles */
.admin-container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.admin-header h1 {
  font-size: 24px;
  font-weight: 700;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.tab-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.tab-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tab-actions input {
  width: 80px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  text-align: center;
}

.generated-codes {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.codes-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
}

.codes-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.code-item {
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 14px;
  word-break: break-all;
}

.table-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-unused {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-used {
  background: #dcfce7;
  color: #166534;
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.pagination button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.pagination button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Loading */
.loading {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 640px) {
  .admin-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-actions {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  th, td {
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* Contact Section */
.contact-section {
  padding: 16px 32px 8px;
  border-top: 1px solid var(--border);
}

.contact-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}

.contact-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.contact-item .contact-label {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 60px;
}

.contact-item .contact-value {
  color: var(--primary);
  font-weight: 500;
}

.contact-qr {
  margin-top: 8px;
  text-align: center;
}

.contact-qr img {
  max-width: 160px;
  max-height: 160px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.contact-qr .qr-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* Settings Card */
.settings-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  max-width: 500px;
}

.tab-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Image Upload */
.image-upload-area {
  margin-top: 4px;
}

.image-preview {
  width: 200px;
  height: 200px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.2s;
  background: var(--bg);
}

.image-preview:hover {
  border-color: var(--primary);
}

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

.image-hint {
  font-size: 12px;
  color: #94a3b8;
}

.image-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-upload-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 200px;
  height: 200px;
  border: 2px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

/* Custom Display Section */
.custom-display-section {
  padding: 16px 32px 8px;
  border-top: 1px solid var(--border);
}

.custom-display-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}

.custom-display-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.custom-display-item {
  font-size: 14px;
  color: var(--text);
  text-align: center;
  word-break: break-all;
}

.custom-display-item a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.custom-display-item a:hover {
  text-decoration: underline;
}

.custom-display-item .item-label {
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 6px;
}

/* Admin display management */
.section-subtitle {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.form-select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: auto;
}

.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-delete {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.btn-delete:hover {
  background: var(--danger);
  color: white;
}
