﻿/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
    --brand-red: #EA7600;
    --header-bg: #FFFFFF;
    --bg-canvas: #E8E8E8;
    --card-surface: #FFFFFF;
    --table-header-bg: #1a1a1a;
    --text-dark: #202020;
    --text-gray: #888;
    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.08);
    --radius: 8px;
    --font: 'Inter', sans-serif;
}

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

/* ============================================
   BODY - FIXED VIEWPORT
   ============================================ */
body {
    font-family: var(--font);
    background-color: var(--bg-canvas);
    color: var(--text-dark);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   HEADER
   ============================================ */
.main-header {
    height: 56px;
    background-color: var(--header-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    transition: background-color 0.3s ease;
}

.logo {
    font-family: var(--font);
    font-size: 1.5rem;
    font-weight: 900;
    font-style: italic;
}

.logo-running {
    color: var(--text-dark);
}

.logo-puch {
    color: var(--brand-red);
}

/* Main Nav */
.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #666;
    text-decoration: none;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--text-dark);
    background: rgba(0, 0, 0, 0.05);
}

.nav-link.active {
    color: #fff;
    background: var(--brand-red);
}

.nav-link svg {
    flex-shrink: 0;
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-avatar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #ddd;
    background: #f0f0f0;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.user-avatar-btn:hover {
    border-color: var(--brand-red);
    color: var(--brand-red);
}

.user-dropdown {
    display: none;
    position: absolute;
    top: 110%;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    z-index: 100;
    min-width: 180px;
    overflow: hidden;
}

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

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    color: #444;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
}

.user-dropdown-item:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-dark);
}

.user-dropdown-item svg {
    flex-shrink: 0;
    opacity: 0.6;
}

/* ============================================
   MAIN LAYOUT
   ============================================ */
.main-layout {
    display: grid;
    grid-template-columns: 242px 1fr 242px;
    /* 220 * 1.1 = 242 => 10% bigger */
    gap: 20px;
    flex: 1;
    overflow: hidden;
    padding: 15px 20px;
}

/* ============================================
   PHONE FRAME ADS
   ============================================ */
.ad-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    overflow: hidden;
}

.phone-frame {
    width: 100%;
    max-width: 220px;
    aspect-ratio: 9 / 17;
    max-height: 95%;
    background: #111;
    border-radius: 28px;
    border: 3px solid #333;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35),
        inset 0 0 0 2px #222;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.phone-notch {
    width: 80px;
    height: 6px;
    background: #333;
    border-radius: 3px;
    margin: 8px auto 4px;
    flex-shrink: 0;
}

.phone-screen {
    flex: 1;
    position: relative;
    overflow: hidden;
    margin: 0 4px;
    border-radius: 4px;
}

.carousel-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.8s ease-in-out;
}

.carousel-img.active {
    opacity: 1;
}

.phone-swipe-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 8px 0;
    flex-shrink: 0;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #555;
    transition: background 0.3s;
}

.dot.active {
    background: #fff;
}

/* ============================================
   CENTER CONTENT
   ============================================ */
.center-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.page-title {
    text-align: center;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 10px;
    flex-shrink: 0;
}

/* ============================================
   CONTROLS BAR (Filters + Sort)
   ============================================ */
.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.filters-group,
.sort-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.controls-bar label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* FILTER DROPDOWN */
.filter-dropdown {
    position: relative;
}

.filter-btn {
    background: var(--card-surface);
    border: 1px solid #ddd;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    color: #333;
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: var(--brand-red);
    color: var(--brand-red);
}

.filter-btn.active-filter {
    background: var(--brand-red);
    color: #fff;
    border-color: var(--brand-red);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 110%;
    left: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 50;
    min-width: 140px;
    max-height: 200px;
    overflow-y: auto;
}

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

.dropdown-item {
    padding: 8px 14px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: #f5f5f5;
}

.dropdown-item.selected {
    background: #fdeaea;
    color: var(--brand-red);
    font-weight: 700;
}

/* CLEAR BUTTON */
.clear-btn {
    background: none;
    border: none;
    color: #999;
    font-size: 0.7rem;
    cursor: pointer;
    padding: 5px 8px;
    font-weight: 600;
    transition: color 0.2s;
}

.clear-btn:hover {
    color: var(--brand-red);
}

/* SEARCH INPUT */
.search-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.search-wrapper {
    position: relative;
}

