/* ========================================
   BM Dashboard — Premium Dark Theme
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ── */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.15);

    --text-primary: #e8e8ed;
    --text-secondary: #8b8b9e;
    --text-muted: #5a5a6e;

    --accent-primary: #6c5ce7;
    --accent-secondary: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);

    --color-war: #ff6b6b;
    --color-robbery: #feca57;
    --color-auction: #48dbfb;
    --color-race: #ff9ff3;
    --color-other: #a29bfe;

    --gradient-hero: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #16213e 100%);
    --gradient-card-war: linear-gradient(135deg, rgba(255, 107, 107, 0.08), rgba(255, 107, 107, 0.02));
    --gradient-card-robbery: linear-gradient(135deg, rgba(254, 202, 87, 0.08), rgba(254, 202, 87, 0.02));
    --gradient-card-auction: linear-gradient(135deg, rgba(72, 219, 251, 0.08), rgba(72, 219, 251, 0.02));

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gradient-hero);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Background ambient glow ── */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 20% 50%, rgba(108, 92, 231, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(72, 219, 251, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(255, 107, 107, 0.02) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ── Layout ── */
#app {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px;
}

/* ── Navigation Bar ── */
.navbar {
    position: relative;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    margin-bottom: 28px;
    transition: border-color var(--transition-normal);
    overflow: visible; /* allow nav links to be visible/scrollable */
}

.navbar:hover {
    border-color: var(--border-glass-hover);
}

.navbar .logo {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1; /* lower logo so links can appear above when needed */
}

.navbar .logo span {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap; /* default: wrap when space allows */
    overflow: visible;
    flex: 1 1 auto; /* allow nav-links to take remaining space and shrink */
    min-width: 0; /* allow flex child to shrink and enable overflow */
    z-index: 3;
    padding-left: 6px;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
}

.nav-links a.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 2px;
    background: var(--accent-primary);
    border-radius: 1px;
}

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

.page-header h2 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 4px;
}

.page-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.93rem;
}

/* ── Filters ── */
.filters-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 18px 22px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    align-items: flex-end;
    transition: border-color var(--transition-normal);
}

.filters-container:hover {
    border-color: var(--border-glass-hover);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

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

.filter-group input,
.filter-group select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.87rem;
    outline: none;
    transition: all var(--transition-fast);
    min-width: 160px;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-group input::placeholder {
    color: var(--text-muted);
}

.filter-group select option,
select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ── Controls (pagination) ── */
.controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.controls .page-info {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.controls .page-info .highlight {
    color: var(--accent-secondary);
    font-weight: 600;
}

.btn-group {
    display: flex;
    gap: 8px;
}

button {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
}

button:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-glass-hover);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ── Table ── */
.table-wrapper {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    /* allow horizontal scroll for wide tables, but visible vertical overflow */
    overflow-x: auto;
    overflow-y: visible;
    transition: border-color var(--transition-normal);
}

/* allow horizontal scrolling for wide tables on small screens */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* make nav links not wrap on small screens and allow scrolling */
@media (max-width: 768px) {
    .nav-links {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 8px;
        overflow: visible;
    }

    .nav-links a {
        white-space: nowrap;
        display: inline-block;
    }
}

/* subtle scrollbar for nav and table on WebKit */
.nav-links::-webkit-scrollbar,
.table-wrapper::-webkit-scrollbar {
    height: 8px;
}
.nav-links::-webkit-scrollbar-thumb,
.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.06);
    border-radius: 6px;
}

.table-wrapper:hover {
    border-color: var(--border-glass-hover);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: rgba(108, 92, 231, 0.06);
    padding: 13px 16px;
    text-align: left;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-glass);
    white-space: nowrap;
    user-select: none;
    position: relative;
}

thead th[data-sortable="true"] {
    cursor: pointer;
    transition: color var(--transition-fast);
}

thead th[data-sortable="true"]:hover {
    color: var(--accent-secondary);
}

thead th .sort-icon {
    opacity: 0.4;
    margin-left: 4px;
    font-size: 0.7rem;
    transition: opacity var(--transition-fast);
}

