/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f7f6f3;
  --surface:   #ffffff;
  --border:    #e2e0da;
  --text:      #1a1917;
  --muted:     #6b6860;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --success:   #16a34a;
  --error:     #dc2626;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --font:      'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg:        #111110;
  --surface:   #1c1c1a;
  --border:    #2e2e2b;
  --text:      #e8e6e1;
  --muted:     #908e87;
  --accent:    #3b82f6;
  --accent-h:  #60a5fa;
  --success:   #4ade80;
  --error:     #f87171;
  --shadow:    0 1px 4px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.6;
}

/* ── Header ───────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.header-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.header-inner .subtitle { flex: 1; }
.logo {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -.01em;
  text-decoration: none;
  color: inherit;
}
.subtitle {
  color: var(--muted);
  font-size: .9rem;
}

/* ── Main ─────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ── Hero ─────────────────────────────────────────────── */
.hero h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: .5rem;
}
.lead {
  color: var(--muted);
  max-width: 56ch;
}

/* ── Card ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

/* ── Form ─────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-bottom: 1.4rem;
}
label {
  font-weight: 600;
  font-size: .9rem;
}
input[type="email"],
input[type="text"],
input[type="date"],
select {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.hint {
  font-size: .8rem;
  color: var(--muted);
}

/* ── Drop Zone ────────────────────────────────────────── */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(37,99,235,.04);
}
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  pointer-events: none;
}
.drop-icon { font-size: 2rem; }
.drop-text { font-weight: 600; }
.drop-formats { font-size: .8rem; color: var(--muted); }

.file-name {
  margin-top: .5rem;
  font-size: .85rem;
  color: var(--success);
  font-weight: 500;
}
.hidden { display: none; }

/* ── Button ───────────────────────────────────────────── */
.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  padding: .7rem 1.6rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
  width: 100%;
  text-align: center;
  margin-top: .5rem;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  display: inline-block;
  padding: .75rem 1.75rem;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.btn-secondary:hover { background: var(--accent); color: #fff; }

.download-buttons {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: .5rem;
}

/* ── Upload Progress ──────────────────────────────────── */
.progress-container {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width .3s;
}
#progress-label { font-size: .85rem; color: var(--muted); }

/* ── Info Grid ────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.info-card h3 { font-size: .95rem; margin-bottom: .4rem; }
.info-card p  { font-size: .85rem; color: var(--muted); }

/* ── Status Page ──────────────────────────────────────── */
.status-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}
.status-icon { font-size: 3rem; }
.status-card h2 { font-size: 1.4rem; }

dl.job-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .3rem 1rem;
  text-align: left;
  font-size: .9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  width: 100%;
}
dl.job-meta dt { font-weight: 600; color: var(--muted); }
dl.job-meta dd code {
  font-family: monospace;
  font-size: .85rem;
  background: var(--border);
  padding: .1rem .35rem;
  border-radius: 4px;
}

.polling-note { font-size: .85rem; color: var(--muted); }
.error-msg    { font-size: .9rem; color: var(--error); }

.queue-info {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .65rem 1rem;
  font-size: .9rem;
  color: var(--muted);
  width: 100%;
  text-align: center;
}
.queue-info strong { color: var(--text); }
.queue-info.processing { border-color: var(--accent); color: var(--accent); }

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

/* ── Dark mode toggle ─────────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .3rem .55rem;
  cursor: pointer;
  font-size: .95rem;
  color: var(--muted);
  line-height: 1;
  transition: border-color .15s, color .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── Admin ────────────────────────────────────────────── */
.section-title { font-size: 1rem; font-weight: 700; margin-bottom: 1.25rem; }

.component-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: .75rem;
}
.component {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.component.ok    { border-color: #bbf7d0; background: #f0fdf4; }
.component.error { border-color: #fecaca; background: #fef2f2; }
.component.warn  { border-color: #fde68a; background: #fffbeb; }
[data-theme="dark"] .component.ok    { border-color: #166534; background: #052e16; }
[data-theme="dark"] .component.error { border-color: #991b1b; background: #2d0a0a; }
[data-theme="dark"] .component.warn  { border-color: #92400e; background: #1c1200; }
.component-icon  { font-size: 1.4rem; }
.component strong { display: block; font-size: .9rem; }
.component-detail { font-size: .8rem; color: var(--muted); }

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  text-align: center;
}
.stat { display: flex; flex-direction: column; gap: .2rem; }
.stat-num   { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--muted); }
.ok-num  .stat-num { color: var(--success); }
.err-num .stat-num { color: var(--error); }

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
}
.table-header .section-title { margin-bottom: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left;
  font-weight: 600;
  font-size: .8rem;
  color: var(--muted);
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
}
td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-done       { background: #dcfce7; color: #166534; }
.badge-failed     { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .badge-pending    { background: #1c1200; color: #fcd34d; }
[data-theme="dark"] .badge-processing { background: #0d1f3c; color: #93c5fd; }
[data-theme="dark"] .badge-done       { background: #052e16; color: #4ade80; }
[data-theme="dark"] .badge-failed     { background: #2d0a0a; color: #f87171; }

.link-small { font-size: .8rem; color: var(--accent); text-decoration: none; }
.link-small:hover { text-decoration: underline; }
.muted  { color: var(--muted); }
.small  { font-size: .8rem; }

/* ── Login ────────────────────────────────────────────── */
main:has(.login-card) {
  justify-content: center;
  align-items: center;
}

.login-card {
  width: 100%;
  max-width: 480px;
}

.login-card input[type="password"] {
  font-size: 1.1rem;
  padding: .75rem 1rem;
}

.login-card .btn-primary {
  width: 100%;
  padding: .75rem;
  font-size: 1rem;
}

.error-text {
  color: var(--error);
}

/* ── Logout Link ──────────────────────────────────────── */
.logout-link {
  font-size: .85rem;
  color: var(--muted);
  text-decoration: none;
}
.logout-link:hover {
  color: var(--text);
}

/* ── Admin ────────────────────────────────────────────── */
main.main--wide {
  max-width: 1400px !important;
  padding-left: 2rem;
  padding-right: 2rem;
}

.ram-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: .35rem 0 .25rem;
  overflow: hidden;
}
.ram-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .3s;
}

.section-subtitle {
  font-size: .8rem;
  font-weight: 400;
  color: var(--muted);
  margin-left: .5rem;
}

.perf-hint {
  margin-top: 1rem;
  font-size: .9rem;
  color: var(--muted);
}

.speed-hint {
  font-size: .75rem;
  color: var(--muted);
}

.actions-cell { white-space: nowrap; }

.btn-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  opacity: .5;
  padding: 0 .25rem;
  transition: opacity .15s;
}
.btn-delete:hover { opacity: 1; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 520px) {
  main { padding: 1.5rem 1rem; }
  .card { padding: 1.25rem; }
  .hero h1 { font-size: 1.4rem; }
}