.search-input {
    background: var(--card-surface);
    border: 1px solid #ddd;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #333;
    width: 220px;
    outline: none;
    transition: border-color 0.2s;
    font-family: var(--font);
}

.search-input:focus {
    border-color: var(--brand-red);
}

.search-input::placeholder {
    color: #aaa;
}

.search-suggestions {
    display: none;
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 60;
    max-height: 200px;
    overflow-y: auto;
}

.search-suggestions.open {
    display: block;
}

.suggestion-item {
    padding: 8px 14px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggestion-item:hover {
    background: #f5f5f5;
}

.suggestion-item mark {
    background: #fdeaea;
    color: var(--brand-red);
    font-weight: 700;
    border-radius: 2px;
    padding: 0 1px;
}

/* ============================================
   TABLE HEADER
   ============================================ */
.table-header {
    background-color: var(--table-header-bg);
    color: #fff;
    display: grid;
    grid-template-columns: 40px 80px 55px 1fr 40px 50px 60px 55px 85px;
    padding: 10px 14px;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
    gap: 4px;
}

.th {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.th.sortable:hover {
    color: #ffcccc;
}

.th.sortable.active-sort {
    color: var(--brand-red);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.sort-arrow {
    font-size: 0.6rem;
    opacity: 0.5;
}

.th.sortable.active-sort .sort-arrow {
    opacity: 1;
}

.th.clientes,
.th.tkts,
.th.importe {
    text-align: right;
}

/* ============================================
   SCROLLABLE LIST
   ============================================ */
.ranking-list {
    flex: 1;
    overflow-y: auto;
    position: relative;
    width: 100%;
    min-height: 0;
    background: #fff;
    scrollbar-width: thin;
    scrollbar-color: #ccc #f0f0f0;
}


/* ============================================
   STORE ROW
   ============================================ */
.store-row {
    background-color: var(--card-surface);
    display: grid;
    grid-template-columns: 40px 80px 55px 1fr 40px 50px 60px 55px 85px;
    padding: 12px 14px;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    transition: background-color 0.2s;
    gap: 4px;
}

.store-row:last-child {
    border-bottom: none;
    border-radius: 0 0 var(--radius) var(--radius);
}

.store-row:hover {
    background-color: #fafafa;
}

/* Cell styles */
.cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
}

.cell.rank-num {
    font-weight: 800;
    font-size: 0.95rem;
    color: #333;
}

.store-row.top-1 .cell.rank-num {
    font-size: 1.8rem;
}

.store-row.top-2 .cell.rank-num {
    font-size: 1.5rem;
}

.store-row.top-3 .cell.rank-num {
    font-size: 1.3rem;
}

.cell.marca {
    font-weight: 600;
    color: #333;
}

.cell.fqcia {
    font-weight: 500;
    color: #666;
}

.cell.tienda {
    font-weight: 600;
    color: #222;
}

.cell.tipo {
    font-weight: 500;
    color: #888;
    font-size: 0.72rem;
}

.cell.ciudad {
    font-weight: 600;
    color: #555;
    font-size: 0.72rem;
}

.cell.clientes,
.cell.tkts {
    text-align: right;
    font-weight: 600;
    color: #555;
}

.cell.importe {
    text-align: right;
    font-weight: 800;
    color: var(--brand-red);
}

/* ============================================
   FOOTER
   ============================================ */
.main-footer {
    background-color: var(--header-bg);
    padding: 8px 40px;
    flex-shrink: 0;
    text-align: center;
}

.footer-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.social-label {
    color: #aaa;
    font-size: 0.7rem;
    font-weight: 500;
}

.social-icons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.social-icons a {
    display: flex;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.social-icons a:hover {
    opacity: 1;
}

.footer-legal {
    color: #777;
    font-size: 0.5rem;
    border-top: 1px solid #ddd;
    padding-top: 4px;
}

.social-label {
    color: #666;
}

/* ============================================
   CONFETTI CANVAS
   ============================================ */
.confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* ============================================
   WHATSAPP BUTTON
   ============================================ */
.whatsapp-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: #25D366;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(37, 211, 102, 0.4);
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
}

.whatsapp-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.5);
}

.whatsapp-btn svg {
    width: 30px;
    height: 30px;
    fill: #fff;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 200px 1fr 200px;
        gap: 10px;
        padding: 10px;
    }

    .table-header,
    .store-row {
        grid-template-columns: 35px 70px 50px 1fr 35px 45px 55px 50px 75px;
        padding: 10px 10px;
    }
}

