/* LEMA Admin Dashboard - Main Styles */

/* Theme Variables */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f9f9f9;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #9ca3af;
    --border-color: #dddddd;
    --border-light: #eeeeee;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --skeleton-from: #f0f0f0;
    --skeleton-to: #e0e0e0;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3d3d3d;
    --text-primary: #e5e5e5;
    --text-secondary: #a0a0a0;
    --text-muted: #6b7280;
    --border-color: #404040;
    --border-light: #333333;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --skeleton-from: #3d3d3d;
    --skeleton-to: #4d4d4d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 0;
    transition: background 0.3s, color 0.3s;
}

#dashboardContent,
#brandPageContent {
    padding: 0 20px 20px 20px;
}

/* Login Screen */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.login-card {
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}

.login-card h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group input:focus {
    outline: none;
    border-color: var(--text-primary);
}

.login-btn {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--text-primary);
    background: var(--text-primary);
    color: var(--bg-primary);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    font-weight: 500;
}

.login-btn:hover {
    opacity: 0.9;
}

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

.login-error {
    color: #ef4444;
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    padding: 20px;
    margin: 0;
    z-index: 100;
}

.header.scrolled {
    box-shadow: var(--shadow-sm);
}

/* Theme Toggle */
.theme-toggle {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
}

/* Header Back Button */
.header-back-btn {
    padding: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: background 0.1s;
}

.header-back-btn:hover {
    background: var(--bg-tertiary);
}


.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Brand Search */
.brand-search {
    position: relative;
}

.brand-search input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    width: 200px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.brand-search input:focus {
    outline: none;
    border-color: var(--text-primary);
}

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
    display: none;
}

.search-dropdown.active {
    display: block;
}

.search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background: var(--bg-tertiary);
}

.search-item-logo {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: #e5e7eb;
    object-fit: cover;
}

.search-item-name {
    font-size: 14px;
    font-weight: 500;
}

.search-item-username {
    font-size: 12px;
    color: var(--text-secondary);
}

.search-no-results {
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Initial Avatar (logo fallback) */
.initial-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

h1 {
    font-size: 24px;
    font-weight: 600;
}

.time-selector {
    display: flex;
    gap: 8px;
}

.time-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.time-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

/* Sections */
.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Overview Cards */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
}

.card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.card-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
}

