/**
 * Common Styles - Shotgun Design System
 */

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

:root {
    /* Palette Shotgun */
    --sg-black: #1B1B1B;
    --sg-grey: #E9ECF1;
    --sg-white: #FFFFFF;
    --sg-beige: #FFFBEE;
    --sg-purple: #8C7FFF;
    --sg-pink: #F26AF2;
    --sg-light-orange: #FFC478;
    --sg-gradient-02-start: #8C7FFF; /* Purple */
    --sg-gradient-02-mid: #F26AF2;   /* Pink */
    --sg-gradient-02-end: #FFC478;   /* Light Orange */
    
    --sg-warm-pink: #EC3C67;
    --sg-orange: #F48A5C;
    --sg-gradient-01-start: #EC3C67; /* Warm Pink */
    --sg-gradient-01-mid: #F48A5C;   /* Orange */
    --sg-gradient-01-end: #FFC478;   /* Light Orange */

    /* Semantic */
    --color-bg: var(--sg-black);
    --color-text: var(--sg-white);
    --color-text-muted: #B5B5B5;
    --color-panel-bg: rgba(27, 27, 27, 0.85);
    --color-border: rgba(255, 255, 255, 0.1);
    
    --font-main: 'Host Grotesk', 'Inter', sans-serif;
}

/* ============================================
   RESET & BASE
   ============================================ */

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

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text);
    height: 100vh;
    overflow: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ============================================
   LAYOUT (SHARED)
   ============================================ */

#canvas-container {
    position: fixed; /* Changed to fixed for global view, but works for knn too if main-content handles sizing */
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    outline: none;
}

/* ============================================
   LEGACY LAYOUT (FOR KNN VIEW)
   ============================================ */

.app-container {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1; /* Ensure it's above the fixed canvas if needed */
}

.sidebar {
    width: 350px;
    background: rgba(27, 27, 27, 0.95);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(10px);
    z-index: 20;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--color-border);
    background: rgba(0,0,0,0.2);
}

.sidebar-header h1 {
    font-family: 'Host Grotesk', sans-serif;
    font-size: 18px;
    margin-bottom: 5px;
    background: linear-gradient(90deg, var(--sg-gradient-02-start), var(--sg-gradient-02-mid));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.sidebar-header h1.has-entity-name {
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    -webkit-text-fill-color: unset;
    color: var(--color-text);
}

.sidebar-header h1 .entity-name-gradient {
    background: linear-gradient(90deg, var(--sg-gradient-02-start), var(--sg-gradient-02-mid));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}


.sidebar-header p {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-bottom: 10px;
}

.sidebar-header .nav-link {
    color: var(--sg-purple);
    text-decoration: none;
    font-size: 12px;
    display: inline-block;
}

.sidebar-header .nav-link:hover {
    text-decoration: underline;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.main-content {
    flex: 1;
    position: relative;
    /* Ensure canvas container inside main-content works correctly */
}

/* Override canvas positioning for legacy layout if it's inside main-content */
.main-content #canvas-container {
    position: absolute;
    width: 100%;
    height: 100%;
}

/* Stats Panel in Sidebar */
.stats-panel {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 15px;
    border: 1px solid var(--color-border);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-label {
    color: var(--color-text-muted);
}

.stat-value {
    color: var(--sg-white);
    font-weight: bold;
}

/* Control Groups in Sidebar */
.control-group {
    margin-bottom: 24px;
}

.control-group h3 {
    margin-bottom: 12px;
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    font-family: 'Host Grotesk', sans-serif;
}

.control-panel {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 15px;
    border: 1px solid var(--color-border);
}

/* ============================================
   GLOBAL VIEW LAYOUT (IMMERSIVE)
   ============================================ */

/* Conteneur pour les UI flottantes */
.ui-layer {
    position: relative;
    z-index: 10;
    width: 100vw;
    height: 100vh;
    pointer-events: none; /* Permet de cliquer sur le canvas à travers */
}

/* Permet de réactiver les clicks sur les éléments UI */
.floating-block, .legend, .controls-hint {
    pointer-events: auto;
}

/* ============================================
   FLOATING BLOCKS
   ============================================ */

.floating-block {
    position: absolute;
    background: var(--color-panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    color: var(--color-text);
    width: 320px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 20;
}

.floating-block:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Positioning */
.block-top-left {
    top: 20px;
    left: 20px;
}

.block-top-right {
    top: 20px;
    right: 20px;
}

.block-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Headers */
.floating-block h3 {
    font-family: 'Host Grotesk', sans-serif;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
    background: linear-gradient(90deg, var(--sg-gradient-02-start), var(--sg-gradient-02-mid));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

/* Branding Header (Top Left) */
.brand-header {
    position: absolute;
    top: 20px;
    left: 20px;
    pointer-events: auto;
    z-index: 20;
}

.brand-title {
    font-family: 'Host Grotesk', sans-serif;
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--sg-white) 0%, var(--sg-grey) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.brand-subtitle {
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 400;
    opacity: 0.8;
}

/* Search Block adjustment (under title) */
.search-block-container {
    position: absolute;
    top: 80px;
    left: 20px;
}

/* ============================================
   COLLAPSIBLE PANELS
   ============================================ */

.collapsible-panel {
    transition: height 0.3s ease, padding 0.3s ease;
    overflow: hidden;
    height: auto; /* Hauteur automatique quand déplié */
}

.collapsible-panel.collapsed {
    height: 60px !important; /* Hauteur du header uniquement */
    padding-bottom: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.panel-header h3 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
    transition: transform 0.3s ease;
}

.collapsible-panel.collapsed .toggle-btn {
    transform: rotate(-90deg);
}

.panel-content {
    margin-top: 16px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.collapsible-panel.collapsed .panel-content {
    opacity: 0;
    pointer-events: none;
}

/* ============================================
   CONTROLS & INPUTS
   ============================================ */

.control-item {
    margin-bottom: 16px;
}

.control-item:last-child {
    margin-bottom: 0;
}

.control-item label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.control-item p {
    font-size: 10px;
    color: var(--color-text-muted);
    opacity: 0.7;
    margin-top: 6px;
}

.field-error-msg {
    font-size: 10px;
    color: var(--sg-warm-pink);
    margin-top: 4px;
    min-height: 14px;
    opacity: 0;
    transition: opacity 0.3s ease;
    font-weight: 600;
}

.field-error-msg.visible {
    opacity: 1;
}

/* Select Styling override */
select {
    width: 100%;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    appearance: none; /* remove default arrow */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFFFFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 8px auto;
}

select:focus {
    outline: none;
    border-color: var(--sg-purple);
    box-shadow: 0 0 0 2px rgba(140, 127, 255, 0.2);
}

/* Custom Checkboxes */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text);
}

.checkbox-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    margin-right: 10px;
    position: relative;
    transition: all 0.2s ease;
}

.checkbox-label input[type="checkbox"]:checked {
    background: var(--sg-gradient-02-mid);
    border-color: transparent;
}

.checkbox-label input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 10px;
    left: 3px;
    top: 0px;
}

/* Buttons */
button {
    background: linear-gradient(135deg, var(--sg-purple), var(--sg-pink));
    border: none;
    border-radius: 8px;
    color: white;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
}

button:hover {
    filter: brightness(1.1);
}

button:active {
    transform: scale(0.98);
}

button.secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

button.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================
   TOM SELECT OVERRIDES (Dark Mode)
   ============================================ */
.ts-control {
    background-color: rgba(0, 0, 0, 0.3) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: 8px !important;
    color: var(--color-text) !important;
    padding: 10px 12px !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

.ts-dropdown {
    background-color: var(--sg-black) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: 8px !important;
    margin-top: 4px !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
    color: var(--color-text) !important;
}

.ts-dropdown .option {
    color: var(--color-text) !important;
}

.ts-dropdown .option.active, .ts-dropdown .option:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: var(--sg-purple) !important;
}

.ts-control input {
    color: var(--color-text) !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

.ts-control .item {
    background: transparent !important;
    color: var(--sg-white) !important; /* Texte blanc comme le reste */
    border-radius: 0 !important;
    margin-right: 4px !important;
    padding: 0 !important; /* Enlève le padding pour que ça ressemble à du texte */
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

.ts-control * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* ============================================
   LEGEND
   ============================================ */
.legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--color-panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--color-border);
    padding: 16px;
    border-radius: 12px;
    z-index: 20;
}

.legend h4 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 10px;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
}