thead th[data-sortable="true"]:hover .sort-icon {
    opacity: 0.8;
}

thead th.sort-active .sort-icon {
    opacity: 1;
    color: var(--accent-primary);
}

tbody tr {
    transition: background var(--transition-fast);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

tbody tr:hover {
    background: rgba(108, 92, 231, 0.04);
}

tbody td {
    padding: 11px 16px;
    font-size: 0.87rem;
    color: var(--text-primary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tbody td[data-key="current_stat"] {
    white-space: normal;
    word-break: break-word;
    overflow: visible;
    text-overflow: clip;
    max-width: 500px;
    line-height: 1.4;
}

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

/* ── Loading State ── */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
    gap: 10px;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-glass);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Empty State ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 2.4rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state .empty-text {
    font-size: 0.93rem;
    font-weight: 500;
}

/* ── Index Page — Hero ── */
.hero {
    text-align: center;
    padding: 60px 20px 40px;
}

.hero h1 {
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: -0.04em;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    max-width: 500px;
    margin: 0 auto;
}

/* ── Index Page — View Cards ── */
.view-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    padding: 0 20px;
    max-width: 1000px;
    margin: 0 auto;
}

.view-card {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 28px;
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-slow);
    position: relative;
    overflow: hidden;
}

.view-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    transition: opacity var(--transition-slow);
    z-index: 0;
    border-radius: var(--radius-lg);
}

.view-card.war::before {
    background: var(--gradient-card-war);
}

.view-card.robbery::before {
    background: var(--gradient-card-robbery);
}

.view-card.auctions::before {
    background: var(--gradient-card-auction);
}

.view-card:hover {
    border-color: var(--border-glass-hover);
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.view-card:hover::before {
    opacity: 1;
}

.view-card>* {
    position: relative;
    z-index: 1;
}

.view-card .card-icon {
    font-size: 2rem;
    margin-bottom: 14px;
    display: block;
}

.view-card h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.view-card p {
    color: var(--text-secondary);
    font-size: 0.87rem;
    line-height: 1.5;
}

.view-card .card-arrow {
    position: absolute;
    bottom: 24px;
    right: 24px;
    font-size: 1.1rem;
    color: var(--text-muted);
    transition: all var(--transition-normal);
}

.view-card:hover .card-arrow {
    color: var(--accent-secondary);
    transform: translateX(4px);
}

/* ── Category badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge.war {
    background: rgba(255, 107, 107, 0.15);
    color: var(--color-war);
}

.badge.robbery {
    background: rgba(254, 202, 87, 0.15);
    color: var(--color-robbery);
}

.badge.auction {
    background: rgba(72, 219, 251, 0.15);
    color: var(--color-auction);
}

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

.stat-chip {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.stat-chip .stat-value {
    font-weight: 700;
    color: var(--accent-secondary);
}

.stat-chip .stat-label {
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* ── Fade-in animation ── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeIn 0.4s ease forwards;
}

tbody tr {
    animation: fadeIn 0.3s ease backwards;
}

tbody tr:nth-child(1) {
    animation-delay: 0.02s;
}

tbody tr:nth-child(2) {
    animation-delay: 0.04s;
}

tbody tr:nth-child(3) {
    animation-delay: 0.06s;
}

tbody tr:nth-child(4) {
    animation-delay: 0.08s;
}

tbody tr:nth-child(5) {
    animation-delay: 0.10s;
}

tbody tr:nth-child(6) {
    animation-delay: 0.12s;
}

tbody tr:nth-child(7) {
    animation-delay: 0.14s;
}

tbody tr:nth-child(8) {
    animation-delay: 0.16s;
}

tbody tr:nth-child(9) {
    animation-delay: 0.18s;
}

tbody tr:nth-child(10) {
    animation-delay: 0.20s;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    #app {
        padding: 16px;
    }

    .navbar {
        flex-direction: column;
        gap: 12px;
    }

    .nav-links {
        width: 100%;
        justify-content: flex-start; /* ensure first items are visible */
        overflow: visible;
        padding-left: 6px;
    }

    .filters-container {
        flex-direction: column;
    }

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

    .controls {
        flex-direction: column;
        gap: 8px;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .view-cards {
        grid-template-columns: 1fr;
    }

    tbody td {
        max-width: 150px;
        font-size: 0.8rem;
        padding: 8px 10px;
    }

    thead th {
        padding: 10px 10px;
        font-size: 0.72rem;
    }
}

