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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --bg: #f8fafc;
  --white: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-focus: #6366f1;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --error-border: #fca5a5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --radius: 10px;
  --radius-sm: 6px;
}

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

/* ── Auth ── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.auth-logo span {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.auth-subtitle {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 0.95rem;
}
.auth-link {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.auth-link a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-link a:hover { text-decoration: underline; }

/* ── App Layout ── */
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-email {
  font-size: 0.875rem;
  color: var(--text-muted);
}
.header-balance {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 0.85rem;
  text-decoration: none;
  transition: background .15s;
}
.header-balance:hover { background: var(--card); border-color: var(--primary); }

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}
.page-header h1 { font-size: 1.75rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 0.95rem; margin-top: 4px; }

/* ── Forms ── */
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 6px; display: block; }
.required { color: #ef4444; }
.optional { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Alert ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 20px;
}
.alert-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}
.alert-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.cert-status { border: 1px solid var(--border); background: var(--bg); }
.cert-issued  { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.cert-issuing { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.cert-pending { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.cert-failed  { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }

/* ── Landings Grid ── */
.landings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.landing-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: box-shadow .2s, transform .2s;
}
.landing-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.landing-card-body {
  padding: 20px 20px 16px;
  flex: 1;
}
.landing-card-body h3 { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.landing-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.landing-card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.landing-urls { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.url-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 100px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.url-badge:hover { background: #e0e7ff; }
.url-badge-custom { color: #059669; background: #ecfdf5; }
.url-badge-custom:hover { background: #d1fae5; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-state h2 { font-size: 1.25rem; font-weight: 600; }
.empty-state p { color: var(--text-muted); }
.empty-state .btn { margin-top: 8px; }

/* ── Builder ── */
.builder-container {
  max-width: 720px;
}
.form-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
}
.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.section-desc { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 16px; }

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  transition: border-color .2s, background .2s;
  position: relative;
  cursor: pointer;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.upload-placeholder p { font-size: 0.9rem; color: var(--text-muted); margin-top: 10px; }
.upload-link { color: var(--primary); font-weight: 500; cursor: pointer; }
.upload-hint { font-size: 0.8rem !important; }

.image-previews { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.image-preview-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.image-preview-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.image-preview-info { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.image-preview-name { font-size: 0.8rem; color: var(--text-muted); }
.image-preview-info textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
.image-preview-info textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.form-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding-top: 4px;
}

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.loading-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: var(--shadow-md);
}
.loading-card h3 { margin: 16px 0 8px; font-size: 1.1rem; }
.loading-card p { font-size: 0.875rem; color: var(--text-muted); }

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Landing View ── */
.landing-info-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 28px;
}
.info-block {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.info-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.url-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.url-code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.875rem;
  font-family: 'Menlo', 'Monaco', monospace;
  color: var(--primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }

.preview-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.preview-header h2 { font-size: 1rem; font-weight: 600; }
.preview-actions { display: flex; gap: 8px; }

.preview-frame-wrap {
  position: relative;
  width: 100%;
  height: 600px;
}
.preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}
.source-code {
  padding: 0;
  max-height: 600px;
  overflow: auto;
  background: #0f172a;
}
.source-code pre {
  padding: 20px;
  margin: 0;
}
.source-code code {
  font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: #e2e8f0;
  white-space: pre;
}

/* ── Status badges ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
}
.status-generating { background: #fef3c7; color: #92400e; }
.status-done       { background: #dcfce7; color: #166534; }
.status-error      { background: #fee2e2; color: #991b1b; }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.7); }
}

/* ── Status panels ── */
.status-panel {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
}
.status-panel-generating { border-color: #fde68a; background: #fffbeb; }
.status-panel-error      { border-color: #fca5a5; background: #fef2f2; }

.status-panel-icon { flex-shrink: 0; padding-top: 2px; }

.status-panel h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; }
.status-panel p  { font-size: .9rem; color: var(--text-muted); }

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

/* Progress steps */
.progress-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}
.progress-step {
  font-size: .85rem;
  color: var(--text-muted);
  padding-left: 20px;
  position: relative;
  transition: color .3s;
}
.progress-step::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background .3s;
}
.progress-step.active {
  color: var(--primary);
  font-weight: 500;
}
.progress-step.active::before { background: var(--primary); }

/* ── Dialog Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  backdrop-filter: blur(3px);
  padding: 24px;
}
.modal {
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  width: 100%;
  max-width: 540px;
  overflow: hidden;
}
.modal-header {
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; }
.modal-header p  { font-size: .85rem; color: var(--text-muted); }
.modal-body   { padding: 20px 24px; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .85rem;
  margin-bottom: 12px;
  display: none;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .page-header { flex-direction: column; }
  .auth-card { padding: 28px 20px; }
  .form-section { padding: 20px; }
  .preview-frame-wrap { height: 400px; }
  .url-row { flex-direction: column; align-items: flex-start; }
}
