/* ==============================================================
   ElvenXCEL · Ancient Wonder Farmer — Modern Stylesheet
   Light: white-dominant (#fff + black text)
   Dark:  black-dominant (#000 + white text)
   ============================================================== */

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

/* --- Light Theme (default) — white dominant --- */
:root {
    --bg-page: #ffffff;
    --bg-surface: #fafafa;
    --bg-card: #ffffff;
    --bg-table: #ffffff;
    --bg-table-header: #f5f5f5;
    --bg-table-row: #ffffff;
    --bg-table-row-alt: #fafafa;
    --bg-table-row-hover: #f0f0f0;
    --bg-input: #ffffff;
    --bg-progress: #e5e5e5;
    --bg-badge: #f0f0f0;

    --text-primary: #000000;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --text-on-accent: #ffffff;
    --text-badge: #333333;
    --text-loading: #999999;
    --text-progress: #666666;

    --border-color: #e5e5e5;
    --border-light: #eeeeee;
    --border-focus: #4ade80;

    --accent: #16a34a;
    --accent-hover: #15803d;
    --accent-light: rgba(22,163,74,0.10);

    --highlight-bg: #f0fdf4;
    --highlight-border: #4ade80;
    --highlight-text: #15803d;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);

    --progress-fill: #16a34a;
    --progress-fill-high: #22c55e;

    --loading-color: #e5e5e5;
    --loading-accent: #16a34a;

    --scrollbar-track: #f0f0f0;
    --scrollbar-thumb: #cccccc;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
    --radius: 16px;
    --radius-sm: 10px;
}

/* --- Dark Theme — black dominant --- */
[data-theme="dark"] {
    --bg-page: #000000;
    --bg-surface: #0a0a0a;
    --bg-card: #111111;
    --bg-table: #0d0d0d;
    --bg-table-header: #111111;
    --bg-table-row: #0d0d0d;
    --bg-table-row-alt: #141414;
    --bg-table-row-hover: #1a1a1a;
    --bg-input: #1a1a1a;
    --bg-progress: #222222;
    --bg-badge: #1a1a1a;

    --text-primary: #ffffff;
    --text-secondary: #999999;
    --text-tertiary: #666666;
    --text-on-accent: #000000;
    --text-badge: #cccccc;
    --text-loading: #666666;
    --text-progress: #999999;

    --border-color: #222222;
    --border-light: #1a1a1a;
    --border-focus: #4ade80;

    --accent: #16a34a;
    --accent-hover: #15803d;
    --accent-light: rgba(22,163,74,0.10);

    --highlight-bg: #052e16;
    --highlight-border: #4ade80;
    --highlight-text: #4ade80;

    --shadow-sm: 0 1px 3px rgba(255,255,255,0.03);
    --shadow-md: 0 4px 12px rgba(255,255,255,0.04);
    --shadow-lg: 0 8px 24px rgba(255,255,255,0.06);

    --progress-fill: #16a34a;
    --progress-fill-high: #22c55e;

    --loading-color: #222222;
    --loading-accent: #16a34a;

    --scrollbar-track: #111111;
    --scrollbar-thumb: #333333;
    --radius: 16px;
    --radius-sm: 10px;
}

/* --- Base --- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Container --- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
}

@media (min-width: 768px) {
    .container {
        padding: 24px;
    }
}

/* --- Page Header --- */
.page-header {
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}

.page-header p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: 640px;
}

@media (min-width: 768px) {
    .page-header h1 {
        font-size: 1.6rem;
    }
    .page-header p {
        font-size: 0.9rem;
    }
}

