/* ============================================================
 * Playmetric — Application Styles
 * Extracted from inline <style> in index.html
 * ============================================================ */

:root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 3.9%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
    --radius: 0.5rem;
}

/* Custom Toggle Switch - Green when checked */
.peer:checked~div {
    background-color: #22c55e !important;
}

/* Game card with edit permission - green gradient from bottom */
.game-card-editable::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 200% 140% at 130% 110%, rgba(34, 197, 94, 0.2) 0%, transparent 75%);
    pointer-events: none;
    border-radius: inherit;
    z-index: 0;
}

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

/* Permission-gated elements: JS (applyPermissionGuards) controls display via inline style.
   Initial state set to none so elements are hidden before JS runs.
   Note: JS uses style.setProperty with !important to override Tailwind utilities if any. */
[data-require-permission]:not([data-perm-checked]) {
    display: none;
}

/* Essential for JS panel switching */

.panel {
    display: none;
}

.panel.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: hsl(var(--muted));
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground));
}

.game-image {
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--secondary)));
}

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.online-dot.active {
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.online-dot.offline {
    background: #6b7280;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: hsl(var(--muted));
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

/* Toggle Switch Green Color */
.switch input:checked+.slider {
    background-color: #22c55e;
}

.switch input:checked+.slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* ── Stat Number Live-Update Flash ─────────────────────────────────────────── */
@keyframes stat-flash-up {
    0% {
        color: inherit;
        text-shadow: none;
    }

    20% {
        color: #4ade80;
        text-shadow: 0 0 12px rgba(74, 222, 128, 0.9), 0 0 24px rgba(74, 222, 128, 0.5);
        transform: scale(1.12);
    }

    60% {
        color: #86efac;
        text-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
        transform: scale(1.04);
    }

    100% {
        color: inherit;
        text-shadow: none;
        transform: scale(1);
    }
}

@keyframes stat-flash-down {
    0% {
        color: inherit;
        text-shadow: none;
    }

    20% {
        color: #f87171;
        text-shadow: 0 0 12px rgba(248, 113, 113, 0.9), 0 0 24px rgba(248, 113, 113, 0.5);
        transform: scale(1.08);
    }

    60% {
        color: #fca5a5;
        text-shadow: 0 0 6px rgba(248, 113, 113, 0.4);
        transform: scale(1.02);
    }

    100% {
        color: inherit;
        text-shadow: none;
        transform: scale(1);
    }
}

@keyframes stat-flash-neutral {
    0% {
        text-shadow: none;
    }

    25% {
        text-shadow: 0 0 10px rgba(148, 163, 184, 0.8), 0 0 20px rgba(148, 163, 184, 0.4);
        transform: scale(1.06);
    }

    100% {
        text-shadow: none;
        transform: scale(1);
    }
}

.stat-flash-up {
    animation: stat-flash-up 1.4s ease-out forwards;
}

.stat-flash-down {
    animation: stat-flash-down 1.4s ease-out forwards;
}

.stat-flash-neutral {
    animation: stat-flash-neutral 1.0s ease-out forwards;
}

/* Game Card Highlight Animation */
@keyframes game-highlight-glow {

    0%,
    100% {
        box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
        border-color: hsl(var(--border));
    }

    50% {
        box-shadow: 0 0 0 4px hsl(var(--primary) / 0.3), 0 0 32px hsl(var(--primary) / 0.7), 0 0 0 2px hsl(var(--primary) / 0.5);
        border-color: hsl(var(--primary));
        transform: translateY(-2px);
    }
}

.game-card-highlight {
    animation: game-highlight-glow 1.8s ease-in-out;
}

/* ===== MOBILE SIDEBAR ===== */
#sidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 768px) {
    #sidebar {
        transform: translateX(-100%);
    }

    #sidebar.sidebar-open {
        transform: translateX(0);
    }

    #mainContent {
        margin-left: 0 !important;
    }
}

/* ===== GLOBAL OVERFLOW PROTECTION ===== */
.panel {
    max-width: 100% !important;
    box-sizing: border-box;
}