.legend-color.artist { background: var(--sg-orange); box-shadow: 0 0 8px rgba(244, 138, 92, 0.6); }
.legend-color.organiser { background: var(--sg-purple); box-shadow: 0 0 8px rgba(140, 127, 255, 0.6); }
.legend-color.center { background: var(--sg-white); box-shadow: 0 0 8px rgba(255, 255, 255, 0.8); }

/* ============================================
   CONTROLS HINT
   ============================================ */
.controls-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    padding: 10px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    gap: 20px;
    font-size: 11px;
    color: var(--color-text-muted);
    z-index: 20;
    white-space: nowrap;
}

.controls-hint div strong {
    color: var(--sg-white);
    margin-right: 4px;
}

/* ============================================
   LOADING
   ============================================ */
.loading-overlay {
    background: var(--sg-black);
    z-index: 10000; /* Très élevé pour être au-dessus de tout */
    position: fixed; /* Fixed pour couvrir tout l'écran même si dans un conteneur */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    /* Visible par défaut jusqu'à ce que JS le cache */
}

.loading-overlay.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--sg-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-family: 'Host Grotesk', sans-serif;
    letter-spacing: 1px;
    color: var(--color-text-muted);
    font-size: 14px;
}

/* ============================================
   NEIGHBOR ITEMS (pour KNN View - Top 10)
   ============================================ */

.neighbor-item {
    padding: 12px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border-left: 3px solid var(--sg-purple);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.neighbor-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(2px);
}

.neighbor-item:active {
    transform: translateX(4px);
}

.neighbor-rank {
    color: var(--sg-purple);
    font-weight: 700;
    font-size: 11px;
    min-width: 24px;
    flex-shrink: 0;
}

.neighbor-name {
    color: var(--color-text);
    font-weight: 600;
    font-size: 12px;
    flex: 1;
}

.neighbor-details {
    color: var(--color-text-muted);
    font-size: 10px;
    line-height: 1.5;
    margin-top: 6px;
}

.neighbor-tag {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(140, 127, 255, 0.15);
    border-radius: 4px;
    color: var(--sg-purple);
    font-size: 9px;
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden {
    display: none !important;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    /* Global View Responsiveness */
    .floating-block {
        width: calc(100% - 40px);
        left: 20px !important;
        right: 20px !important;
    }
    
    .search-block-container {
        top: 70px;
    }
    
    .block-top-right {
        top: auto;
        bottom: 100px; /* Above legend/hints */
    }
    
    .controls-hint {
        width: 90%;
        flex-wrap: wrap;
        justify-content: center;
        bottom: 10px;
    }

    /* Legacy Layout Responsiveness (KNN) */
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
    
    .main-content {
        height: 60vh;
    }
}
