:root {
  --background: #f4f4f2;
  --foreground: #2d332a;
  --card: #ffffff;
  --primary: #7a9a1f;
  --primary-foreground: #ffffff;
  --muted: #e6e6e3;
  --muted-foreground: #6b7268;
  --border: #d9d9d6;
  --destructive: #d22d2d;
  --success: #7a9a1f;
  --warning: #f2a30f;
  --warning-bg: #fdf2dd;
  --header: #141414;
  --header-foreground: #ffffff;
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.header {
  background: var(--header);
  color: var(--header-foreground);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}

.logo {
  height: 40px;
  width: auto;
}

.divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
}

.header-title {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.8);
}

.header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.header-link {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}

.header-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-foreground);
}

.header-link-btn {
  background: transparent;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.hidden {
  display: none;
}

/* Main layout */
.main {
  max-width: 760px;
  padding-top: 2rem;
  padding-bottom: 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.back-link {
  color: var(--foreground);
  text-decoration: none;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

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

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

.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

.card h3 {
  margin: 0;
  font-size: 1rem;
}

.muted {
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.muted-card h3 {
  margin-bottom: 1rem;
}

.muted-card ul {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.muted-card li {
  margin-bottom: 0.25rem;
}

.muted-card .note {
  margin-top: 1rem;
  border: 1px solid var(--border);
  background: var(--muted);
  border-radius: var(--radius);
  padding: 0.75rem;
}

/* Dropzone */
.dropzone {
  position: relative;
  margin-top: 1rem;
  min-height: 180px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.dragging {
  border-color: var(--primary);
  background: rgba(122, 154, 31, 0.05);
}

.dropzone input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-content {
  text-align: center;
  padding: 2rem;
}

.dropzone-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.dropzone-title {
  font-size: 1.05rem;
  font-weight: 500;
  margin: 0 0 0.25rem;
}

/* File list */
.file-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-list.hidden,
.dropzone.hidden,
.progress-list.hidden,
.status-bar.hidden,
.tab-content.hidden,
#resultsSection.hidden {
  display: none;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 2px solid rgba(122, 154, 31, 0.3);
  background: rgba(122, 154, 31, 0.05);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.file-icon {
  font-size: 1.25rem;
}

.file-name {
  font-weight: 500;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, background 0.15s;
}

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

.btn-primary:hover {
  opacity: 0.9;
}

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

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--foreground);
}

.btn-outline:hover {
  background: var(--muted);
}

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

.btn-clear {
  align-self: flex-end;
}

/* Progress list */
.progress-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.015);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 0.875rem;
}

.progress-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--muted-foreground);
  flex-shrink: 0;
}

.progress-row.progress-pending .progress-dot {
  border-color: rgba(107, 114, 104, 0.4);
  background: transparent;
}

.progress-row.progress-processing .progress-dot {
  border-color: var(--primary);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.progress-row.progress-processing .progress-name {
  font-weight: 600;
}

.progress-row.progress-complete .progress-dot {
  border-color: var(--success);
  background: var(--success);
}

.progress-row.progress-error .progress-dot {
  border-color: var(--destructive);
  background: var(--destructive);
}

.progress-row.progress-pending .progress-name {
  color: var(--muted-foreground);
}

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

/* Status bar */
.status-bar {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 500;
  font-size: 0.95rem;
}

.status-bar.status-loading {
  color: var(--primary);
}

.status-bar.status-success {
  color: var(--success);
}

.status-bar.status-error {
  color: var(--destructive);
}

.status-bar::before {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-bar.status-loading::before {
  border: 2px solid var(--primary);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.status-bar.status-success::before {
  background: var(--success);
}

.status-bar.status-error::before {
  background: var(--destructive);
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: rgba(122, 154, 31, 0.1);
}

.stat-icon.warning {
  background: rgba(242, 163, 15, 0.12);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-value.warning {
  color: var(--warning);
}

.stat-value.success {
  color: var(--success);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted-foreground);
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem;
  background: var(--muted);
  border-radius: var(--radius);
  padding: 0.25rem;
  margin-top: 1.5rem;
}

.tab {
  border: none;
  background: transparent;
  padding: 0.5rem 1rem;
  border-radius: calc(var(--radius) - 1px);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted-foreground);
}

.tab.active {
  background: var(--card);
  color: var(--foreground);
}

.tab-content {
  margin-top: 1rem;
}

/* Order preview */
.preview-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.order-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.order-group-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--header);
  color: var(--header-foreground);
  padding: 0.5rem 1rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.order-group-header .badge {
  margin-left: auto;
  background: var(--primary);
  color: var(--primary-foreground);
  border-radius: var(--radius);
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.order-table-wrapper {
  overflow-x: auto;
}

.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.order-table th,
.order-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.order-table thead th {
  background: rgba(0, 0, 0, 0.02);
  font-weight: 600;
}

.order-table tbody tr:last-child td {
  border-bottom: none;
}

.order-table tr.row-warning {
  background: rgba(242, 163, 15, 0.05);
}

.cell-empty {
  color: rgba(107, 114, 104, 0.5);
}

.cell-uncertain {
  color: var(--warning);
  font-weight: 600;
}

.cell-bold {
  font-weight: 600;
  color: var(--primary);
}

.cell-note {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  white-space: normal;
}

.badge-e {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  border-radius: var(--radius);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0 0.3rem;
  margin-left: 0.25rem;
}

/* Downloads */
.downloads-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0;
}

.downloads-grid .btn {
  width: 100%;
  max-width: 320px;
}

/* Prompt editor */
.prompt-textarea {
  width: 100%;
  min-height: 480px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  resize: vertical;
  background: var(--card);
  color: var(--foreground);
  margin-top: 1rem;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
}

.editor-footer .actions {
  display: flex;
  gap: 0.5rem;
}

/* Auth: login */
.main-narrow {
  max-width: 420px;
  padding-top: 3rem;
  padding-bottom: 3rem;
}

.login-card h2 {
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.field input,
.checkbox-field input[type='text'] {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
}

.field input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.form-error {
  color: var(--destructive);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.btn-full {
  width: 100%;
}

/* API keys */
.new-key-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.new-key-form input {
  flex: 1;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
}

.new-key-result {
  margin-top: 1rem;
  border: 1px solid var(--border);
  background: var(--muted);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-size: 0.875rem;
}

.key-value {
  display: block;
  margin-top: 0.5rem;
  padding: 0.5rem 0.65rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  word-break: break-all;
}

.keys-list,
.users-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.key-name {
  font-weight: 500;
}

/* Users */
.new-user-form {
  margin-top: 1rem;
}

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

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

  .header-nav {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}
