:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: all 0.2s;
}

.nav-links a:hover {
  color: var(--primary);
  background-color: #f1f5f9;
}

.nav-links a.active {
  color: var(--primary);
  background-color: #eff6ff;
}

.nav-logout-form { display: inline; }

/* Login */
.login-page {
  background: #f5f7fb;
}

.login-page .navbar {
  display: none;
}

.login-page .nav-links {
  display: none;
}

.login-page .main-container {
  max-width: 760px;
  display: flex;
  align-items: center;
  margin: 0 auto;
  padding: clamp(3rem, 8vh, 6rem) clamp(1.25rem, 5vw, 4rem);
}

.login-layout {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.login-intro {
  max-width: 530px;
}

.login-mark {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 1.5rem;
  color: #fff;
  background: var(--primary);
  border-radius: 1rem;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.2);
}

.login-mark svg { width: 1.75rem; height: 1.75rem; }

.eyebrow {
  margin-bottom: 0.75rem;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.login-intro h1 {
  max-width: 300px;
  margin-bottom: 1rem;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.login-intro-copy {
  max-width: 260px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-card {
  width: min(100%, 400px);
  padding: clamp(1.75rem, 4vw, 2.5rem);
  background: #fff;
  border: 1px solid #e1e7f0;
  border-radius: 1rem;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

.login-card-heading { margin-bottom: 2rem; text-align: center; }
.login-card-heading h2 { margin-bottom: 0.4rem; font-size: 1.6rem; letter-spacing: -0.025em; text-align: center; }
.login-card-heading p { color: var(--text-muted); font-size: 0.92rem; text-align: center; }

.login-card .form-group { margin-bottom: 1.35rem; }
.login-card .form-input { min-height: 3rem; border-color: #cbd5e1; border-radius: 0.55rem; }
.login-card .form-input:focus { border-color: var(--primary); }
.field-heading { display: flex; justify-content: space-between; }
.login-submit { width: 100%; min-height: 3rem; margin-top: 0.35rem; border-radius: 0.55rem; }
.login-submit span { font-size: 1.2rem; line-height: 1; }
.form-error { margin-bottom: 1.25rem; color: var(--danger); font-size: 0.85rem; }

/* Dashboard */
.dashboard-page .main-container {
  max-width: 1180px;
}

/* Status page */
.status-page .main-container {
  max-width: 1180px;
}

.status-page .card {
  padding: 1.25rem;
}

.status-page .card-title {
  font-size: 1.1rem;
}

.status-page .card-subtitle {
  font-size: 0.82rem;
}

.status-page .stats-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.status-page .stat-box {
  min-width: 0;
  padding: 0.7rem 0.55rem;
}

.status-page .stat-value {
  overflow: hidden;
  margin-bottom: 0.15rem;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-page .stat-label {
  font-size: 0.65rem;
}

.status-page .progress-container {
  height: 8px;
  margin: 0.65rem 0;
}

.status-page .table-container {
  margin-top: 0.75rem;
}

.status-page th,
.status-page td {
  padding: 0.55rem 0.7rem;
}

.status-page .alert {
  margin-bottom: 0.85rem;
  padding: 0.7rem 0.9rem;
  font-size: 0.82rem;
}

/* New submission */
.submit-page .main-container {
  max-width: 920px;
}

.submission-card {
  max-width: 860px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.5rem);
}

.submission-card > h1 {
  margin-bottom: 0.4rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.03em;
}

.submission-card > .card-subtitle {
  margin-bottom: 2rem;
}

.submission-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.35rem 1.5rem;
}

.submission-form-grid .form-group {
  margin-bottom: 0;
}

.submission-form-grid .upload-field {
  grid-column: 1 / -1;
}

.submission-form-grid .form-input,
.submission-form-grid .form-file-input {
  min-height: 3rem;
}

.submission-form-grid .form-file-input {
  width: 100%;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 0.9rem;
}

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

.file-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 10rem;
  padding: 1.5rem;
  color: #64748b;
  background: #f8fafc;
  border: 1.5px dashed #b8c6d9;
  border-radius: 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.file-dropzone:hover,
.file-dropzone:focus-visible,
.file-dropzone.is-dragging {
  color: var(--primary);
  background: #eff6ff;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  outline: none;
}

.file-dropzone.has-file {
  background: #f0fdf4;
  border-color: #86efac;
}

.file-dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.file-dropzone-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.7rem;
  color: var(--primary);
  background: #dbeafe;
  border-radius: 0.7rem;
}

.file-dropzone-icon svg { width: 1.35rem; height: 1.35rem; }
.file-dropzone-copy { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; text-align: center; }
.file-dropzone-copy strong { color: #1e293b; font-size: 0.9rem; }
.file-dropzone-copy span { font-size: 0.78rem; }
.file-dropzone-copy em { display: inline-block; padding: 0.15rem 0.45rem; color: var(--primary); background: #dbeafe; border-radius: 0.3rem; font-style: normal; font-weight: 700; }
.file-selected { display: none; color: #15803d; font-size: 0.82rem; font-weight: 700; }
.file-dropzone.has-file .file-dropzone-copy { display: none; }
.file-dropzone.has-file .file-dropzone-icon { color: #15803d; background: #dcfce7; }
.file-dropzone.has-file .file-selected { display: block; }
.file-dropzone-error { min-height: 0; margin-top: 0.35rem; color: var(--danger); font-size: 0.8rem; font-weight: 600; }
.file-dropzone-error[hidden] { display: none; }

.submission-actions {
  display: block;
  margin-top: 2.25rem;
}

.submission-submit {
  width: 100%;
  min-height: 3.1rem;
}

.submission-actions #submitting-spinner {
  margin-top: 0.75rem;
  text-align: center;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.page-header h1 {
  margin-bottom: 0.35rem;
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  letter-spacing: -0.03em;
}

.eyebrow {
  margin-bottom: 0.4rem;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dashboard-summary .stat-box {
  text-align: left;
  padding: 1.15rem 1.25rem;
}

.stat-box-primary {
  border-color: #bfdbfe;
  background: #eff6ff;
}

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

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.section-heading .card-subtitle { margin-bottom: 0; }
.section-count {
  display: inline-grid;
  min-width: 2rem;
  height: 2rem;
  place-items: center;
  padding: 0 0.5rem;
  color: var(--primary);
  background: #eff6ff;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.active-submissions-list { display: grid; gap: 0.75rem; }

.active-submission {
  padding: 1rem 1.15rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
}

.active-submission-main,
.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.active-submission h3 { margin-bottom: 0.2rem; font-size: 0.98rem; }
.active-submission p { color: var(--text-muted); font-size: 0.82rem; }
.active-submission-progress { margin: 0.85rem 0 0.65rem; }
.progress-meta { margin-bottom: 0.3rem; color: var(--text-muted); font-size: 0.78rem; }
.progress-meta strong { color: var(--text-main); }
.active-submission .progress-container { height: 8px; margin: 0; }
.text-link { color: var(--primary); font-size: 0.82rem; font-weight: 600; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

.compact-empty { display: flex; flex-direction: column; gap: 0.25rem; padding: 1.5rem; }
.compact-empty strong { color: var(--text-main); }
.compact-empty span { font-size: 0.85rem; }

.section-heading-history { align-items: center; }
.bulk-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }
.selected-count { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }
.bulk-actions .btn:disabled { cursor: not-allowed; opacity: 0.45; }
.submissions-table td { vertical-align: middle; }
.table-secondary { display: block; margin-top: 0.15rem; color: var(--text-muted); font-size: 0.78rem; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a, .row-actions button { margin-left: 0.65rem; }
.nowrap { white-space: nowrap; }

.credits-section { padding: 0; overflow: hidden; }
.credits-summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.5rem; cursor: pointer; list-style: none; }
.credits-summary::-webkit-details-marker { display: none; }
.credits-summary::after { content: 'Show'; color: var(--primary); font-size: 0.82rem; font-weight: 700; }
.credits-section[open] .credits-summary::after { content: 'Hide'; }
.credits-summary > span:first-child { display: flex; flex-direction: column; gap: 0.2rem; }
.credits-summary strong { font-size: 1rem; }
.credits-summary small { color: var(--text-muted); font-size: 0.82rem; }
.credits-summary-balance { color: var(--primary); font-size: 0.85rem; font-weight: 700; }
.credits-content { padding: 0 1.5rem 1.5rem; }
.credit-stats { margin-bottom: 1.75rem; }
.subsection-title { margin: 1.5rem 0 0.75rem; font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .login-page .main-container { padding-top: 3rem; padding-bottom: 3rem; }

  .page-header { align-items: flex-start; flex-direction: column; }
  .dashboard-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading, .section-heading-history { align-items: flex-start; flex-direction: column; }
  .bulk-actions { justify-content: flex-start; width: 100%; }
  .status-page .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .navbar { padding: 0.85rem 1rem; }
  .nav-brand { font-size: 1rem; }
  .nav-links a, .nav-link-button { padding: 0.4rem 0.55rem; font-size: 0.85rem; }
  .dashboard-summary { gap: 0.65rem; }
  .dashboard-summary .stat-box { padding: 0.9rem; }
  .active-submission-main { align-items: flex-start; flex-direction: column; gap: 0.5rem; }
  .bulk-actions .btn { flex: 1; }
  .selected-count { width: 100%; }
  .credits-summary, .credits-content { padding-left: 1rem; padding-right: 1rem; }
  .submission-form-grid { grid-template-columns: 1fr; gap: 1.15rem; }
  .submission-form-grid .upload-field { grid-column: auto; }
  .status-page .card { padding: 1rem; }
  .status-page .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.nav-link-button {
  color: var(--text-muted);
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
}

.nav-link-button:hover {
  color: var(--primary);
  background-color: #f1f5f9;
}

.main-container {
  max-width: 1000px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
  flex: 1;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.375rem;
}

.form-input, .form-file-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  outline: none;
  background-color: #fff;
}

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

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

.error-text {
  font-size: 0.85rem;
  color: var(--danger);
  margin-top: 0.25rem;
  font-weight: 500;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease-in-out;
}

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

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

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

.btn-secondary:hover {
  background-color: #e2e8f0;
}

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

.btn-danger:hover {
  background-color: #b91c1c;
}

.link-button {
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.danger-link { color: var(--danger); }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 9999px;
  letter-spacing: 0.025em;
}

.badge-queued { background-color: #f1f5f9; color: #475569; }
.badge-processing { background-color: var(--info-bg); color: var(--info); animation: pulse 2s infinite; }
.badge-completed { background-color: var(--success-bg); color: var(--success); }
.badge-completed_with_errors { background-color: var(--warning-bg); color: var(--warning); }
.badge-failed { background-color: var(--danger-bg); color: var(--danger); }
.badge-cancelled { background-color: #f1f5f9; color: #94a3b8; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background-color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

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

/* Progress Bar */
.progress-container {
  width: 100%;
  height: 12px;
  background-color: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
  margin: 1rem 0;
}

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

/* Message Alert */
.alert {
  padding: 0.875rem 1.25rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-info { background-color: var(--info-bg); color: #0369a1; }
.alert-success { background-color: var(--success-bg); color: #15803d; }
.alert-warning { background-color: var(--warning-bg); color: #b45309; }
.alert-danger { background-color: var(--danger-bg); color: #b91c1c; }

/* Tables */
.table-container {
  overflow-x: auto;
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

th, td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

th {
  background-color: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
}

tr:hover {
  background-color: #f8fafc;
}

.empty-state {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
}

.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  background-color: #fff;
}
