/* ===== Design tokens ===== */
:root {
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg: #f4f6fb;
  --bg-accent: #eef2ff;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --error: #dc2626;
  --error-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --header-h: 64px;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

.subtitle, .muted {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}
.btn-primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
  color: #fff;
}
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--surface-hover);
  text-decoration: none;
}
.btn-block { width: 100%; }
.btn-sm { padding: 0.45rem 0.85rem; font-size: 0.85rem; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1rem; }

/* ===== Login page ===== */
.page-login {
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 20%, rgba(79, 70, 229, 0.12), transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(14, 165, 233, 0.1), transparent 35%),
    var(--bg);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem;
  gap: 2rem;
  align-items: center;
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2.25rem;
  box-shadow: var(--shadow-md);
}

.login-brand { margin-bottom: 1.75rem; }
.login-brand h1 {
  margin: 0.75rem 0 0.35rem;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff;
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
.logo-mark.sm {
  width: 40px;
  height: 40px;
  font-size: 0.65rem;
  border-radius: 10px;
}

.login-form .field { margin-bottom: 1rem; }
.field label, .field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="password"],
select.select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.login-aside {
  padding: 1rem 1.5rem;
}
.login-aside h2 {
  font-size: 1.35rem;
  margin: 0 0 1rem;
}
.feature-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.feature-list li {
  position: relative;
  padding: 0.65rem 0 0.65rem 1.75rem;
  color: var(--text-secondary);
}
.feature-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--success);
  font-weight: 700;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error {
  background: var(--error-soft);
  color: var(--error);
  border: 1px solid #fecaca;
}

/* ===== Dashboard layout ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand strong { display: block; font-size: 1rem; }
.brand-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}
.page-head { margin-bottom: 1.5rem; }
.page-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
}

.layout-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.steps-panel {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.steps-panel h3 {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.step-item {
  position: relative;
  padding: 0.65rem 0.65rem 0.65rem 2rem;
  margin-bottom: 0.35rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.step-item::before {
  content: attr(data-step);
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.step-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.step-item.active::before {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.step-item.done {
  color: var(--success);
}
.step-item.done::before {
  content: "✓";
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: var(--success);
}

.content-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.card-head h2 {
  margin: 0;
  font-size: 1.1rem;
}
.step-badge {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Dropzone ===== */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 2.5rem 1.5rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-hover);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.dropzone:hover, .dropzone.is-dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.dropzone-icon { font-size: 2rem; }
.dropzone-title {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.info-banner {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--success-soft);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-sm);
  color: #065f46;
  font-size: 0.9rem;
}

/* ===== Settings ===== */
.settings-block { margin-bottom: 1.5rem; }
.block-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.65rem;
}

.option-card {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.option-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.option-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.option-card.is-locked {
  opacity: 0.7;
  cursor: not-allowed;
}
.option-card input {
  margin-top: 0.2rem;
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.option-body strong { display: block; font-size: 0.9rem; }
.option-body small {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
  line-height: 1.4;
}
.option-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.lock-text {
  display: block;
  color: var(--warning);
  font-size: 0.78rem;
  font-style: normal;
  margin: 0.2rem 0;
}

.badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-free { background: var(--success-soft); color: var(--success); }
.badge-soon { background: #f1f5f9; color: #64748b; }

.feature-section { margin-bottom: 1.25rem; }
.feature-section-title {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.field-hint { margin: 0 0 0.75rem; font-size: 0.85rem; }

.actions-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}

/* ===== Progress ===== */
.progress-wrap { margin-bottom: 1rem; }
.progress-bar {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 999px;
  transition: width 0.35s ease;
}
.progress-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}
#progressPercent {
  margin-left: auto;
  font-weight: 700;
  color: var(--primary);
}

.log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
}
.log-list li {
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.log-list li:last-child { border-bottom: none; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-box {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}
.stat-box strong {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.stat-box span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.data-table th,
.data-table td,
.table-wrap table th,
.table-wrap table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th,
.table-wrap table th {
  background: var(--surface-hover);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
}
.data-table tbody tr:hover,
.table-wrap table tbody tr:hover {
  background: var(--surface-hover);
}
.data-table tbody tr:last-child td,
.table-wrap table tbody tr:last-child td {
  border-bottom: none;
}

.link { font-weight: 600; }

.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: lowercase;
}
.pill-done, .pill-completed { background: var(--success-soft); color: var(--success); }
.pill-failed { background: var(--error-soft); color: var(--error); }
.pill-running, .pill-queued { background: var(--primary-soft); color: var(--primary); }

.card-history { margin-top: 0.5rem; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .login-shell {
    grid-template-columns: 1fr;
    padding: 1.25rem;
  }
  .login-aside { display: none; }

  .layout-grid {
    grid-template-columns: 1fr;
  }
  .steps-panel {
    position: static;
    display: none;
  }

  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  .app-main { padding: 1rem; }
  .page-head h1 { font-size: 1.45rem; }
}

@media (max-width: 480px) {
  .card { padding: 1rem; }
  .dropzone { padding: 1.75rem 1rem; }
  .btn-lg { width: 100%; }
}

/* ===== Header nav ===== */
.header-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.header-nav-link {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}
.header-nav-link:hover {
  background: var(--surface-hover);
  text-decoration: none;
  color: var(--text);
}
.header-nav-link.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

/* ===== Settings page ===== */
.alert-success {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #a7f3d0;
}
.settings-page-card { max-width: 720px; }
.settings-hint-card { max-width: 720px; margin-top: 1rem; }
.settings-section-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}
.settings-form .settings-block + .settings-block {
  margin-top: 1.75rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--border);
}
.field-input {
  width: 100%;
  max-width: 480px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  margin-top: 0.35rem;
}
.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.key-status {
  margin: 0.75rem 0;
  font-size: 0.88rem;
}
.key-status code {
  background: var(--bg);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.85rem;
}
.key-status-ok { color: var(--success); }
.key-status-warn { color: var(--warning); }
.key-status-muted { color: var(--text-muted); }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1.75rem;
}
.hint-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.hint-list li + li { margin-top: 0.35rem; }