/* Tab bar — hide scrollbar but allow horizontal scroll */
.game-info-tab {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Hide scrollbar on tab bars (webkit + firefox) */
[style*="scrollbar-width:none"] {
    scrollbar-width: none;
}

[style*="scrollbar-width:none"]::-webkit-scrollbar {
    display: none;
}

/* Prevent any chart or grid from overflowing its container */
.apexcharts-canvas {
    max-width: 100% !important;
}

/* Header revenue/sales stat pills — shown when data-active is set by JS */
/* These live inside a hidden md:flex parent, so they appear only on md+ automatically */
#headerRevenueStat[data-active="true"],
#headerSalesStat[data-active="true"] {
    display: flex !important;
}

/* Prevent table overflow on small screens */
@media (max-width: 640px) {
    .fin-btn-group {
        flex-wrap: wrap;
    }
}

#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 40;
    backdrop-filter: blur(2px);
}

#sidebarOverlay.active {
    display: block;
}

#hamburgerBtn {
    display: none;
}

@media (max-width: 768px) {
    #hamburgerBtn {
        display: flex;
    }
}

/* Background Banner */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/assets/brand/background_banner.png');
    background-size: cover;
    background-position: center;
    opacity: 0.15;
    filter: blur(8px);
    z-index: -1;
    pointer-events: none;
}

@keyframes firefly {
    0% {
        opacity: 0.05;
    }

    50% {
        opacity: 0.12;
        filter: blur(12px) brightness(0.6) hue-rotate(5deg);
    }

    100% {
        opacity: 0.05;
    }
}

@keyframes drift {
    0% {
        background-position: center;
    }

    50% {
        background-position: center 20px;
    }

    100% {
        background-position: center;
    }
}

/* ===== SHADCN/UI — CUSTOM SELECT STYLES ===== */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: hsl(var(--secondary));
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 2rem !important;
    color: hsl(var(--foreground));
    border-color: hsl(var(--border));
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

select:hover {
    background-color: hsl(var(--accent));
    border-color: hsl(var(--ring) / 0.5);
}

select:focus {
    outline: none;
    box-shadow: 0 0 0 1px hsl(var(--ring));
    border-color: hsl(var(--ring));
}

select option {
    background-color: hsl(var(--card));
    color: hsl(var(--foreground));
    padding: 8px 12px;
}

/* Compact variant used inside task panel */
select.select-sm {
    font-size: 0.8125rem;
}

/* ===== FINANCIAL DASHBOARD ===== */

/* Button groups (period / group / chart type) */
.fin-btn-group {
    display: inline-flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--secondary));
}

.fin-btn-group button {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    line-height: 1.4;
}

.fin-btn-group button:not(:last-child) {
    border-right: 1px solid hsl(var(--border));
}

.fin-btn-group button:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}

.fin-btn-group button.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

