:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #eef5ff;
  --text: #172033;
  --muted: #667085;
  --border: #d9e2ef;
  --primary: #1769e0;
  --primary-dark: #0f56bd;
  --success: #16834a;
  --danger: #c62828;
  --warning: #b86b00;
  --shadow: 0 14px 40px rgba(31, 55, 91, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 20px 14px 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 8vw, 40px);
  line-height: 1.04;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 12px 0;
}

.auth-panel {
  display: grid;
  gap: 8px;
}

label {
  font-weight: 700;
}

input[type="password"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 13px 14px;
  outline: none;
  background: #fbfdff;
}

input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.14);
}

.file-drop {
  display: grid;
  gap: 8px;
  min-height: 128px;
  place-items: center;
  text-align: center;
  border: 1.5px dashed #93b4e6;
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 22px;
  cursor: pointer;
}

.file-title {
  color: var(--primary);
  font-size: 20px;
}

.file-subtitle {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

input[type="file"] {
  display: none;
}

.options-block {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.section-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-weight: 600;
}

.toggle-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 16px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  min-height: 46px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.64;
}

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

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

.secondary,
.icon-button {
  background: #e9f1ff;
  color: var(--primary-dark);
}

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

.compact {
  min-height: 36px;
  padding: 0 12px;
}

.icon-button {
  width: 44px;
  min-height: 44px;
  border-radius: 8px;
  font-size: 22px;
  padding: 0;
}

.button-icon,
.icon-button svg,
.status-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary .button-icon {
  color: #fff;
}

.compact .button-icon {
  width: 16px;
  height: 16px;
}

.result-header,
.history-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.neutral {
  background: #edf1f7;
  color: #4a5568;
}

.status-pill.queued {
  background: #fff4d6;
  color: var(--warning);
}

.status-pill.clean,
.status-pill.success {
  background: #e5f7ed;
  color: var(--success);
}

.status-pill.detected,
.status-pill.extract_error,
.status-pill.error {
  background: #fdeaea;
  color: var(--danger);
}

.status-pill.running {
  background: #fff4d6;
  color: var(--warning);
}

.spin {
  animation: spin 900ms linear infinite;
}

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

pre {
  margin: 14px 0 0;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #111827;
  color: #e5edf7;
  border-radius: 8px;
  padding: 14px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.history-list.empty {
  color: var(--muted);
  font-size: 14px;
}

.history-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.history-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-name {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  min-width: min(90vw, 360px);
  background: #172033;
  color: white;
  border-radius: 8px;
  padding: 11px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  text-align: center;
  font-weight: 700;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 620px) {
  .app-shell {
    padding-top: 34px;
  }

  .button-grid {
    grid-template-columns: 1.3fr 1fr;
  }
}
