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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232733;
  --border: #2e3345;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Header === */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.connection-status {
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.connection-status.connected {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

.connection-status.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

/* === Captcha Balance Badge === */
/* === Health Badges === */
.health-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  transition: all 0.3s;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.health-badge.health-online {
  background: rgba(34, 197, 94, 0.12);
  color: var(--green);
}

.health-badge.health-online .health-dot {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.health-badge.health-offline {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  animation: pulse-badge 2s infinite;
}

.health-badge.health-offline .health-dot {
  background: var(--red);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.health-badge.health-checking {
  background: var(--surface-2);
  color: var(--yellow);
}

.health-badge.health-checking .health-dot {
  background: var(--yellow);
  animation: health-pulse 1s infinite;
}

@keyframes health-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

.health-badge.health-unknown {
  background: var(--surface-2);
  color: var(--text-muted);
}

.health-badge.health-unknown .health-dot {
  background: var(--text-muted);
}

.captcha-balance {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  transition: all 0.3s;
}

.captcha-balance svg { opacity: 0.6; flex-shrink: 0; }

.captcha-balance.balance-ok {
  background: rgba(34, 197, 94, 0.12);
  color: var(--green);
}

.captcha-balance.balance-low {
  background: rgba(234, 179, 8, 0.15);
  color: var(--yellow);
}

.captcha-balance.balance-critical {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* === Main === */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* === Stats Cards === */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: border-color 0.2s;
}

.card-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.card-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-total .card-value { color: var(--text); }
.card-pending .card-value { color: var(--yellow); }
.card-processing .card-value { color: var(--blue); }
.card-done .card-value { color: var(--green); }
.card-error .card-value { color: var(--red); }

/* === Sections === */
section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 { margin-bottom: 0; }

.stats-cards {
  background: none;
  border: none;
  padding: 0;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { border-color: var(--text-muted); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Drop Zone === */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.05);
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.drop-zone-content svg { opacity: 0.5; }
.drop-zone-content p { font-size: 0.95rem; }
.drop-zone-content span { font-size: 0.8rem; }

/* === Import Progress === */
.import-progress {
  margin-top: 16px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.progress-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s;
}

.progress-fill.done { background: var(--green); }
.progress-fill.error { background: var(--red); }

.import-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* === Tables === */
.table-wrapper {
  overflow-x: auto;
}

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

thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 12px !important;
}

/* === Progress Badge (historico) === */
.progress-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.progress-badge .mini-bar {
  width: 80px;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-badge .mini-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-badge.status-done .mini-fill { background: var(--green); }
.progress-badge.status-running .mini-fill { background: var(--blue); }
.progress-badge.status-error .mini-fill { background: var(--red); }
.progress-badge.status-pending .mini-fill { background: var(--yellow); }

/* === Header Controls === */
.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* === Pause Button === */
.pause-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.pause-btn .pause-icon {
  font-size: 0.7rem;
}

.pause-btn.running {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.3);
}

.pause-btn.paused {
  background: rgba(234, 179, 8, 0.15);
  color: var(--yellow);
  border-color: rgba(234, 179, 8, 0.3);
}

.pause-btn:hover { opacity: 0.85; }

/* === Action Buttons (small) === */
.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-warning {
  background: rgba(234, 179, 8, 0.15);
  color: var(--yellow);
  border-color: rgba(234, 179, 8, 0.3);
}

.btn-warning:hover { background: rgba(234, 179, 8, 0.25); }

.btn-success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.3);
}

.btn-success:hover { background: rgba(34, 197, 94, 0.25); }

/* === Filter Tabs === */
.filter-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.filter-tab {
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
}

.filter-tab:hover { background: var(--surface-2); color: var(--text); }
.filter-tab.active { background: var(--primary); color: white; }

/* === Status Badges === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-pending { background: rgba(234, 179, 8, 0.15); color: var(--yellow); }
.badge-processing { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.badge-error { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.badge-cancelled { background: rgba(139, 143, 163, 0.15); color: var(--text-muted); }
.badge-done { background: rgba(34, 197, 94, 0.15); color: var(--green); }

/* === Bulk Actions === */
.bulk-actions {
  display: flex;
  gap: 8px;
}

/* === Queue Action Buttons === */
.action-btns {
  display: flex;
  gap: 4px;
}

/* === Pagination === */
.pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 12px;
}

.pagination button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.pagination button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.pagination button:hover:not(.active) { border-color: var(--text-muted); }

/* === Error text truncation === */
.error-text {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--red);
}

/* === ETA Cell === */
.eta-cell {
  font-size: 0.8rem;
  color: var(--blue);
  font-weight: 500;
}

/* === Login Screen === */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
  border: none;
  border-radius: 0;
  padding: 24px;
}

.login-screen[hidden] { display: none; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: -12px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.login-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.login-input:focus {
  border-color: var(--primary);
}

.login-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.login-error {
  color: var(--red);
  font-size: 0.85rem;
  text-align: center;
}

.login-btn {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 0.95rem;
}

/* === User Info (header) === */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-email {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === Responsive === */
@media (max-width: 768px) {
  .stats-cards {
    grid-template-columns: repeat(3, 1fr);
  }
  .card-value { font-size: 1.5rem; }
}

@media (max-width: 480px) {
  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}