/* Stat cards */
.fin-stat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid color-mix(in srgb, var(--accent, #facc15) 20%, transparent);
    background: color-mix(in srgb, var(--accent, #facc15) 5%, transparent);
    transition: border-color 0.2s, background 0.2s;
}

.fin-stat-card:hover {
    border-color: color-mix(in srgb, var(--accent, #facc15) 35%, transparent);
    background: color-mix(in srgb, var(--accent, #facc15) 8%, transparent);
}

.fin-stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--accent, #facc15) 12%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--accent, #facc15);
    font-size: 14px;
}

.fin-stat-label {
    font-size: 11px;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.fin-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: hsl(var(--foreground));
    font-variant-numeric: tabular-nums;
    margin-top: 1px;
}

.fin-stat-sub {
    font-size: 10px;
    color: hsl(var(--muted-foreground));
    margin-top: 1px;
}

/* ─── Custom date range row ─────────────────────────────── */

.fin-custom-date-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: 4px;
    animation: finFadeIn 0.18s ease;
}

.fin-custom-date-row.hidden {
    display: none !important;
}

@keyframes finFadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

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

.fin-date-input {
    height: 32px;
    padding: 0 10px;
    border-radius: 7px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(255, 255, 255, 0.04);
    color: hsl(var(--foreground));
    font-size: 12px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    color-scheme: dark;
}

.fin-date-input:focus {
    border-color: rgba(99, 102, 241, 0.55);
    background: rgba(99, 102, 241, 0.06);
}

.fin-date-input.fin-date-error {
    border-color: rgba(239, 68, 68, 0.6) !important;
    background: rgba(239, 68, 68, 0.06) !important;
    animation: finShake 0.3s ease;
}

@keyframes finShake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.fin-apply-btn {
    height: 32px;
    padding: 0 14px;
    border-radius: 7px;
    border: 1px solid rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.14);
    color: #a5b4fc;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.fin-apply-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.55);
    color: #c7d2fe;
}


/* ─── Leaflet Choropleth World Map ─────────────────────────── */

.leaflet-container {
    background: #0f172a !important;
    font-family: Inter, system-ui, sans-serif;
}

.fin-leaflet-tooltip {
    background: rgba(15, 23, 42, 0.95) !important;
    border: 1px solid rgba(148, 163, 184, 0.15) !important;
    border-radius: 10px !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
    padding: 10px 14px !important;
    color: #e2e8f0 !important;
    backdrop-filter: blur(8px);
    pointer-events: none;
    max-width: 220px;
}

.fin-leaflet-tooltip::before {
    display: none !important;
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5) !important;
}

.leaflet-control-zoom a {
    background: rgba(15, 23, 42, 0.92) !important;
    color: #94a3b8 !important;
    border: 1px solid rgba(148, 163, 184, 0.15) !important;
    font-size: 16px !important;
    line-height: 28px !important;
    width: 28px !important;
    height: 28px !important;
    transition: background 0.15s, color 0.15s;
}

.leaflet-control-zoom a:hover {
    background: rgba(99, 102, 241, 0.2) !important;
    color: #e2e8f0 !important;
}

.leaflet-control-zoom-in {
    border-radius: 6px 6px 0 0 !important;
}

.leaflet-control-zoom-out {
    border-radius: 0 0 6px 6px !important;
}

.leaflet-control-attribution {
    display: none !important;
}

/* ─── Game Library Groups ─────────────────────────────────── */

/* Group section spans full grid width */
.game-group-section {
    grid-column: 1 / -1;
}

/* The inner grid within each group — explicit responsive columns matching #gamesGrid */
.game-group-grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 1.5rem;
}

@media (min-width: 640px) {
    .game-group-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .game-group-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1280px) {
    .game-group-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1536px) {
    .game-group-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}


/* Sortable ghost (semi-transparent placeholder while dragging) */
.sortable-ghost {
    opacity: 0.35;
    border: 2px dashed hsl(var(--primary) / 0.6) !important;
    background: hsl(var(--primary) / 0.06) !important;
    border-radius: 12px;
}

/* The card being dragged */
.sortable-drag {
    opacity: 0.95;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 2px hsl(var(--primary) / 0.4);
    rotate: 1.5deg;
}

/* Drag handle cursor */
.drag-handle {
    cursor: grab !important;
}

.drag-handle:active {
    cursor: grabbing !important;
}

/* ── Player count badge — fire icon & glow ───────────────────────────────── */

/* Fire icon: animates with a flicker to draw attention */
@keyframes fireFlicker {

    0%,
    100% {
        opacity: 1;
        transform: scaleY(1) rotate(-2deg);
    }

    25% {
        opacity: 0.8;
        transform: scaleY(1.08) rotate(2deg);
    }

    50% {
        opacity: 1;
        transform: scaleY(0.95) rotate(-1deg);
    }

    75% {
        opacity: 0.9;
        transform: scaleY(1.05) rotate(1deg);
    }
}

.card-player-fire {
    color: #f97316;
    animation: fireFlicker 0.9s ease-in-out infinite;
    display: inline-block;
    font-size: 0.7em;
    vertical-align: middle;
    filter: drop-shadow(0 0 4px rgba(251, 146, 60, 0.7));
}

/* Text glow: pulsing warm glow when player count is below peak */
@keyframes playerGlow {

    0%,
    100% {
        text-shadow: 0 0 5px rgba(251, 146, 60, 0.5);
    }

    50% {
        text-shadow: 0 0 12px rgba(251, 146, 60, 0.9), 0 0 24px rgba(239, 68, 68, 0.4);
    }
}

.card-player-glow {
    animation: playerGlow 1.8s ease-in-out infinite;
}



/* ===== iOS PWA SAFE AREA INSETS =====
 * viewport-fit=cover ile içerik notch/status bar ve home indicator
 * alanının altına uzanır. Bu kurallar tıklanamaz bölgeleri düzeltir.
 * env() değerleri yalnızca iPhone standalone modunda aktif olur,
 * diğer cihazlarda 0px olarak çalışır — yan etki yok.
 * ===================================================== */

/* Body'nin tamamını safe area'nın altına it.
 * Header'ın kendi içeriğini bozmadan tüm layout doğru yerden başlar. */
body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Sidebar da body'den bağımsız fixed olduğu için ayrıca hesaplamalı */
#sidebar {
    top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
}

/* Scrollable içerik alanı da alt safe area'yı hesaplayacak */
#mainContent>div[class*="overflow-y-auto"] {
    padding-bottom: max(2rem, calc(2rem + env(safe-area-inset-bottom)));
}

