:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --ok: #10b981;
  --ok-bg: #ecfdf5;
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --info-bg: #e0f2fe;
  --info-text: #0369a1;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="dark"] {
  --bg: #090d16;
  --card: #131b2e;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #1e293b;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-glow: rgba(129, 140, 248, 0.2);
  --danger: #f87171;
  --danger-bg: #2d191b;
  --ok: #34d399;
  --ok-bg: #11261f;
  --warn: #fbbf24;
  --warn-bg: #2b2013;
  --info-bg: #0d2231;
  --info-text: #38bdf8;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; transition: background-color 0.3s ease, color 0.3s ease; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 14px 16px 30px; display: flex; flex-direction: column; gap: 12px; }
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top right, var(--accent-glow), transparent 40%), radial-gradient(circle at bottom left, var(--accent-glow), transparent 40%), var(--bg);
}
.login-card {
  width: min(440px, 100%);
  padding: 32px;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}
.login-card h1 {
  margin-top: 0;
  margin-bottom: 24px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.025em;
  text-align: center;
}
.login-error {
  display: none;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.login-error.open { display: block; }
.app-shell { display: none; }
body.authenticated .login-screen { display: none; }
body.authenticated .app-shell { display: flex; }
.top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.top h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
  font-weight: 400;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.auth { display: grid; gap: 16px; }
.nav {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  align-self: flex-start;
}
.nav button {
  height: 32px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 13px;
  font-weight: 600;
  border-radius: calc(var(--radius-md) - 2px);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.nav button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.4);
}
[data-theme="dark"] .nav button:hover {
  background: rgba(255, 255, 255, 0.05);
}
.nav button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.logout-btn {
  background: var(--danger-bg) !important;
  color: var(--danger) !important;
  border: 1px solid rgba(239, 68, 68, 0.2) !important;
}
.logout-btn:hover {
  background: var(--danger) !important;
  color: #ffffff !important;
  border-color: var(--danger) !important;
}
.view { display: none; }
.view.open { display: block; animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
input, select, button {
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
input, select {
  padding: 0 14px;
  background: var(--card);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
button {
  padding: 0 20px;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
}
button:active {
  transform: translateY(0);
}
button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
button.secondary:hover {
  background: var(--line);
  border-color: var(--line);
  transform: none;
}
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.filters select, .filters input {
  height: 32px;
  width: auto;
  min-width: 130px;
  font-size: 13px;
}
.filters button {
  height: 32px;
  padding: 0 14px;
  font-size: 13px;
}
.toolbar-group {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--line);
  flex-shrink: 0;
}
.field-label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}
.form-message {
  margin-top: 10px;
  font-size: 13px;
}
.form-message-error { color: var(--danger); }
.form-message-success { color: var(--success); }
#addTokenForm input[type="url"] {
  width: 100%;
}
.tabs {
  display: flex;
  gap: 16px;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tabs button {
  height: 38px;
  padding: 0 2px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tabs button:hover {
  color: var(--text);
  border-bottom-color: var(--line);
}
.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1;
}
.tab-badge:empty {
  display: none;
}
.tab-badge.info { background: var(--info-bg); color: var(--info-text); }
.tab-badge.warning { background: var(--warn-bg); color: var(--warn); }
.tab-badge.danger { background: var(--danger-bg); color: var(--danger); }
.tab-badge.ok { background: var(--ok-bg); color: var(--ok); }
.tab-badge.muted { background: var(--line); color: var(--muted); }

.nav-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  line-height: 1;
  background: var(--warn-bg);
  color: var(--warn);
  margin-left: 4px;
  vertical-align: middle;
}
.nav button {
  position: relative;
}
@media (max-width: 768px) {
  .nav-badge {
    position: absolute;
    top: 4px;
    right: 12%;
    margin-left: 0;
    font-size: 9px;
    padding: 1px 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
}

.token-requests {
  border-top: 1px solid var(--line);
  background: var(--warn-bg);
}
.token-generation-alert {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
}
.token-generation-title {
  font-weight: 700;
  color: var(--warn);
}
.token-request-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px 12px;
}
.token-request-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}
.token-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.token-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.token-cell code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}
.btn-copy.copied {
  color: var(--ok);
  border-color: rgba(16, 185, 129, 0.35);
  background: var(--ok-bg);
}

