*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #111113;
  --bg2:         #1a1a1d;
  --bg3:         #232326;
  --bg4:         #2c2c30;
  --border:      #2e2e32;
  --border-soft: #26262a;
  --text:        #e8e8ea;
  --muted:       #7a7a82;
  --accent:      #d47a3a;
  --accent-dim:  #9e5a24;
  --accent-glow: rgba(212,122,58,0.15);
  --green:       #4caf7d;
  --yellow:      #f0c040;
  --red:         #e05555;
  --danger-hover-bg: rgba(224,85,85,0.12);
  --radius:      6px;
  --radius-sm:   4px;
  --font:        'Inter', system-ui, sans-serif;
  --shadow:      0 8px 32px rgba(0,0,0,0.55);
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.3);
  --sidebar-w:   210px;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

/* ── App shell ── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  height: 100vh;
  overflow: hidden;
}

.sb-logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-logo-title {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.01em;
}

.sb-logo small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sb-section {
  padding: 14px 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0 6px;
  margin-bottom: 7px;
}

.sb-select-wrap {
  position: relative;
}

.sb-select-wrap::after {
  content: '';
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  pointer-events: none;
}

.sb-select-wrap select {
  width: 100%;
  padding: 6px 28px 6px 9px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  margin-top: 0;
  transition: border-color 0.15s;
}

.sb-select-wrap select:focus {
  outline: none;
  border-color: var(--accent);
}

.sb-nav {
  flex: 1;
  padding: 14px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid transparent;
  background: transparent;
  font-family: var(--font);
  font-weight: 400;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}

.nav-item:hover {
  background: var(--bg3);
  color: var(--text);
}

.nav-item.active {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--border-soft);
}

.nav-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.55;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
  opacity: 1;
}

.sb-bottom {
  flex-shrink: 0;
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sb-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
  border: none;
  font-family: var(--font);
  font-weight: 400;
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
  width: 100%;
  text-align: left;
}

.sb-link:hover {
  background: var(--bg3);
  color: var(--muted);
}

.spinner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  z-index: 2;
}

.sb-link svg,
.sb-link-icon {
  flex-shrink: 0;
  opacity: 0.6;
  filter: invert(1);
}

.sb-link:hover svg,
.sb-link:hover .sb-link-icon {
  opacity: 1;
}

/* ── Sidebar primary button ── */
.sb-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 10px;
  margin-top: 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.sb-btn:hover:not(:disabled) {
  background: var(--bg4);
  border-color: var(--muted);
}

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

.sb-btn.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

.sb-btn.primary:hover:not(:disabled) {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ── Main content ── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Views ── */
.view {
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  display: none;
}

.view.active-view {
  display: flex;
}

/* ── Setup view ── */
.setup-inner {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.setup-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-sm);
}

.setup-card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6rem;
}

.setup-card > p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

.setup-card a { color: var(--accent); }

/* ── Nearly completed view ── */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.view-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.view-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.spinner {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}

.spin-icon {
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
  color: var(--accent);
}

/* ── Table ── */
.table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative; /* ADD THIS */
  scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}

.table-wrap::-webkit-scrollbar { width: 6px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 99px; }

#results-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

#results-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

#results-table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#results-table tbody tr:nth-child(odd) td  { background: var(--bg2); }
#results-table tbody tr:nth-child(even) td { background: var(--bg3); }
#results-table tbody tr:hover td           { background: var(--bg4); }
#results-table tbody tr:last-child td { border-bottom: none; }

.col-pct    { width: 80px; }
.col-prog   { width: 160px; }
.col-name   { width: auto; }
.col-reward { width: 260px; }

td.col-pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

td.col-prog {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

td.col-reward {
  color: var(--muted);
  font-size: 13px;
}

.pct-high { color: var(--green); }
.pct-med  { color: var(--yellow); }
.pct-low  { color: var(--text); }

.ap-icon {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  margin-right: 2px;
}

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

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 4rem 0;
  border: none;
  background: transparent !important;
}

/* ── Progress bar ── */
.prog-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  font-size: 12px;
}

.prog-bar-bg {
  width: 100%;
  height: 4px;
  background: var(--bg4);
  border-radius: 99px;
  overflow: hidden;
}

.prog-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* ── Generic buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.38rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover:not(:disabled) {
  background: var(--bg4);
  border-color: var(--muted);
}

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

.btn.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn.danger {
  border-color: var(--red);
  color: var(--red);
  background: transparent;
}

.btn.danger:hover:not(:disabled) { background: var(--danger-hover-bg); }

.btn.small {
  font-size: 11px;
  padding: 0.25rem 0.65rem;
}

/* ── Form elements ── */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 1rem;
}

.form-field:last-child { margin-bottom: 0; }

.field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 0.42rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237a7a82'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 10px 6px;
  padding-right: 2rem;
  cursor: pointer;
}

option {
  background-color: var(--bg2);
  color: var(--text);
}

.api-key-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.api-key-wrap input {
  width: 100%;
  padding-right: 2.4rem;
}

.eye-btn {
  position: absolute;
  right: 0.4rem;
  background: transparent;
  border: none;
  padding: 0.2rem;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  border-radius: 3px;
  transition: color 0.15s;
}

.eye-btn:hover { color: var(--text); }

.field-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 0.25rem;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  pointer-events: none;
  visibility: hidden;
  transition: background 0.25s ease, visibility 0s linear 0.25s;
}

.modal-overlay.open {
  background: rgba(0,0,0,0.65);
  pointer-events: all;
  visibility: visible;
  transition: background 0.25s ease, visibility 0s linear 0s;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  opacity: 0;
  transform: scale(0.9) translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.modal-overlay.open .modal {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem 0.9rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 1;
}

.modal-header h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover { color: var(--text); background: var(--bg3); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--border);
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  background: var(--bg2);
}

/* ── Settings sections ── */
.settings-section {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child { border-bottom: none; }

.settings-section h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.9rem;
}

.settings-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.settings-section-header h3 { margin-bottom: 0; }

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.85rem 1.25rem;
}

/* ── Accounts list ── */
.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.account-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

.account-row-info {
  flex: 1;
  min-width: 0;
}

.account-row-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.account-row-key {
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-row-delete {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.account-row-delete:hover {
  color: var(--red);
  background: var(--danger-hover-bg);
}

.add-account-form {
  margin-top: 10px;
  padding: 12px;
  background: var(--bg3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 0.75rem;
}

.form-row .form-field {
  flex: 1;
  margin-bottom: 0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 10px;
}

/* ── Cache row ── */
.cache-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* ── Legal modal ── */
.legal-body {
  padding: 1.1rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.legal-body section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.legal-body section p {
  color: var(--muted);
  line-height: 1.65;
  font-size: 13px;
  margin-bottom: 0.35rem;
}

.legal-body section a { color: var(--accent); }

/* ── Number spinner ── */
input[type="number"] {
  -moz-appearance: textfield;
  padding-right: 1.5rem;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.number-wrap {
  position: relative;
}

.number-wrap input { width: 100%; }

.number-spin {
  position: absolute;
  right: 1px;
  top: 1px;
  bottom: 1px;
  width: 1.5rem;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  overflow: hidden;
}

.number-spin button {
  flex: 1;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: var(--bg3);
  color: var(--muted);
  font-size: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  transition: background 0.12s, color 0.12s;
}

.number-spin button:hover {
  background: var(--bg4);
  color: var(--text);
}

.number-spin button:first-child {
  border-bottom: 1px solid var(--border);
}

/* ── Misc ── */
.muted { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

#results-body.fade-in {
  animation: fadeIn 0.2s ease forwards;
}