.card-label {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Billing Status */
.billing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.billing-card {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    text-align: center;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}

.billing-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.billing-count {
    font-size: 24px;
    font-weight: 700;
}

.billing-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.billing-card.active { border-left: 4px solid #22c55e; }
.billing-card.trialing { border-left: 4px solid #3b82f6; }
.billing-card.past_due { border-left: 4px solid #f59e0b; }
.billing-card.canceled { border-left: 4px solid #ef4444; }
.billing-card.creating { border-left: 4px solid #8b5cf6; }
.billing-card.none { border-left: 4px solid #9ca3af; }

/* Tables */
.table-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

th:first-child {
    border-top-left-radius: 8px;
}

th:last-child {
    border-top-right-radius: 8px;
}

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

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 var(--border-light);
}

td {
    font-size: 14px;
}

tr.clickable {
    cursor: pointer;
    transition: background 0.1s;
}

tr.clickable:hover {
    background: var(--bg-tertiary);
}

tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}

tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

/* Expandable Leaderboard */
.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.leaderboard-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
}

.expand-btn {
    width: 100%;
    padding: 12px;
    border: none;
    background: var(--bg-tertiary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    transition: background 0.1s;
    color: var(--text-secondary);
}

.expand-btn:hover {
    background: var(--border-light);
}

/* Leaderboard footer for expand button */
.leaderboard-footer {
    display: flex;
    padding: 0;
    background: var(--bg-secondary);
    border-radius: 0 0 8px 8px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.leaderboard-wrapper {
    max-height: none;
    overflow: visible;
    transition: max-height 0.3s ease;
}

.leaderboard-wrapper.expanded {
    max-height: 550px;
    overflow-y: auto;
}

.leaderboard-wrapper.expanded .table-container {
    border-radius: 8px 8px 0 0;
}

.load-more-indicator {
    text-align: center;
    padding: 12px;
    color: var(--text-secondary);
    font-size: 13px;
    background: var(--bg-secondary);
    border-radius: 0 0 8px 8px;
    box-shadow: var(--shadow-sm);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-trialing { background: #dbeafe; color: #1e40af; }
.badge-past_due { background: #fef3c7; color: #92400e; }
.badge-canceled { background: #fee2e2; color: #991b1b; }
.badge-none { background: #f3f4f6; color: #4b5563; }

/* Charts */
.chart-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.chart-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
}

.chart-container {
    position: relative;
    height: 300px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 24px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-title {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
}

.brand-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.brand-list-item.clickable {
    cursor: pointer;
    border-radius: 8px;
    padding: 12px 8px;
    margin: 0 -8px;
    transition: background-color 0.15s ease;
}

.brand-list-item.clickable:hover {
    background-color: var(--bg-tertiary, rgba(0, 0, 0, 0.05));
}

.brand-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #e5e7eb;
    object-fit: cover;
}

.brand-name {
    font-weight: 500;
}

.paid-through {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Live Viewers */
.live-section {
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.live-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.live-dot {
    width: 12px;
    height: 12px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.live-count {
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 4px;
}

.live-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.live-brands {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.live-brand-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 6px;
}

.live-brand-item.clickable {
    cursor: pointer !important;
    background: var(--bg-secondary);
    transition: background 0.15s ease;
}

.live-brand-item.clickable:hover {
    background: var(--bg-tertiary);
}

.live-brand-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-brand-logo {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background: #e5e7eb;
    object-fit: cover;
}

.live-brand-name {
    font-size: 13px;
    font-weight: 500;
}

.live-brand-count {
    font-size: 13px;
    font-weight: 600;
    color: #22c55e;
}

.reload-btn {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.1s;
    color: var(--text-primary);
}

.reload-btn:hover {
    background: var(--bg-tertiary);
}

.reload-btn:active {
    background: var(--border-light);
}

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

/* Loading states */
.loading {
    opacity: 0.5;
    pointer-events: none;
}

.skeleton {
    background: linear-gradient(90deg, var(--skeleton-from) 25%, var(--skeleton-to) 50%, var(--skeleton-from) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Chart tooltip */
.chart-tooltip-custom {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-shadow: var(--shadow-md);
    font-size: 12px;
    pointer-events: none;
    color: var(--text-primary);
}

.tooltip-date {
    font-weight: 600;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.tooltip-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.tooltip-logo {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: #e5e7eb;
    object-fit: cover;
}

.tooltip-name {
    flex: 1;
}

.tooltip-value {
    font-weight: 600;
}

.tooltip-party-name {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Hidden parties toggle */
.hidden-parties-toggle {
    padding: 12px;
    text-align: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-top: 12px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
}

.hidden-parties-toggle:hover {
    background: var(--border-light);
}

.hidden-parties-section {
    margin-top: 12px;
}

.hidden-parties-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    font-weight: 600;
}

/* Brand Page */
.brand-page {
    max-width: 1200px;
    margin: 0 auto;
}

.brand-page-back {
    margin-bottom: 16px;
}

.back-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.1s;
    color: var(--text-primary);
}

.back-btn:hover {
    background: var(--bg-tertiary);
}

.brand-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.brand-page-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-page-logo {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
    background: #e5e7eb;
}

.brand-page-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.brand-page-name {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
}

.brand-page-username {
    font-size: 14px;
    color: var(--text-secondary);
}

.brand-page-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.brand-page-paid-through {
    font-size: 12px;
    color: var(--text-secondary);
}

.view-brand-btn {
    padding: 10px 20px;
    background: var(--text-primary);
    color: var(--bg-primary);
    border: 1px solid var(--text-primary);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: opacity 0.1s;
}

.view-brand-btn:hover {
    opacity: 0.9;
}

/* Party status badges */
.badge-announced { background: #dbeafe; color: #1e40af; }
.badge-ongoing { background: #dcfce7; color: #166534; }
.badge-ended { background: #f3f4f6; color: #4b5563; }
.badge-on_queue { background: #fef3c7; color: #92400e; }
