:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #171717;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b91c1c;
  --warning: #b45309;
  --ok: #047857;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 16px; }
p { color: var(--muted); margin-top: 6px; }

.actions, .filters, .pager, .panel-head, .form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 650;
  white-space: nowrap;
}

.btn:hover { filter: brightness(0.98); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn.secondary { background: #fff; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 14px 16px;
}

.metric span, .label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.panel {
  padding: 16px;
  margin-bottom: 12px;
}

.status-panel {
  display: grid;
  grid-template-columns: 1fr 160px 100px auto auto auto;
  align-items: center;
  gap: 14px;
}

.worker-state, .cooldown, #rateCount {
  margin-top: 5px;
  font-weight: 700;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(380px, 0.9fr) minmax(480px, 1.1fr);
  gap: 12px;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

label {
  display: block;
  color: #374151;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  color: var(--text);
  background: #fff;
  margin-top: 6px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.form-row > label { flex: 1; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
}

.check input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin: -4px 0 10px;
}

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

.filters input { width: 320px; }
.filters select { width: 150px; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  min-width: 1120px;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  color: #374151;
  z-index: 1;
}

.thumb {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.status-success { color: var(--ok); background: #d1fae5; }
.status-failed { color: var(--danger); background: #fee2e2; }
.status-retry_wait { color: var(--warning); background: #fef3c7; }
.status-processing { color: #1d4ed8; background: #dbeafe; }
.status-pending { color: #475569; background: #e2e8f0; }

.clamp {
  max-width: 340px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.pager {
  justify-content: flex-end;
  margin-top: 12px;
}

.events {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.event {
  display: grid;
  grid-template-columns: 150px 80px 1fr;
  gap: 10px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  padding: 12px 14px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform: translateY(120px);
  opacity: 0;
  transition: 0.2s ease;
  max-width: 460px;
  z-index: 20;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.42);
  z-index: 100;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
  padding: 22px;
}

.auth-card h2 {
  font-size: 20px;
}

.auth-card label {
  margin-top: 18px;
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  margin: 4px 0 12px;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .topbar, .table-toolbar { flex-direction: column; align-items: stretch; }
  .actions, .filters { flex-wrap: wrap; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .status-panel { grid-template-columns: 1fr; }
  .grid-two { grid-template-columns: 1fr; }
  .filters input, .filters select { width: 100%; }
}