.stats {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.table-wrap {
  overflow-x: auto;
  background: var(--card);
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1120px;
}
.panel table { min-width: auto; }
th, td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}
th {
  background: var(--card);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid var(--line);
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: var(--bg);
}
.fio {
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
}
.muted {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.btn-data, .btn-danger, .btn-edit, .btn-approve {
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s ease;
}
.btn-data {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-data:hover {
  background: var(--line);
  border-color: var(--line);
  transform: none;
}
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
  transform: none;
}
.btn-edit {
  height: 32px;
  padding: 0 10px;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid rgba(245, 158, 11, 0.2);
  font-size: 12px;
}
.btn-placeholder { visibility: hidden; pointer-events: none; }
.btn-approve {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid rgba(16, 185, 129, 0.2);
}
.btn-approve:hover {
  background: var(--ok);
  color: #ffffff;
  transform: none;
}
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  height: 26px;
  min-height: 26px;
  max-height: 26px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
  transition: all 0.2s ease;
  cursor: pointer;
}
.btn-secondary:hover {
  background: var(--line);
  transform: none;
}

/* Priority table action grid */
.priority-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: 176px;
  align-items: stretch;
}

.priority-actions-grid button,
.priority-actions-grid .claim-badge {
  height: 26px;
  min-height: 26px;
  max-height: 26px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  white-space: nowrap;
  line-height: 1;
  text-align: center;
}

.priority-actions-grid button {
  cursor: pointer;
}

.priority-actions-grid button:hover {
  transform: none;
}

.priority-actions-grid .claim-badge {
  cursor: default;
}

/* Claim badges */
.claim-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  min-height: 26px;
  max-height: 26px;
  padding: 0 6px;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  gap: 4px;
  line-height: 1;
}
.claim-bot {
  background: rgba(99, 102, 241, 0.12);
  color: #6366f1;
  border: 1px solid rgba(99, 102, 241, 0.25);
}
.claim-mine {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid rgba(16, 185, 129, 0.25);
}
.claim-other {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

/* Row tints for claimed applicants */
tr.row-claimed-bot   { background: rgba(99, 102, 241, 0.05); }
tr.row-claimed-mine  { background: rgba(16, 185, 129, 0.06); }
tr.row-claimed-other { background: rgba(245, 158, 11, 0.07); opacity: 0.8; }

.status-select {
  height: 26px;
  padding: 0 22px 0 8px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--line);
  font-weight: 600;
  cursor: pointer;
  width: auto;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 12px;
  box-sizing: border-box;
}
[data-theme="dark"] .status-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
}
.status-select:focus {
  border-color: var(--accent);
}
.status-select.ready { background-color: var(--ok-bg); color: var(--ok); border-color: rgba(16, 185, 129, 0.2); }
.status-select.walk { background-color: var(--warn-bg); color: var(--warn); border-color: rgba(245, 158, 11, 0.2); }
.status-select.error { background-color: var(--danger-bg); color: var(--danger); border-color: rgba(239, 68, 68, 0.2); }
.status-select.booked { background-color: var(--info-bg); color: var(--info-text); border-color: rgba(14, 165, 233, 0.2); }
.status-select.lockdown { background-color: var(--line); color: var(--muted); border-color: rgba(148, 163, 184, 0.2); }
.status-select option, select option {
  background-color: var(--card);
  color: var(--text);
}

.reschedule-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  border: 1px solid var(--line);
  padding: 0 8px;
  border-radius: var(--radius-sm);
  height: 26px;
  background: var(--bg);
  transition: all 0.2s ease;
}
.reschedule-label:hover {
  border-color: var(--accent);
}
.reschedule-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
  margin: 0;
}
.reschedule-label:has(input:checked) {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

.paid-cell {
  text-align: center;
  vertical-align: middle;
}
.paid-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0;
}
.paid-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

.priority-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0;
  gap: 3px;
}
.priority-label input[type="checkbox"] {
  accent-color: #f59e0b;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: transparent;
  border: none;
  box-shadow: none;
}
.priority-label .vip-star {
  font-size: 13px;
  line-height: 1;
  user-select: none;
}

