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

:root {
  --bg:         #0d1117;
  --bg-card:    #161b22;
  --bg-input:   #0d1117;
  --bg-result:  #1c2128;
  --border:     #30363d;
  --text:       #c9d1d9;
  --text-muted: #8b949e;
  --accent:     #58a6ff;
  --accent-dim: #1f6feb;
  --success:    #3fb950;
  --error:      #f85149;
  --warning:    #d29922;
  --radius:     8px;
  --transition: 150ms ease;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, 'Inter', -apple-system, BlinkMacSystemFont,
               'Segoe UI', Helvetica, Arial, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  padding: 1.5rem 1rem 4rem;
}

/* ── Layout ───────────────────────────────────────────────── */
.container {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  text-align: center;
  padding: 2rem 0 0.5rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.card h2 {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.card-error {
  border-color: var(--error);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-error .error-icon {
  font-size: 1.1rem;
  color: var(--error);
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.card-error #error-message {
  flex: 1;
  color: var(--text);
  font-size: 0.9rem;
  min-width: 0;
}

.card-error #dismiss-error-btn {
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Fields ───────────────────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

input[type="url"],
input[type="password"],
input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  padding: 0.55rem 0.75rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.55rem 1.1rem;
  transition: background var(--transition), opacity var(--transition),
              box-shadow var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary:not(:disabled):hover {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

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

.btn-secondary:not(:disabled):hover {
  background: var(--bg-result);
  border-color: var(--text-muted);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.8rem;
}

.btn-success {
  background: transparent;
  border: 1px solid var(--success);
  color: var(--success);
}

/* ── Progress ─────────────────────────────────────────────── */
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

#progress-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent);
}

#progress-percent {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.progress-bar-track {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 300ms ease;
  position: relative;
}

.progress-bar-fill.indeterminate {
  width: 40% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.progress-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ── Result ───────────────────────────────────────────────── */
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.result-header h2 {
  margin-bottom: 0;
}

.result-box {
  background: var(--bg-result);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  color: var(--text);
}

.result-box::-webkit-scrollbar {
  width: 6px;
}
.result-box::-webkit-scrollbar-track {
  background: transparent;
}
.result-box::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

/* ── API key status ───────────────────────────────────────── */
.status-ok    { color: var(--success); }
.status-error { color: var(--error); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
  body {
    padding: 1rem 0.75rem 3rem;
  }

  header h1 {
    font-size: 1.4rem;
  }

  .card {
    padding: 1rem 1.1rem;
  }

  .input-row {
    flex-direction: column;
  }

  .input-row .btn {
    width: 100%;
  }

  .result-box {
    max-height: 280px;
  }
}
