:root {
  color-scheme: light;
  --bg: #f6f2ea;
  --bg-accent: #f0e6d8;
  --ink: #1f1b16;
  --muted: #5e564d;
  --accent: #d14c3f;
  --accent-dark: #a93a31;
  --card: #fffaf2;
  --border: #e4d7c6;
  --shadow: 0 12px 30px rgba(31, 27, 22, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #ffffff 0%, var(--bg) 45%, #efe4d4 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--accent), #f7b267);
  box-shadow: var(--shadow);
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.4px;
}

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
}

.nav {
  display: flex;
  gap: 20px;
  font-weight: 600;
}

.nav a {
  padding: 6px 10px;
  border-radius: 999px;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav a:hover {
  background: var(--bg-accent);
  color: var(--accent-dark);
}

.user {
  font-size: 0.9rem;
  color: var(--muted);
}

.container {
  width: min(1200px, 92vw);
  margin: 32px auto 40px;
  flex: 1;
}

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

.page-header h1 {
  margin: 0 0 6px;
  font-size: 2rem;
}

.muted {
  color: var(--muted);
}

.actions,
.filters {
  display: flex;
  gap: 12px;
  align-items: center;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.refresh-countdown {
  font-size: 0.82rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn.loading {
  opacity: 0.8;
  pointer-events: none;
  padding-right: 34px;
  position: relative;
}

.btn.loading::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
}

.stat-card.loading {
  opacity: 0.75;
}

.stat-card.loading::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 14px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-meta {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-body {
  padding: 16px 20px 20px;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.config-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.config-item {
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.config-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.config-value {
  font-weight: 700;
}

.api-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.api-row:last-child {
  border-bottom: none;
}

.table-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.table th,
.table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

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

.action-select {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.85rem;
}

.link {
  color: var(--accent);
  text-decoration: none;
}

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

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-accent);
}

#batch-detail {
  margin-top: 24px;
}

.flash {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: #f1f0ea;
  border: 1px dashed var(--border);
  display: none;
  position: sticky;
  top: 84px;
  z-index: 5;
}

.flash.show {
  display: block;
}

.footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 0.85rem;
}

.user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.logout {
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  transition: all 0.2s ease;
}

.logout:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.login-wrap {
  display: flex;
  justify-content: center;
  padding: 40px 0 20px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0 0 6px;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.login-form input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.95rem;
}

.login-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #ffe7e2;
  border: 1px solid #d14c3f;
  color: #8c2b22;
  font-size: 0.9rem;
}

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

select {
  border-radius: 999px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--card);
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .nav {
    flex-wrap: wrap;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .actions-stack {
    align-items: flex-start;
  }
  .actions {
    flex-wrap: wrap;
  }
}