@media (max-width: 480px) {
    .hero h1 {
        font-size: 1.6rem;
    }

    .page-header h2 {
        font-size: 1.4rem;
    }
    /* larger touch targets for very small screens */
    .nav-links a {
        padding: 10px 12px;
        font-size: 0.95rem;
    }

    button {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
}

/* ── Auth Button Layout ── */
#auth-nav-container {
    flex-shrink: 0;
    margin-left: 12px;
}
@media (max-width: 768px) {
    #auth-nav-container {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-left: 0;
        margin-top: 4px;
    }
}

/* ── Item Image Styling ── */
.table-item-img {
    max-width: 32px;
    max-height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
    vertical-align: middle;
    transition: transform var(--transition-fast);
}
.table-item-img:hover {
    transform: scale(1.2);
}

/* ── Stars & Shapes Styling ── */
.ui-star {
    display: inline-block;
    line-height: 1;
    vertical-align: middle;
    margin-right: 2px;
}
.ui-star.star {
    color: #ffd700; /* gold */
}
.ui-star.diamond {
    color: #00d2fc; /* cyan / diamond */
}
.ui-star.hex {
    color: #a29bfe; /* purple hex */
}
.ui-star.large {
    font-size: 1.15rem;
}
.ui-star.small {
    font-size: 0.85rem;
}
.star-level-badge {
    color: var(--accent-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}

/* ── Rarity Colors ── */
.rarity-cell {
    font-weight: 600;
    text-transform: capitalize;
}
.rarity-common {
    color: #a0a0a0;
}
.rarity-rare {
    color: #3498db;
}
.rarity-epic {
    color: #9b59b6;
}
.rarity-legendary {
    color: #f1c40f;
}
.rarity-mythic {
    color: #e74c3c;
}

/* ── Admin Dropdown ── */
.dropdown {
    position: relative;
    display: inline-block;
    z-index: 100;
}

.dropdown-btn {
    background: rgba(139, 92, 246, 0.1) !important;
    color: var(--accent-secondary) !important;
    border: 1px solid rgba(139, 92, 246, 0.25) !important;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 0.87rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.dropdown-btn:hover {
    background: rgba(139, 92, 246, 0.2) !important;
    border-color: rgba(139, 92, 246, 0.45) !important;
    color: var(--text-primary) !important;
}

.dropdown-content {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    background: #0f0f16;
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: var(--radius-md);
    min-width: 220px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    padding: 8px 0;
    z-index: 1000;
}

/* Hover bridge to prevent losing hover status over the gap */
.dropdown-content::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
    background: transparent;
}

/* Modifiers for dropdown alignments */
.dropdown-right .dropdown-content {
    right: 0;
    left: auto;
}

.dropdown-content a {
    color: var(--text-secondary) !important;
    padding: 10px 16px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.87rem;
    font-weight: 500;
    transition: all var(--transition-fast);
    background: none !important;
}

.dropdown-content a::after {
    display: none !important; /* Hide active underline border inside dropdown */
}

.dropdown-content a:hover {
    background: rgba(139, 92, 246, 0.08) !important;
    color: var(--text-primary) !important;
}

.dropdown-content a.active {
    background: rgba(139, 92, 246, 0.12) !important;
    color: var(--accent-secondary) !important;
    font-weight: 600 !important;
}

.dropdown.open .dropdown-content {
    display: block;
}

/* Row Outcome Accents */
tr.row-win {
    border-left: 4px solid #10b981 !important;
    background: rgba(16, 185, 129, 0.02) !important;
}
tr.row-win:hover {
    background: rgba(16, 185, 129, 0.06) !important;
}
tr.row-loss {
    border-left: 4px solid #ef4444 !important;
    background: rgba(239, 68, 68, 0.02) !important;
}
tr.row-loss:hover {
    background: rgba(239, 68, 68, 0.06) !important;
}