:root {
  --bg-color: #f8fafc;
  --surface-color: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Sarabun", "Thonburi", "Leelawadee UI", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #0b1120;
    --surface-color: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5f;
    --success: #22c55e;
    --success-bg: #052e16;
    --warning: #f59e0b;
    --warning-bg: #451a03;
    --danger: #ef4444;
    --danger-bg: #450a0a;
  }
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  padding: 24px 16px;
  min-height: 100vh;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
}

@media (min-width: 640px) {
  .app-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.app-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* Progress & Alert Bars */
.progress-section {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
}

.progress-bar-track {
  width: 100%;
  height: 8px;
  background-color: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--primary);
  transition: width 0.15s ease;
}

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

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.4;
}

.alert-warning {
  background-color: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning);
}

.alert-error {
  background-color: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.error-title {
  font-weight: 700;
  margin-bottom: 4px;
}

/* Card */
.card {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 640px) {
  .form-grid:has(#cutoffGroup:not(.hidden)) {
    grid-template-columns: 2fr 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tier-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background-color: var(--primary-light);
  color: var(--primary);
}

.tier-tag.tier-2 {
  background-color: var(--warning-bg);
  color: var(--warning);
}

.form-control {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background-color: var(--surface-color);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.text-area {
  font-size: 1rem;
  resize: vertical;
  min-height: 90px;
}

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

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.action-links {
  display: flex;
  gap: 12px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.link-btn:hover {
  color: var(--primary-hover);
}

/* Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
  text-decoration: none;
}

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

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

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

.btn-secondary {
  background-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  opacity: 0.85;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 4px 10px;
}

.exec-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* Output Pane */
.output-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.output-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.output-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.output-box {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 80px;
  max-height: 400px;
  overflow-y: auto;
  color: var(--text-main);
}

.image-box {
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.image-box img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Footer */

/* Footer */
.app-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

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