.edit-dates-label {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 12px;
}
.buffer-picker {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
}
.buffer-picker input {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
.buffer-step {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.buffer-step:hover { background: var(--accent-glow); }
.buffer-step:active { transform: translateY(1px) scale(0.96); }
.month-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  margin-right: 8px;
  background: var(--bg);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}
.month-row input[type="month"],
.month-row select {
  height: 32px;
  font-size: 13px;
  width: auto;
  min-width: 140px;
  padding: 0 8px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.month-row .btn-remove {
  height: 24px;
  width: 24px;
  padding: 0;
  background: transparent;
  color: var(--danger);
  border: none;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: all 0.2s ease;
}
.month-row .btn-remove:hover {
  background: var(--danger-bg);
}

.date-range-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
  width: 100%;
}
.date-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.date-input-group label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.date-input-group input[type="date"] {
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
  font-family: var(--font);
  width: 100%;
}
.date-input-group input[type="date"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.btn-remove-range {
  height: 40px;
  width: 40px;
  min-width: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-remove-range:hover {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
  transform: none;
}
.settings { padding: 24px; }
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 24px; }
@media (min-width: 768px) {
  .settings-grid { grid-template-columns: 1fr auto; align-items: end; }
}
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; padding: 10px; }
.summary-box { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 8px 12px; background: var(--bg); }
.summary-value { font-size: 18px; font-weight: 800; margin-top: 2px; color: var(--accent); }
.month-list { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.ready { color: var(--ok); background-color: var(--ok-bg); }
.walk { color: var(--warn); background-color: var(--warn-bg); }
.error { color: var(--danger); background-color: var(--danger-bg); }
.booked { color: var(--info-text); background-color: var(--info-bg); }
.lockdown { color: var(--muted); background-color: var(--line); }

a { color: var(--accent); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }
.empty, .err { padding: 40px; text-align: center; color: var(--muted); font-size: 15px; font-weight: 500; }
.err { color: var(--danger); }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}
.modal.open { display: flex; }
.panel {
  width: min(760px, 100%);
  background: var(--card);
  max-height: 90vh;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--modal-shadow);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.panel-head {
  position: sticky;
  top: 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}
.panel-head > div:first-child { min-width: 0; }
.panel-head h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.panel-body { padding: 20px; overflow-y: auto; flex: 1; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#editDatesModal {
  z-index: 60;
}
.panel-foot {
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: var(--card);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}
.panel-close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.panel-close-btn:hover {
  background: var(--line);
  color: var(--text);
  transform: none;
}
#detailsModal .panel { width: min(1000px, 100%); }
#detailsModal .panel-head > div:first-child { flex: 1; }
#detailsModal .panel-actions { flex: 0 0 auto; flex-wrap: nowrap; justify-content: flex-end; }
#detailsModal .panel-actions button { white-space: nowrap; }
.detail-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 16px;
}
.detail-grid div { padding: 12px 16px; background: var(--card); font-size: 14px; line-height: 1.5; }
.detail-grid div:nth-child(odd) { background: var(--bg); color: var(--muted); font-weight: 600; }
.detail-grid div:nth-last-child(-n+2) { border-bottom: none; }
.queue-list { border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; background: var(--card); }
.queue-row { display: flex; justify-content: space-between; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.queue-row:last-child { border-bottom: none; }
.queue-row span:last-child { font-weight: 700; color: var(--accent); }
.queue-hint { margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* Sun & Moon theme icons toggle */
.sun-icon { display: block; }
.moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none !important; }
[data-theme="dark"] .moon-icon { display: block !important; }

@media (min-width: 769px) {
  #sortByBookedAtBtn {
    display: none !important;
  }

  #homeView .table-wrap {
    overflow-x: auto;
  }

  #homeView .applicants-table {
    min-width: 1140px;
    width: 100%;
    table-layout: fixed;
  }

  #homeView .applicants-table th,
  #homeView .applicants-table td {
    padding: 5px 6px;
    white-space: normal;
    overflow-wrap: anywhere;
    vertical-align: middle;
    font-size: 12px;
    line-height: 1.25;
  }


  #homeView .applicants-table th {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    white-space: nowrap;
    text-transform: uppercase;
    color: var(--muted);
    text-align: left;
  }

  #homeView .applicants-table .col-id { width: 34px; }
  #homeView .applicants-table th.col-id,
  #homeView .applicants-table td.col-id {
    padding-left: 2px;
    padding-right: 2px;
    text-align: center;
  }
  #homeView .applicants-table .col-applicant { width: 140px; }
  #homeView .applicants-table .col-count { width: 38px; text-align: center; }
  #homeView .applicants-table th.col-count,
  #homeView .applicants-table td.col-count {
    text-align: center;
  }
  #homeView .applicants-table .col-city { width: 90px; }
  #homeView .applicants-table .col-status { width: 116px; }
  #homeView .applicants-table .col-booked-at { width: 96px; }
  #homeView .applicants-table .col-contacts { width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #homeView .applicants-table .col-contacts a { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
  #homeView .applicants-table .col-dates { width: 145px; }
  #homeView .applicants-table .col-buffer { width: 50px; text-align: center; }
  #homeView .applicants-table th.col-buffer,
  #homeView .applicants-table td.col-buffer {
    text-align: center;
  }
  #homeView .applicants-table .col-form { width: 75px; white-space: nowrap; }
  #homeView .applicants-table .col-priority { width: 34px; padding-left: 1px; padding-right: 1px; text-align: center; }
  #homeView .applicants-table th.col-priority,
  #homeView .applicants-table td.col-priority {
    text-align: center;
  }
  #homeView .applicants-table .col-paid { width: 58px; padding-left: 1px; padding-right: 1px; text-align: center; }
  #homeView .applicants-table th.col-paid,
  #homeView .applicants-table td.col-paid {
    text-align: center;
  }
  #homeView .applicants-table .col-actions { width: 126px; }
  #homeView .applicants-table .col-status-time { width: 78px; }
  #homeView .applicants-table .col-created { width: 70px; }
  #homeView .applicants-table .col-deleted { width: 70px; }

  #homeView .applicants-table .fio {
    font-size: 12px;
    line-height: 1.3;
  }

  #homeView .applicants-table .col-applicant .muted,
  #homeView .applicants-table .col-contacts .muted,
  #homeView .applicants-table .col-status .muted {
    font-size: 10px;
    line-height: 1.3;
  }

  #homeView .applicants-table .time-muted {
    font-size: 10px;
    color: #888;
    line-height: 1.3;
  }

  #homeView .applicants-table td.col-created,
  #homeView .applicants-table td.col-status-time,
  #homeView .applicants-table td.col-deleted {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
  }

  #homeView .applicants-table .col-contacts .muted,
  #homeView .applicants-table .col-created .muted {
    display: none;
  }

  #homeView .applicants-table .col-form .muted {
    font-size: 10px;
    line-height: 1.2;
    margin-top: 1px;
  }

  #homeView .applicants-table .col-status .status-select {
    width: 100%;
    max-width: 100%;
    font-size: 10px;
    padding: 0 18px 0 6px;
    height: 24px;
  }

  #homeView .applicants-table .col-form a {
    white-space: nowrap;
    font-size: 11px;
  }

  #homeView .applicants-table .booked-date {
    font-size: 11px;
  }

  #homeView .applicants-table th.col-actions,
  #homeView .applicants-table td.col-actions {
    text-align: left;
    padding-left: 4px;
    padding-right: 4px;
  }

  #homeView .applicants-table .col-actions .actions {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    width: fit-content;
    max-width: 100%;
  }

  #homeView .applicants-table .col-actions .actions button {
    width: 20px;
    min-width: 20px;
    height: 20px;
    padding: 0;
    justify-content: center;
    flex: 0 0 20px;
  }

  #homeView .applicants-table .col-actions .actions button span,
  #homeView .applicants-table .col-actions .reschedule-label span {
    display: none;
  }

  #homeView .applicants-table .col-actions .reschedule-label {
    justify-content: center;
    padding: 0;
    width: 20px;
    min-width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  #homeView .applicants-table th.col-priority,
  #homeView .applicants-table th.col-paid {
    text-align: center;
  }

  #homeView .applicants-table .col-priority.priority-cell,
  #homeView .applicants-table .col-paid.paid-cell {
    text-align: center;
    vertical-align: middle;
  }

  #homeView .applicants-table .col-priority .priority-label,
  #homeView .applicants-table .col-paid .paid-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    cursor: pointer;
  }

  #homeView .applicants-table .col-priority .vip-badge {
    margin-left: 2px;
    font-size: 11px;
  }

  #homeView .applicants-table .col-actions .btn-placeholder {
    display: none;
  }
}