/* --- Header (TL RSS pattern) --- */
.header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; background: var(--bg-surface);
  border: 1px solid var(--border-color); border-radius: var(--radius);
  margin-bottom: 16px; gap: 12px;
  transition: background 0.3s ease, border-color 0.3s ease;
}
.header-left { display: flex; align-items: center; gap: 10px; flex: 1; }
.header-left h1 { font-size: 18px; font-weight: 700; color: var(--text-primary); margin: 0; }
.header-left .highlight { color: var(--accent); }
.version-badge {
  font-size: 9px; background: var(--accent); color: #000;
  padding: 1px 5px; border-radius: 3px; vertical-align: middle;
  margin-left: 6px; font-weight: 600; letter-spacing: 0.3px;
  display: none;
}
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.icon-btn {
  background: var(--bg-card); border: 1px solid var(--border-color);
  color: var(--text-primary); width: 34px; height: 34px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease; padding: 0; line-height: 1;
}
.icon-btn:hover { background: var(--bg-table-row-hover); border-color: var(--accent); }

.badge-api {
  background: var(--bg-surface);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  padding: 4px 10px; font-size: 10px; font-family: var(--font-mono);
  color: var(--accent); font-weight: 500; white-space: nowrap;
}

/* --- Filters Card --- */
.filters {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    box-shadow: var(--shadow-sm);
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

@media (min-width: 768px) {
    .filters {
        padding: 20px 24px;
        gap: 20px;
    }
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 130px;
}

.filter-group label {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

select, input[type="number"], .filter-group button {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    appearance: auto;
    height: 38px;
    box-sizing: border-box;
    line-height: 1.4;
}

select:focus, input[type="number"]:focus, .filter-group button:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}

[data-theme="dark"] select:focus,
[data-theme="dark"] input[type="number"]:focus,
[data-theme="dark"] .filter-group button:focus {
    box-shadow: 0 0 0 2px rgba(255,255,255,0.08);
}

.filter-group button {
    background: var(--accent);
    border: 1px solid var(--accent-hover);
    color: var(--text-on-accent);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    width: 100%;
}

.filter-group button:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.filter-group button:active {
    transform: scale(0.98);
}

/* --- Stats Bar --- */
.stats {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.counter {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: background 0.3s ease, border-color 0.3s ease;
    box-shadow: var(--shadow-sm);
}

@media (min-width: 768px) {
    .counter {
        font-size: 0.85rem;
        padding: 6px 18px;
    }
}

/* --- Stat Chips --- */
.stat-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 7px 14px 7px 10px;
    box-shadow: var(--shadow-sm);
    transition: background 0.3s ease, border-color 0.3s ease, transform 0.15s ease;
}

.stat-chip:hover {
    transform: translateY(-1px);
}

.stat-chip--accent {
    border-color: var(--accent);
}

.stat-icon {
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent-light);
    flex-shrink: 0;
}

.stat-body {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.stat-label {
    font-size: 0.63rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

@media (min-width: 768px) {
    .stat-value {
        font-size: 0.95rem;
    }
}

/* --- Table --- */
.table-wrapper {
    overflow-x: auto;
    background: var(--bg-table);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    -webkit-overflow-scrolling: touch;
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    min-width: 560px;
}

@media (min-width: 768px) {
    table {
        font-size: 0.85rem;
        min-width: 900px;
    }
}

/* --- Table Header --- */
th {
    background: var(--bg-table-header);
    padding: 12px 10px;
    text-align: left;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease, color 0.2s ease;
    position: sticky;
    top: 0;
    z-index: 10;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

@media (min-width: 768px) {
    th {
        padding: 14px 12px;
        font-size: 0.78rem;
    }
}

th:hover {
    background: var(--bg-table-row-hover);
}

th .sort-icon {
    margin-left: 6px;
    font-size: 0.7rem;
    opacity: 0.4;
    transition: opacity 0.2s ease;
}

th.sorted {
    color: var(--accent);
}

th.sorted .sort-icon {
    opacity: 1;
}

/* --- Table Body --- */
td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    transition: background 0.2s ease;
}

@media (min-width: 768px) {
    td {
        padding: 12px;
    }
}

tr {
    background: var(--bg-table-row);
    transition: background 0.15s ease;
}

tr:nth-child(even) {
    background: var(--bg-table-row-alt);
}

tr:hover {
    background: var(--bg-table-row-hover);
}

/* --- Empty / Loading state --- */
.table-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-loading);
    font-size: 0.9rem;
}