@media (max-width: 950px) {
    body {
        height: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .main-layout {
        grid-template-columns: 1fr;
        overflow: visible;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .center-content {
        overflow: visible;
        height: auto;
    }

    .ranking-list {
        overflow-y: visible;
        min-height: 300px;
    }

    .ad-slot {
        display: none;
    }

    .main-header {
        padding: 0 15px;
    }
}

@media (max-width: 700px) {

    .table-header,
    .store-row {
        grid-template-columns: 35px 70px 1fr 55px 55px 75px;
    }

    .th.fqcia,
    .store-row .cell.fqcia,
    .th.tipo,
    .store-row .cell.tipo,
    .th.ciudad,
    .store-row .cell.ciudad {
        display: none;
    }

    .controls-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .main-nav {
        display: none;
    }
}

@media (max-width: 500px) {

    .table-header,
    .store-row {
        grid-template-columns: 30px 60px 1fr 65px;
    }

    .th.clientes,
    .store-row .cell.clientes,
    .th.tkts,
    .store-row .cell.tkts {
        display: none;
    }

    .page-title {
        font-size: 1.3rem;
    }

    .logo {
        font-size: 1.1rem;
    }
}

/* ============================================
   DARK THEME OVERRIDES
   ============================================ */
body.dark-theme {
    --bg-canvas: #121212;
    --card-surface: #1e1e1e;
    --header-bg: #0a0a0a;
    --table-header-bg: #111;
    --text-dark: #e0e0e0;
    --text-gray: #999;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
}

body.dark-theme .page-title {
    color: #e0e0e0;
}

body.dark-theme .controls-bar label {
    color: #aaa;
}

body.dark-theme .filter-btn {
    background: #2a2a2a;
    border-color: #444;
    color: #ccc;
}

body.dark-theme .filter-btn:hover {
    border-color: var(--brand-red);
    color: var(--brand-red);
}

body.dark-theme .dropdown-menu {
    background: #2a2a2a;
    border-color: #444;
}

body.dark-theme .dropdown-item {
    color: #f0f0f0;
}

body.dark-theme .dropdown-item:hover {
    background: #333;
}

body.dark-theme .dropdown-item.selected {
    background: #3a1a1a;
    color: var(--brand-red);
}

body.dark-theme .clear-btn {
    color: #888;
}

body.dark-theme .clear-btn:hover {
    color: var(--brand-red);
}

body.dark-theme .search-input {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
}

body.dark-theme .search-input:focus {
    border-color: var(--brand-red);
}

body.dark-theme .search-suggestions {
    background: #2a2a2a;
    border-color: #444;
}

body.dark-theme .suggestion-item {
    color: #f0f0f0;
}

body.dark-theme .suggestion-item:hover {
    background: #333;
}

body.dark-theme .suggestion-item mark {
    background: rgba(234, 118, 0, 0.2);
}

body.dark-theme .ranking-list {
    background: #1e1e1e;
    scrollbar-color: #555 #1e1e1e;
}

body.dark-theme .store-row {
    border-bottom-color: #333;
}

body.dark-theme .store-row:hover {
    background-color: #2a2a2a;
}

body.dark-theme .cell.rank-num,
body.dark-theme .cell.marca,
body.dark-theme .cell.tienda {
    color: #e0e0e0;
}

body.dark-theme .cell.fqcia,
body.dark-theme .cell.tipo,
body.dark-theme .cell.ciudad,
body.dark-theme .cell.clientes,
body.dark-theme .cell.tkts {
    color: #999;
}

body.dark-theme .footer-legal {
    color: #777;
    border-top-color: #333;
}

/* --- Header, Nav, User Menu in dark --- */
body.dark-theme .main-header {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

body.dark-theme .logo-running {
    color: #fff;
}

body.dark-theme .nav-link {
    color: #999;
}

body.dark-theme .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

body.dark-theme .user-avatar-btn {
    background: #333;
    border-color: #444;
    color: #ccc;
}

body.dark-theme .user-avatar-btn:hover {
    border-color: var(--brand-red);
    color: #fff;
}

body.dark-theme .user-dropdown {
    background: #2a2a2a;
    border-color: #444;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

body.dark-theme .user-dropdown-item {
    color: #ccc;
}

body.dark-theme .user-dropdown-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

body.dark-theme .social-label {
    color: #aaa;
}

body.dark-theme .phone-frame {
    border-color: #444;
}