@media (max-width: 768px) {
  /* ── Page shell & Padding adjustment for bottom nav ── */
  .wrap {
    padding: 12px 14px calc(76px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  /* ── Top Header ── */
  .top {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    gap: 8px;
  }
  .top > div:first-child {
    min-width: 0;
    flex: 1;
  }
  .top h1 {
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .top .sub {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .top button.logout-btn span {
    display: none;
  }
  .top button.logout-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-md);
  }

  /* ── Bottom Navigation Bar (iOS Tab Bar style) ── */
  .nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-around;
    align-self: auto;
    width: 100%;
    margin: 0;
    border-radius: 0;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
  }
  [data-theme="dark"] .nav {
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
    background: rgba(19, 27, 46, 0.95);
  }
  .nav button {
    flex: 1;
    flex-direction: column;
    height: auto;
    padding: 4px 2px;
    gap: 4px;
    font-size: 10px;
    border-radius: var(--radius-sm);
    text-align: center;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: var(--muted) !important;
  }
  .nav button.active {
    color: var(--accent) !important;
    background: transparent !important;
  }
  .nav button i {
    width: 20px !important;
    height: 20px !important;
  }
  .nav button span {
    display: block;
  }

  /* ── Toolbars, Filters & Stats ── */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    gap: 8px;
  }
  .filters {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
    margin-bottom: 0;
  }
  /* Override general input styling to make 2 columns */
  .filters select, .filters input, .filters button {
    width: calc(50% - 4px) !important;
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  /* Stats styled as a clean centered badge */
  .stats {
    font-size: 12px;
    padding: 6px 10px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    margin-top: 4px;
    justify-content: center;
    text-align: center;
    width: 100%;
  }

  /* ── Table-to-Card Transformations ── */
  .table-wrap {
    background: transparent;
    padding: 0;
    overflow-x: visible; /* Disable horizontal overflow scroll */
  }
  .table-wrap table {
    min-width: 100% !important;
    display: block;
    border-spacing: 0;
  }
  .table-wrap table thead {
    display: none;
  }
  .table-wrap table tbody {
    display: block;
  }
  .table-wrap table tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    position: relative;
    box-sizing: border-box;
  }
  .table-wrap table tr:hover td {
    background: transparent;
  }
  .table-wrap table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border: none;
    border-bottom: 1px dashed var(--line);
    min-height: 38px;
    box-sizing: border-box;
    text-align: right;
  }
  .table-wrap table td:last-child {
    border-bottom: none;
  }
  .table-wrap table td > * {
    text-align: right;
  }
  .table-wrap table td::before {
    font-weight: 700;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    margin-right: 12px;
    flex-shrink: 0;
  }

  /* ── Home Table Card Layout (Normal Tabs) ── */
  #rows td:nth-child(1) {
    position: absolute;
    top: 14px;
    right: 16px;
    border: none;
    padding: 0;
    width: auto !important;
    min-height: auto;
    font-weight: 700;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
  }
  #rows td:nth-child(1)::before {
    content: "#";
    margin-right: 1px;
  }
  #rows td:nth-child(2) {
    display: block;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
    margin-bottom: 6px;
    text-align: left;
    min-height: auto;
  }
  #rows td:nth-child(2)::before {
    display: none;
  }
  #rows td:nth-child(2) > * {
    text-align: left;
  }
  #rows td:nth-child(2) .fio {
    font-size: 15px;
    font-weight: 800;
    margin-right: 60px; /* Leave space for the absolute positioned ID badge */
  }
  #rows td:nth-child(3)::before { content: "Чел."; }
  #rows td:nth-child(4)::before { content: "Город"; }
  #rows td:nth-child(5)::before { content: "Статус"; }
  #rows td:nth-child(6)::before { content: "Контакты"; }
  #rows td:nth-child(7)::before { content: "Даты записи"; }
  #rows td:nth-child(8)::before { content: "Запас"; }
  #rows td:nth-child(9)::before { content: "Анкета"; }
  #rows td:nth-child(10) {
    display: block !important;
    border-top: 1px solid var(--line);
    border-bottom: none;
    padding-top: 12px;
    margin-top: 6px;
    width: 100% !important;
    min-height: auto;
  }
  #rows td:nth-child(10)::before {
    display: none !important;
  }
  #rows td:nth-child(10) .actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
  }
  #rows td:nth-child(10) .actions > * {
    flex: 1 1 calc(50% - 4px) !important;
    height: 34px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    font-size: 11px !important;
  }
  #rows td:nth-child(11)::before { content: "Создана"; }

  /* ── Home Table Card Layout (Booked Tab Column Shift) ── */
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(6)::before { content: "Дата зап."; }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(7)::before { content: "Контакты"; }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(8)::before { content: "Даты записи"; }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(9)::before { content: "Запас"; }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(10)::before { content: "Анкета"; }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(10) {
    display: flex !important;
    border-top: none;
    border-bottom: 1px dashed var(--line);
    padding-top: 8px;
    margin-top: 0;
    min-height: 38px;
  }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(11) {
    display: block !important;
    border-top: 1px solid var(--line);
    border-bottom: none;
    padding-top: 12px;
    margin-top: 6px;
    width: 100% !important;
    min-height: auto;
  }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(11)::before {
    display: none !important;
  }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(11) .actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
  }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(11) .actions > * {
    flex: 1 1 calc(50% - 4px) !important;
    height: 34px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    font-size: 11px !important;
  }
  #homeView:has(#bookedTabBtn.active) #rows td:nth-child(12)::before { content: "Создана"; }

  /* ── Tokens Table Card Layout ── */
  #tokenRows td:nth-child(1) {
    display: block;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
    margin-bottom: 6px;
    text-align: left;
    min-height: auto;
    font-size: 15px;
    font-weight: 800;
  }
  #tokenRows td:nth-child(1)::before {
    display: none;
  }
  #tokenRows td:nth-child(1) > * {
    text-align: left;
  }
  #tokenRows td:nth-child(2)::before { content: "Токен"; }
  #tokenRows td:nth-child(2) .token-cell {
    justify-content: flex-end;
    width: 100%;
  }
  #tokenRows td:nth-child(3)::before { content: "Создан"; }
  #tokenRows td:nth-child(4)::before { content: "Капча обн."; }
  #tokenRows td:nth-child(5)::before { content: "Капча до"; }
  #tokenRows td:nth-child(6)::before { content: "Прокси IP"; }
  #tokenRows td:nth-child(7)::before { content: "Возраст"; }
  #tokenRows td:nth-child(8) {
    position: absolute;
    top: 14px;
    right: 16px;
    border: none;
    padding: 0;
    width: auto !important;
    min-height: auto;
    display: flex;
    align-items: center;
  }
  #tokenRows td:nth-child(8)::before {
    display: none;
  }
  #tokenRows td:nth-child(9) {
    display: block !important;
    border-top: 1px solid var(--line);
    border-bottom: none;
    padding-top: 12px;
    margin-top: 6px;
    width: 100% !important;
    min-height: auto;
  }
  #tokenRows td:nth-child(9)::before {
    display: none !important;
  }
  #tokenRows td:nth-child(9) button {
    width: 100% !important;
    height: 36px !important;
  }

  /* ── Batch Preview Table Card Layout ── */
  #batchResultsContainer tbody td:nth-child(1) {
    position: absolute;
    top: 14px;
    right: 16px;
    border: none;
    padding: 0;
    width: auto !important;
    min-height: auto;
    font-weight: 700;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
  }
  #batchResultsContainer tbody td:nth-child(1)::before {
    content: "#";
  }
  #batchResultsContainer tbody td:nth-child(2) {
    display: block;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
    margin-bottom: 6px;
    text-align: left;
    min-height: auto;
  }
  #batchResultsContainer tbody td:nth-child(2)::before {
    display: none;
  }
  #batchResultsContainer tbody td:nth-child(2) > * {
    text-align: left;
  }
  #batchResultsContainer tbody td:nth-child(2) .fio {
    font-size: 15px;
    font-weight: 800;
    margin-right: 60px;
  }
  #batchResultsContainer tbody td:nth-child(3)::before { content: "Чел."; }
  #batchResultsContainer tbody td:nth-child(4)::before { content: "Статус"; }
  #batchResultsContainer tbody td:nth-child(5)::before { content: "Контакты"; }
  #batchResultsContainer tbody td:nth-child(6)::before { content: "Даты записи"; }
  #batchResultsContainer tbody td:nth-child(7)::before { content: "Запас"; }
  #batchResultsContainer tbody td:nth-child(8)::before { content: "Анкета"; }

  /* ── Batch Leaders Table Card Layout ── */
  #batchLeadersContainer tbody td:nth-child(1) {
    position: absolute;
    top: 14px;
    right: 16px;
    border: none;
    padding: 0;
    width: auto !important;
    min-height: auto;
    font-weight: 700;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
  }
  #batchLeadersContainer tbody td:nth-child(1)::before {
    content: "#";
  }
  #batchLeadersContainer tbody td:nth-child(2) {
    display: block;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
    margin-bottom: 6px;
    text-align: left;
    min-height: auto;
  }
  #batchLeadersContainer tbody td:nth-child(2)::before {
    display: none;
  }
  #batchLeadersContainer tbody td:nth-child(2) > * {
    text-align: left;
  }
  #batchLeadersContainer tbody td:nth-child(2) .fio {
    font-size: 15px;
    font-weight: 800;
    margin-right: 60px;
  }
  #batchLeadersContainer tbody td:nth-child(3)::before { content: "Чел."; }
  #batchLeadersContainer tbody td:nth-child(4)::before { content: "Дат"; }
  #batchLeadersContainer tbody td:nth-child(5)::before { content: "Период"; }
  #batchLeadersContainer tbody td:nth-child(6)::before { content: "Создана"; }

  /* ── Settings Form month-row styling ── */
  .month-row {
    display: flex !important;
    width: 100% !important;
    justify-content: space-between;
    box-sizing: border-box;
    margin-right: 0 !important;
    gap: 8px;
  }
  .month-row input[type="month"],
  .month-row select {
    width: auto !important;
    flex-grow: 1;
  }

  /* ── Edit Dates Modal date-range-row styling ── */
  .date-range-row {
    flex-direction: row;
    align-items: flex-end;
    gap: 6px;
  }
  .date-input-group label {
    font-size: 10px;
  }
  .date-input-group input[type="date"] {
    padding: 0 8px;
    font-size: 13px;
    height: 38px;
  }
  .btn-remove-range {
    height: 38px;
    width: 38px;
    min-width: 38px;
  }

  /* ── Modals & Details Modal Header ── */
  .panel-head:has(.panel-actions) {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .panel-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px !important;
    width: 100% !important;
    margin-top: 4px;
  }
  .panel-actions button {
    width: 100% !important;
    font-size: 12px !important;
    height: 36px !important;
    margin: 0 !important;
  }
  .panel-actions button.secondary {
    grid-column: span 2;
  }

  /* ── Captcha Grid 1-column layout ── */
  #captchaGridView {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  /* ── Auth page styling ── */
  .auth {
    grid-template-columns: 1fr;
  }
  input, select, button {
    width: 100%;
  }

  /* ── Details Grid styling ── */
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .detail-grid div:nth-child(odd) {
    border-bottom: none;
    padding-bottom: 4px;
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
  }
  .detail-grid div:nth-child(even) {
    padding-top: 4px;
    border-bottom: 1px solid var(--line);
  }
  .detail-grid div:last-child {
    border-bottom: none;
  }
}