/* --- Error state --- */
.error-text {
    color: #ef4444;
    font-weight: 600;
}

/* --- High Reward row --- */
tr.high-reward {
    background: var(--highlight-bg);
    border-left: 3px solid var(--highlight-border);
}

tr.high-reward:nth-child(even) {
    background: var(--highlight-bg);
}

tr.high-reward:hover {
    background: color-mix(in srgb, var(--highlight-bg), var(--bg-table-row-hover) 50%);
}

/* --- High Reward Badge --- */
.high-reward-badge {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    border-radius: 999px;
    padding: 3px 10px;
    font-weight: 800;
    font-size: 0.7rem;
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(245,158,11,0); }
    50% { opacity: 0.85; box-shadow: 0 0 12px 2px rgba(245,158,11,0.15); }
}

/* --- Regular Badge --- */
.badge-rewards {
    background: var(--bg-badge);
    color: var(--text-badge);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-block;
    white-space: nowrap;
}

/* --- Progress Bar --- */
.progress-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.progress-container {
    background: var(--bg-progress);
    border-radius: 999px;
    height: 5px;
    width: 80px;
    max-width: 120px;
    overflow: hidden;
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .progress-container {
        width: 100px;
    }
}

.progress-fill {
    background: var(--progress-fill);
    width: 0%;
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Progress fill color for high rewards */
tr.high-reward .progress-fill {
    background: var(--progress-fill-high);
}

/* Progress fill tiers by completion percentage */
.progress-fill--low {
    background: #ef4444;
}

.progress-fill--mid {
    background: #f59e0b;
}

.progress-fill--high {
    background: var(--progress-fill-high);
}

.progress-text {
    font-size: 0.7rem;
    color: var(--text-progress);
    font-weight: 500;
    min-width: 2.2em;
    text-align: right;
    flex-shrink: 0;
}

/* --- Near-complete badge (>=90% progress) --- */
.near-complete-badge {
    font-size: 0.75rem;
    flex-shrink: 0;
    line-height: 1;
}

/* --- Center aligned cell --- */
.td-center {
    text-align: center;
}

/* --- KP Cell --- */
.kp-cell {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    white-space: nowrap;
    color: var(--text-primary);
}

/* --- KP Missing Cell --- */
.kp-missing-cell {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
    color: var(--warning, #f59e0b);
}

/* --- Reward Cell --- */
.reward-cell {
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
}

/* --- Loading Spinner --- */
.loading-spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 3px solid var(--loading-color);
    border-top-color: var(--loading-accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

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

/* --- Retry Button --- */
.retry-btn {
    background: var(--accent);
    border: none;
    border-radius: 10px;
    padding: 8px 18px;
    color: var(--text-on-accent);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    margin-top: 12px;
}

.retry-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

/* --- Mobile — ocultar colunas menos relevantes --- */
@media (max-width: 767px) {
    th:nth-child(2),
    td:nth-child(2) {
        display: none;
    }

    th:nth-child(6),
    td:nth-child(6) {
        display: none;
    }

    th, td {
        padding: 8px 6px;
    }

    .progress-container {
        max-width: 60px;
    }

    .high-reward-badge {
        font-size: 0.6rem;
        padding: 2px 8px;
    }
}

@media (max-width: 480px) {
    .filters {
        flex-direction: column;
        padding: 14px 16px;
        gap: 12px;
    }

    .filter-group {
        width: 100%;
        min-width: unset;
    }

    .stats {
        flex-direction: column;
        align-items: stretch;
    }

    .counter {
        text-align: center;
    }

    .theme-toggle {
        width: 100%;
        justify-content: space-between;
    }

    td, th {
        font-size: 0.72rem;
    }

    .table-empty {
        padding: 24px 16px;
        font-size: 0.85rem;
    }

    .kp-cell {
        font-size: 0.68rem;
    }
}