/* =============================================
 * RBAC Permission Guards — CSS-based show/hide
 *
 * Convention:
 *   permission key:  "reviews.analytics.view"
 *   body class:      "perm-reviews-analytics-view"   (set by applyPermissionGuards)
 *   guard class:     "perm-guard-reviews-analytics-view"  (on the element)
 *
 * All guard elements are hidden by default.
 * When body has the matching perm-* class, the element becomes visible.
 * Admins get perm-admin class, which overrides all guards.
 * ============================================= */

/* ── Base rule: all guard elements are hidden ─ */
[class*="perm-guard-"] {
    display: none !important;
}

/* ── Admin override: show everything ─────────── */
body.perm-admin [class*="perm-guard-"] {
    display: revert !important;
}

/* ── Reviews ─────────────────────────────────── */
body.perm-reviews-analytics-view .perm-guard-reviews-analytics-view {
    display: revert !important;
}

/* backward-compat alias (old class name in HTML) */
body.perm-reviews-analytics-view .perm-guard-reviews-analytics {
    display: revert !important;
}

body.perm-reviews-ai-refresh .perm-guard-reviews-ai-refresh {
    display: revert !important;
}

/* ── Marketing ───────────────────────────────── */
body.perm-marketing-data-create .perm-guard-marketing-data-create {
    display: revert !important;
}

/* backward-compat alias (old class name in HTML) */
body.perm-marketing-data-create .perm-guard-marketing-create {
    display: revert !important;
}

body.perm-marketing-data-edit .perm-guard-marketing-data-edit {
    display: revert !important;
}

/* backward-compat alias */
body.perm-marketing-data-edit .perm-guard-marketing-edit {
    display: revert !important;
}

body.perm-marketing-data-delete .perm-guard-marketing-data-delete {
    display: revert !important;
}

/* backward-compat alias */
body.perm-marketing-data-delete .perm-guard-marketing-delete {
    display: revert !important;
}

/* ── Games ───────────────────────────────────── */
body.perm-games-create .perm-guard-games-create {
    display: revert !important;
}

body.perm-games-edit-global .perm-guard-games-edit-global {
    display: revert !important;
}

body.perm-games-admin-global .perm-guard-games-admin-global {
    display: revert !important;
}

/* ── Settings ────────────────────────────────── */
body.perm-settings-manage-roles .perm-guard-settings-manage-roles {
    display: revert !important;
}

/* ── Users (in Settings > Members tab) ───────── */
body.perm-users-create .perm-guard-users-create {
    display: revert !important;
}

body.perm-users-edit .perm-guard-users-edit {
    display: revert !important;
}

body.perm-users-delete .perm-guard-users-delete {
    display: revert !important;
}

/* ── Finance (global) ────────────────────────── */
body.perm-finance-view-global .perm-guard-finance-view-global {
    display: revert !important;
}

body.perm-finance-export-global .perm-guard-finance-export-global {
    display: revert !important;
}

/* ── Logs ────────────────────────────────────── */
body.perm-logs-view .perm-guard-logs-view {
    display: revert !important;
}

/* ── Todo ────────────────────────────────────── */
body.perm-todo-create .perm-guard-todo-create {
    display: revert !important;
}

body.perm-todo-delete .perm-guard-todo-delete {
    display: revert !important;
}