.batch-block {
  border-bottom: 1px solid var(--line);
}
.batch-block:last-child {
  border-bottom: none;
}
.batch-header {
  padding: 12px 14px;
  background: var(--bg);
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.batch-block .table-wrap {
  border-top: none;
}

#batchResultsContainer table {
  table-layout: fixed;
  width: 100%;
}
#batchResultsContainer table th:nth-child(1),
#batchResultsContainer table td:nth-child(1) {
  width: 70px;
}
#batchResultsContainer table th:nth-child(2),
#batchResultsContainer table td:nth-child(2) {
  width: 260px;
}
#batchResultsContainer table th:nth-child(3),
#batchResultsContainer table td:nth-child(3) {
  width: 60px;
}
#batchResultsContainer table th:nth-child(4),
#batchResultsContainer table td:nth-child(4) {
  width: 150px;
}
#batchResultsContainer table th:nth-child(5),
#batchResultsContainer table td:nth-child(5) {
  width: 170px;
}
#batchResultsContainer table th:nth-child(6),
#batchResultsContainer table td:nth-child(6) {
  width: 220px;
}
#batchResultsContainer table th:nth-child(7),
#batchResultsContainer table td:nth-child(7) {
  width: 80px;
}
#batchResultsContainer table th:nth-child(8),
#batchResultsContainer table td:nth-child(8) {
  width: 110px;
}

