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

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #ef4444;
  --success: #10b981;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

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

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.admin-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.subtitle {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 14px;
}

/* ── SCREENS ──────────────────────────────────────────────── */

.screen {
  display: none;
}

.screen.active,
.overlay.active {
  display: block;
}

.screen.active.center {
  display: flex;
}

/* ── CARDS ────────────────────────────────────────────────── */

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

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

.card h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

.icon-wrap {
  width: 64px;
  height: 64px;
  background: #eef2ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--primary);
}

.icon-wrap svg {
  width: 32px;
  height: 32px;
}

.icon-wrap.warn {
  background: #fef3c7;
  color: #d97706;
}

/* ── INPUTS ───────────────────────────────────────────────── */

.input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s;
  background: #fff;
  color: var(--text);
}

.input:focus {
  outline: none;
  border-color: var(--primary);
}

.input.big {
  padding: 16px;
  font-size: 20px;
  text-align: center;
  letter-spacing: 2px;
}

.input.small {
  padding: 6px 10px;
  font-size: 13px;
}

.input.tiny {
  width: 60px;
  padding: 6px 8px;
  font-size: 12px;
  text-align: center;
}

.input.color {
  width: 40px;
  height: 34px;
  padding: 2px;
}

textarea.input {
  resize: vertical;
  font-family: monospace;
  font-size: 14px;
  text-align: left;
  letter-spacing: 0;
}

select.input {
  appearance: auto;
}

/* ── BUTTONS ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn.full {
  width: 100%;
  margin-top: 16px;
}

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

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

.btn.outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}

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

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

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 12px;
}

.hint code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ── CERTIFICATE GRID ─────────────────────────────────────── */

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

.cert-header h2 {
  font-size: 20px;
}

.badge {
  background: var(--primary);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.cert-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.cert-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  transition: box-shadow 0.2s;
}

.cert-card:hover {
  box-shadow: var(--shadow-lg);
}

.cert-thumb {
  width: 100px;
  min-height: 70px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cert-thumb-inner {
  text-align: center;
}

.cert-icon {
  font-size: 32px;
}

.cert-info {
  padding: 12px 16px;
  flex: 1;
}

.cert-info h4 {
  font-size: 15px;
  margin-bottom: 4px;
}

.cert-name {
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
}

.cert-date {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ── VIEWER / OVERLAY ─────────────────────────────────────── */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.overlay.active {
  display: flex;
}

.viewer {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.viewer .close {
  position: absolute;
  top: 8px;
  right: 16px;
  font-size: 28px;
  color: #fff;
  background: rgba(0,0,0,0.5);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
}

.viewer img {
  width: 100%;
  display: block;
}

.viewer-actions {
  padding: 12px;
  text-align: center;
}

/* ── MODAL ────────────────────────────────────────────────── */

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  margin-bottom: 16px;
  font-size: 20px;
}

.modal label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal .input {
  margin-bottom: 4px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* ── ADMIN HEADER ─────────────────────────────────────────── */

.admin-header {
  text-align: center;
}

.admin-header h1 {
  margin-bottom: 16px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--border);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tab.active {
  background: var(--card);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.tab-content {
  display: none;
}

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

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── SESSIONS LIST ────────────────────────────────────────── */

.sessions-list {
  display: grid;
  gap: 12px;
}

.session-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s;
  position: relative;
}

.session-card:hover {
  box-shadow: var(--shadow-lg);
}

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

.session-card-header h3 {
  font-size: 16px;
}

.session-card-body {
  font-size: 13px;
  color: var(--text-muted);
}

.session-card-body p {
  margin-bottom: 4px;
}

.session-card-actions {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.3s;
}

/* ── SESSION INFO ─────────────────────────────────────────── */

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

.session-info h2 {
  font-size: 20px;
  margin-bottom: 4px;
}

.session-info p {
  font-size: 14px;
  color: var(--text-muted);
}

.search-bar {
  margin-bottom: 12px;
}

.search-bar .input {
  padding: 10px 14px;
  font-size: 14px;
}

/* ── PARTICIPANTS LIST ────────────────────────────────────── */

.participants-list {
  display: grid;
  gap: 8px;
}

.participant-row {
  background: var(--card);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  border-left: 4px solid var(--border);
  transition: border-color 0.2s;
}

.participant-row.issued {
  border-left-color: var(--success);
}

.participant-info {
  display: flex;
  flex-direction: column;
}

.participant-phone {
  font-size: 13px;
  color: var(--text-muted);
}

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

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--success);
}

.toggle-text {
  color: var(--text-muted);
}

.toggle-label input:checked + .toggle-text {
  color: var(--success);
}

/* ── TEMPLATES GRID ───────────────────────────────────────── */

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

.template-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.template-preview {
  width: 100%;
  height: 170px;
  background: #f1f5f9;
  overflow: hidden;
}

.template-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.template-placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

.template-info {
  padding: 12px 16px;
}

.template-info h4 {
  font-size: 15px;
  margin-bottom: 2px;
}

.template-info p {
  font-size: 12px;
  color: var(--text-muted);
}

.template-actions {
  padding: 0 16px 12px;
  display: flex;
  gap: 8px;
}

/* ── EDITOR ───────────────────────────────────────────────── */

.editor-body {
  background: #1a1a2e;
  color: #e2e8f0;
  min-height: 100vh;
}

.editor-layout {
  max-width: 1300px;
  margin: 0 auto;
  padding: 16px;
}

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

.editor-header h1 {
  font-size: 22px;
  color: #fff;
}

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

.editor-main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  align-items: start;
}

