/* ─── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f4f6f9;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --border-focus:#3b82f6;
  --text:        #1e293b;
  --text-muted:  #64748b;
  --primary:     #2563eb;
  --primary-h:   #1d4ed8;
  --success:     #16a34a;
  --success-bg:  #f0fdf4;
  --success-brd: #bbf7d0;
  --error:       #dc2626;
  --error-bg:    #fef2f2;
  --error-brd:   #fecaca;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.08);
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --mono:        'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  background: #eff6ff;
  color: var(--primary);
  border: 1px solid #bfdbfe;
  padding: 2px 8px;
  border-radius: 99px;
}

.main {
  flex: 1;
  max-width: 680px;
  width: 100%;
  margin: 48px auto;
  padding: 0 24px;
}

.footer {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ─── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 40px;
}

.card-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.card-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}
.card-subtitle code {
  font-family: var(--mono);
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

/* ─── Steps ────────────────────────────────────────────────────────────────── */
.step { display: none; }
.step.active { display: block; }

/* ─── Drop zone ────────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  outline: none;
}
.drop-zone:hover,
.drop-zone:focus,
.drop-zone.drag-over {
  border-color: var(--border-focus);
  background: #eff6ff;
}
.drop-icon {
  color: #94a3b8;
  margin-bottom: 12px;
  transition: color .2s;
}
.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon { color: var(--primary); }

.drop-text { font-size: 15px; color: var(--text); margin-bottom: 4px; }
.drop-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.drop-limit { margin-top: 12px; font-size: 12px; color: var(--text-muted); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, color .15s, opacity .15s;
  border: 1.5px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); border-color: var(--primary-h); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: #bfdbfe;
}
.btn-outline:hover:not(:disabled) { background: #eff6ff; }

.btn-full { width: 100%; padding: 12px; font-size: 15px; }

.btn-reset {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  margin-left: auto;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.btn-reset:hover { color: var(--error); background: var(--error-bg); }

/* ─── File info bar ─────────────────────────────────────────────────────────── */
.file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 20px;
}
.file-info svg { flex-shrink: 0; color: var(--primary); }
#file-name-display { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Form elements ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.toggle-label {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.toggle-label span:first-child { padding-top: 2px; }
.toggle-desc {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

.form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-select:focus { border-color: var(--border-focus); }

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

/* ─── Toggle switch ─────────────────────────────────────────────────────────── */
.toggle { display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0; }
.toggle input { display: none; }

.toggle-track {
  width: 42px;
  height: 24px;
  background: var(--border);
  border-radius: 99px;
  position: relative;
  transition: background .2s;
}
.toggle input:checked + .toggle-track { background: var(--primary); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); }

/* ─── Loading ───────────────────────────────────────────────────────────────── */
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 0;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 15px; color: var(--text-muted); }

/* ─── Result / Success ──────────────────────────────────────────────────────── */
.result {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}
.result--success {
  background: var(--success-bg);
  border: 1px solid var(--success-brd);
}
.result-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #dcfce7;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--success);
}
.result-body { display: flex; flex-direction: column; gap: 2px; }
.result-body strong { font-size: 15px; color: var(--text); }
.result-meta { font-size: 13px; color: var(--text-muted); }

.success-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.success-actions .btn { flex: 1; min-width: 160px; }

/* ─── Error banner ──────────────────────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--error-bg);
  border: 1px solid var(--error-brd);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--error);
  margin-top: 16px;
}
.error-banner svg { flex-shrink: 0; margin-top: 1px; }

/* ─── API hint ──────────────────────────────────────────────────────────────── */
.api-hint {
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.api-hint summary {
  cursor: pointer;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
}
.api-hint summary::marker { display: none; }
.api-hint summary::-webkit-details-marker { display: none; }
.api-hint summary::before { content: '▶ '; font-size: 10px; }
.api-hint[open] summary::before { content: '▼ '; }

.api-hint pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-top: none;
}

/* ─── Login page ─────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  width: 64px;
  height: 64px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin: 0 auto 20px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.login-form { display: flex; flex-direction: column; gap: 12px; }

.login-field { position: relative; }

.login-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

.login-error {
  font-size: 13px;
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-brd);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  text-align: left;
}

.login-btn { padding: 12px; font-size: 15px; }

.login-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ─── Logout button in header ────────────────────────────────────────────────── */
.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-logout:hover { color: var(--text); border-color: #94a3b8; background: #f8fafc; }

/* ─── Utilities ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .card { padding: 24px 20px; }
  .card-title { font-size: 19px; }
  .drop-zone { padding: 36px 20px; }
  .success-actions { flex-direction: column; }
}