.batch-subpanel {
  display: none;
}
.batch-subpanel.open {
  display: block;
}

/* ── Captcha 3×3 gallery ─────────────────────────────────────── */
#captchaGridView {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.captcha-event-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--card);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}
.captcha-event-card:hover {
  box-shadow: var(--shadow-md);
}

.captcha-event-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.captcha-event-task {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.captcha-event-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.captcha-review-btn {
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: 999px;
}


.captcha-3x3-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 12px;
  background: var(--bg);
}

/* Individual cell */
.captcha-cell {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: default;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, transform 0.15s ease;
  background: #111;
  line-height: 0;
}
.captcha-cell:hover {
  transform: scale(1.03);
  z-index: 1;
}
.captcha-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Clicked cell — green border + green tint overlay */
.captcha-cell--clicked {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px var(--ok), inset 0 0 0 9999px rgba(16, 185, 129, 0.12);
}
.captcha-cell--clicked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(16, 185, 129, 0.15);
  pointer-events: none;
}

/* Normal / not-clicked cell */
.captcha-cell--normal {
  border-color: transparent;
  opacity: 0.8;
}

/* Empty / missing cell */
.captcha-cell--empty {
  border: 2px dashed var(--line);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 22px;
  font-weight: 700;
  opacity: 0.4;
}