.editor-canvas-wrap {
  background: #16213e;
  border-radius: var(--radius);
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  border: 2px dashed #2a3a5c;
  position: relative;
}

.editor-canvas-wrap canvas {
  display: block;
  cursor: crosshair;
  max-width: 100%;
}

.canvas-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #aaa;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  pointer-events: none;
}

.editor-panel {
  background: #16213e;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.panel-section {
  margin-bottom: 14px;
}

.panel-label {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-section .input,
.panel-section select {
  background: #1a1a2e;
  border-color: #2a3a5c;
  color: #e2e8f0;
}

.panel-section .input:focus {
  border-color: var(--primary);
}

.panel-section input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.pos-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 13px;
  color: #94a3b8;
}

.color-picker {
  width: 60px !important;
  height: 36px;
  padding: 2px;
  border: none;
  cursor: pointer;
}

.preview-modal {
  max-width: 680px;
}

.preview-modal canvas {
  width: 100%;
  display: block;
  border-radius: 4px;
  margin-bottom: 12px;
}

.editor-canvas-wrap .field-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .editor-main {
    grid-template-columns: 1fr;
  }
  .editor-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── EMPTY STATE ──────────────────────────────────────────── */

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

.empty-state p {
  margin-bottom: 4px;
}

/* ── SPINNER ──────────────────────────────────────────────── */

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

/* ── FOOTER ───────────────────────────────────────────────── */

footer {
  text-align: center;
  margin-top: 32px;
  padding: 16px 0;
}

.admin-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}

.admin-link:hover {
  color: var(--primary);
}

/* ── SYNC BAR ──────────────────────────────────────────────── */

.sync-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.sync-bar.sync-ok {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.sync-bar.sync-pending {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.sync-bar.sync-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.sync-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.sync-bar.sync-ok .sync-icon::before {
  content: '\2714';
}

.sync-bar.sync-pending .sync-icon::before {
  content: '\26A0';
}

.sync-bar.sync-error .sync-icon::before {
  content: '\2716';
}

.sync-bar #sync-text {
  flex: 1;
}

.sync-bar .btn.small {
  flex-shrink: 0;
  white-space: nowrap;
}

.sync-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0,0,0,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

/* ── LOADING OVERLAY ──────────────────────────────────────── */

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 35, 0.92);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.loading-overlay.active {
  display: flex;
}

.loading-box {
  background: #1e293b;
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
  min-width: 280px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #334155;
  border-top-color: #818cf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

.loading-message {
  color: #e2e8f0;
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

/* ── BULK ISSUE BAR ────────────────────────────────────── */

.bulk-issue-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 2px solid var(--primary);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.15), var(--shadow);
}

.select-all-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.select-all-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.issue-status {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.issue-status.status-issued {
  background: #d1fae5;
  color: #065f46;
}

.issue-status.status-pending {
  background: #fef3c7;
  color: #92400e;
}

/* ── RESPONSIVE ───────────────────────────────────────────── */

@media (max-width: 600px) {
  .admin-container {
    padding: 12px;
  }

  .template-actions {
    flex-direction: column;
  }

  .participant-actions {
    width: 100%;
    justify-content: space-between;
  }
}
