:root {
  --primary: #667eea;
  --primary-dark: #5a6fd6;
  --secondary: #764ba2;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  --text-main: #2d3748;
  --text-muted: #718096;
  --text-light: #a0aec0;

  --bg-card: #ffffff;
  --bg-input: #f7fafc;

  --border-light: #e2e8f0;

  --shadow-card: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-header: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  --radius-card: 16px;
  --radius-input: 8px;

  --danger-bg: #fff5f5;
  --danger-text: #e53e3e;
  --success-bg: #f0fff4;
  --success-text: #38a169;
  --warn-bg: #fffaf0;
  --warn-text: #dd6b20;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-gradient) fixed;
  /* Fixed gradient to prevent weird scrolling cuts */
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  padding: 20px 0 40px 0;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s;
}

a:hover {
  color: var(--primary-dark);
}

/* Layout Containers */
/* The layout uses .topbar > .container and main.container */
.container {
  width: min(1000px, 94vw);
  margin: 0 auto;
  padding: 0;
}

/* Floating Header Card style */
.topbar {
  margin-bottom: 24px;
}

.topbar .container {
  background: white;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-header);
  padding: 20px 30px;
  display: flex;
  align-items: center;
}

.topbar-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 15px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navlink {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: var(--radius-input);
}

.navlink:hover {
  background: #f7fafc;
  color: var(--primary);
}

/* Main Content */
main.container {
  /* main container itself is transparent, holding cards */
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Cards (Content Blocks) */
.card {
  background: white;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 30px;
  border: none;
  /* No border for cleaner look */
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2d3748;
  margin: 0 0 20px 0;
  border-bottom: 2px solid #edf2f7;
  padding-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: #4a5568;
  margin: 0 0 10px 0;
}

/* Helpers */
.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.875rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 8px;
  line-height: 1.5;
}

/* Forms */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

input,
select {
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-input);
  background: #fff;
  color: var(--text-main);
  font-size: 0.95rem;
  transition: border 0.2s, box-shadow 0.2s;
  min-width: 0;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 6px rgba(102, 126, 234, 0.25);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(102, 126, 234, 0.35);
}

button:active {
  transform: translateY(0);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid #e2e8f0;
  box-shadow: none;
}

.btn-ghost:hover {
  background: #f7fafc;
  color: var(--text-main);
  border-color: #cbd5e0;
  transform: none;
  box-shadow: none;
}

.btn-danger {
  background: white;
  color: var(--danger-text);
  border: 1px solid #fed7d7;
  box-shadow: none;
}

.btn-danger:hover {
  background: #fff5f5;
  border-color: #fc8181;
  color: #c53030;
  transform: none;
  box-shadow: 0 2px 4px rgba(229, 62, 62, 0.1);
}

.link-danger {
  background: none;
  border: none;
  padding: 0;
  color: var(--danger-text);
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: none;
}

.link-danger:hover {
  text-decoration: underline;
}

/* File Upload */
.filebtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: #f8fafc;
  border: 2px dashed #cbd5e0;
  border-radius: var(--radius-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  position: relative;
  min-width: 140px;
}

.filebtn:hover {
  border-color: var(--primary);
  background: #ebf4ff;
  color: var(--primary);
}

.fileinput {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Document Grid */
.docs {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.doc {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-card);
  padding: 20px;
  display: flex;
  gap: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.doc:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border-color: #cbd5e0;
}

.thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 12px;
  background: #edf2f7;
}

.doc-thumb.thumb-missing {
  width: 80px;
  height: 80px;
  background: #edf2f7;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-size: 12px;
  color: #a0aec0;
  text-align: center;
}

.doc-link {
  font-size: 0.9rem;
  margin-right: 12px;
  font-weight: 500;
}

/* Pills & Status */
.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.pill-queued,
.pill-pending {
  background: #feebc8;
  color: #c05621;
}

.pill-running {
  background: #bee3f8;
  color: #2b6cb0;
}

.pill-done {
  background: #c6f6d5;
  color: #276749;
}

.pill-failed {
  background: #fed7d7;
  color: #9b2c2c;
}

/* Progress */
.upload-progress-box {
  margin-top: 20px;
  padding: 15px;
  background: #f7fafc;
  border-radius: var(--radius-input);
}

.progress-bar-track {
  height: 8px;
  background: #cbd5e0;
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  transition: width 0.2s;
}

/* Alert */
.alert {
  padding: 16px;
  border-radius: var(--radius-input);
  margin-bottom: 20px;
}

.alert-error {
  background: #fff5f5;
  color: #c53030;
  border: 1px solid #feb2b2;
}

/* Modal */
.modal-backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(5px);
}

.modal-content {
  background: white;
  border-radius: 20px;
  border: none;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-bar {
  padding: 20px;
  border-bottom: 1px solid #edf2f7;
}

.modal-footer {
  padding: 20px;
  background: #f7fafc;
  border-top: 1px solid #edf2f7;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 10px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-light);
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0;
}

.table th,
.table td {
  padding: 12px 16px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
}

.table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.table tbody tr:hover td {
  background: #fcfcfc;
}

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

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.cell-actions {
  width: 1%;
  white-space: nowrap;
}

.cell-ocr {
  max-width: 300px;
  word-break: break-word;
  font-size: 0.85rem;
}
/* Code Blocks */
.pre {
  background: #2d3748;
  color: #f7fafc;
  padding: 20px;
  border-radius: 12px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow: auto;
}

@media (max-width: 640px) {
  body { padding: 10px 0; }
  .container { width: 95vw; }
  .topbar .container { padding: 15px; flex-direction: column; gap: 15px; }
  .topbar-row { justify-content: center; }
  .topbar-left { justify-content: center; }
  .card { padding: 20px; }
  .docs { grid-template-columns: 1fr; }
}