/* Cell number badge (top-left) */
.captcha-cell-num {
  position: absolute;
  top: 4px;
  left: 5px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  pointer-events: none;
}

/* Checkmark badge (bottom-right) for clicked cells */
.captcha-cell-check {
  position: absolute;
  bottom: 4px;
  right: 5px;
  font-size: 13px;
  color: var(--ok);
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  pointer-events: none;
}

/* Seen count badge */
.captcha-cell-count {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  pointer-events: none;
}

.captcha-cell-delete {
  position: absolute;
  bottom: 4px;
  left: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.85); /* red */
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  line-height: 1;
  z-index: 2;
}

.captcha-cell:hover .captcha-cell-delete {
  opacity: 1;
}

.captcha-cell-delete:hover {
  background: rgb(220, 38, 38);
}

.captcha-cell-toggle {
  position: absolute;
  bottom: 4px;
  left: 27px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  line-height: 1;
  z-index: 2;
}

.captcha-cell-toggle.to-click {
  background: rgba(16, 185, 129, 0.85); /* green */
}
.captcha-cell-toggle.to-click:hover {
  background: rgb(16, 185, 129);
}

.captcha-cell-toggle.to-unclick {
  background: rgba(245, 158, 11, 0.85); /* orange/yellow */
}
.captcha-cell-toggle.to-unclick:hover {
  background: rgb(245, 158, 11);
}

.captcha-cell:hover .captcha-cell-toggle {
  opacity: 1;
}

/* ── Priority view ──────────────────────────────────────────────────── */

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 0 4px;
}

.rank-badge-muted {
  background: var(--bg-alt);
  color: var(--muted);
  border: 1px solid var(--line);
}

.earliest-date {
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

#priorityView .no-dates-row td {
  opacity: 0.55;
}

/* ── Status time and Admin Timeline Modal ────────────────────────────── */

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

.admin-timeline-list {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 24px;
  margin: 8px 0;
}

.admin-timeline-list::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--line);
}

.admin-timeline-item {
  position: relative;
  padding-bottom: 16px;
}

.admin-timeline-item:last-child {
  padding-bottom: 0;
}

.admin-timeline-dot {
  position: absolute;
  left: -24px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card);
  border: 3px solid var(--accent);
  box-sizing: border-box;
}

.admin-timeline-item.type-created .admin-timeline-dot { border-color: var(--muted); background: var(--card); }
.admin-timeline-item.type-confirmed .admin-timeline-dot { border-color: var(--accent); background: var(--card); }
.admin-timeline-item.type-status_changed .admin-timeline-dot { border-color: var(--accent); background: var(--card); }
.admin-timeline-item.type-booked .admin-timeline-dot { border-color: var(--ok); background: var(--ok-bg); }
.admin-timeline-item.type-error .admin-timeline-dot { border-color: var(--danger); background: var(--danger-bg); }
.admin-timeline-item.type-lockdown .admin-timeline-dot { border-color: var(--warn); background: var(--warn-bg); }
.admin-timeline-item.type-deleted .admin-timeline-dot { border-color: var(--muted); background: var(--card); }

.admin-timeline-date {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.admin-timeline-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.admin-timeline-item.type-booked .admin-timeline-label { color: var(--ok); }
.admin-timeline-item.type-error .admin-timeline-label { color: var(--danger); }
.admin-timeline-item.type-lockdown .admin-timeline-label { color: var(--warn); }

.admin-timeline-detail {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  background: var(--bg);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  word-break: break-word;
}

/* ── Captcha Management & Inspector Styles ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  font-family: var(--font-number, inherit);
}

.text-success { color: var(--ok, #22c55e) !important; }
.text-danger { color: var(--danger, #ef4444) !important; }
.text-warning { color: var(--warn, #f59e0b) !important; }

.captcha-thumb {
  width: 56px;
  height: 35px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: #0f172a;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.captcha-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 2;
}

.captcha-thumb-placeholder {
  width: 56px;
  height: 35px;
  border-radius: 4px;
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--bg);
}

.captcha-rule-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
}

.captcha-row {
  cursor: pointer;
  transition: background 0.15s ease;
}

.captcha-row:hover td {
  background: var(--hover-bg, rgba(0, 0, 0, 0.03));
}

.captcha-board-stage {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
}
