/* Location Tool - Styles */
:root {
    --bg-dark: #1a1a2e;
    --bg-darker: #16213e;
    --bg-card: #1f2937;
    --bg-input: #374151;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #374151;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    
    /* Couleurs de légende */
    --color-both: #22c55e;
    --color-narrative: #f97316;
    --color-location: #3b82f6;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-wrap: wrap;
}

.top-bar .left,
.top-bar .right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.top-bar h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-input);
    border-radius: 6px;
    text-decoration: none;
    font-size: 1.1rem;
    transition: background 0.2s;
}

.nav-link:hover {
    background: var(--accent);
}

.badge {
    background: var(--accent);
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.separator {
    color: var(--border);
    margin: 0 0.25rem;
}

/* Buttons */
button {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: all 0.2s;
}

button:hover:not(:disabled) {
    background: var(--bg-card);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.primary {
    background: var(--accent);
    color: white;
}

button.primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

button.danger {
    background: var(--danger);
    color: white;
}

button.danger:hover:not(:disabled) {
    background: #dc2626;
}

button.secondary {
    background: var(--bg-input);
}

.btn-create {
    background: var(--success);
    color: white;
}

.btn-create:hover {
    background: #059669;
}

.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* Checkbox label */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.checkbox-label input {
    cursor: pointer;
}

/* Select */
select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Layout */
.layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--bg-darker);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.panel {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.panel h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

/* Fields */
.field {
    margin-bottom: 0.75rem;
}

.field label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
}

.field-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* Autocomplete field */
.autocomplete-field {
    position: relative;
}

.autocomplete-field .dropdown-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
}

.autocomplete-field .dropdown-toggle:hover {
    color: var(--text-primary);
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.autocomplete-dropdown.show {
    display: block;
}

.autocomplete-option {
    padding: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.autocomplete-option:hover {
    background: var(--bg-input);
}

/* Actions */
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.actions-hint {
    margin-top: 0.5rem;
    text-align: center;
    width: 100%;
}

.actions button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Locations list */
.locations-legend {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Locations list container */
.locations-list-container {
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
}

.locations-list {
    list-style: none;
    padding: 0.25rem;
}

.locations-list li {
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.85rem;
    transition: background 0.2s;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.locations-list li:hover {
    background: var(--bg-card);
    border-color: var(--border);
}

.locations-list li.selected {
    background: var(--accent);
    border-color: var(--accent-hover);
}

.locations-list li .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 3px;
}

.locations-list li .status-dot.both {
    background: var(--color-both);
}

.locations-list li .status-dot.narrative {
    background: var(--color-narrative);
}

.locations-list li .status-dot.location {
    background: var(--color-location);
}

.locations-list li .loc-content {
    flex: 1;
    min-width: 0;
}

.locations-list li .loc-name {
    display: block;
    word-wrap: break-word;
    white-space: normal;
    line-height: 1.3;
}

.locations-list li .loc-info {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Environments list */
.environments-list {
    list-style: none;
}

.environments-list li {
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.environments-list li:hover {
    background: var(--bg-input);
}

.environments-list li.active {
    background: var(--accent);
}

.environments-list li .env-count {
    font-size: 0.7rem;
    background: var(--bg-input);
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
}

/* Links container */
#loc-links-container,
#loc-env-links-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

/* Styles obsolètes supprimés - voir section "Style pour les liens dans le panel" plus bas */

/* Canvas */
.canvas-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #0f0f1a;
}

.canvas-wrapper {
    width: 100%;
    height: 100%;
    overflow: auto;
    position: relative;
}

.canvas {
    position: relative;
    min-width: 3000px;
    min-height: 2000px;
    background: 
        linear-gradient(rgba(59, 130, 246, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(59, 130, 246, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
}

.connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
}

.segments-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* Location card */
.location-card {
    position: absolute;
    width: 280px;
    min-height: 80px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: grab;
    transition: box-shadow 0.2s, border-color 0.2s;
    overflow: hidden;
}

.location-card:hover {
    border-color: var(--accent);
}

.location-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3), var(--shadow);
}

.location-card.dragging {
    cursor: grabbing;
    opacity: 0.9;
    z-index: 1000;
}

.location-card .card-header {
    padding: 0.6rem 0.75rem;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
}

.location-card .card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    word-wrap: break-word;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.location-card .card-body {
    padding: 0.6rem 0.75rem;
}

.location-card .card-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.location-card .card-info span {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.location-card .card-links,
.location-card .card-env-links {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.location-card .card-links-title {
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.location-card .card-link-item {
    padding: 0.25rem 0;
    padding-left: 0.5rem;
    color: var(--text-secondary);
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.3;
}

.location-card .card-link-item.link-other-env,
.location-card .card-link-item.link-external {
    color: var(--accent);
}

/* Sub-segment cards (separate draggable elements for external links) */
.sub-segment-card {
    position: absolute;
    min-width: 160px;
    max-width: 240px;
    background: var(--bg-card);
    border: 2px dashed var(--accent);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: grab;
    transition: box-shadow 0.2s, border-color 0.2s;
    z-index: 1;
}

.sub-segment-card:hover {
    border-style: solid;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.sub-segment-card.dragging {
    cursor: grabbing;
    opacity: 0.9;
    z-index: 1000;
}

.sub-segment-card.dir-to {
    border-color: #3b82f6;
}

.sub-segment-card.dir-from {
    border-color: #10b981;
}

.sub-segment-card.dir-bi {
    border-color: #f59e0b;
}

.sub-segment-content {
    font-size: 0.85rem;
    font-weight: 500;
    text-align: left;
    line-height: 1.4;
}

.sub-segment-content .sub-dir-icon {
    font-weight: 700;
    margin-right: 2px;
}

.sub-segment-content strong {
    font-weight: 700;
}

.sub-segment-card.dir-to .sub-segment-content {
    color: #3b82f6;
}

.sub-segment-card.dir-from .sub-segment-content {
    color: #10b981;
}

.sub-segment-card.dir-bi .sub-segment-content {
    color: #f59e0b;
}

/* Sous-segments de type unlock (à déverrouiller) */
.sub-segment-card.link-unlock {
    border-color: #a855f7;
    background: rgba(168, 85, 247, 0.1);
}

.sub-segment-card.link-unlock:hover {
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.3);
}

.sub-segment-card.link-unlock .sub-segment-content {
    color: #a855f7;
}

/* Status indicator on card */
.location-card .status-indicator {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.location-card .status-indicator.both {
    background: var(--color-both);
}

.location-card .status-indicator.narrative {
    background: var(--color-narrative);
}

.location-card .status-indicator.location {
    background: var(--color-location);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    width: 400px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.modal-small {
    width: 350px;
}

.field-row {
    display: flex;
    gap: 1rem;
}

.field-row .field {
    flex: 1;
}

#link-destination {
    width: 100%;
    height: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

/* Create pending banner */
.create-pending-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    z-index: 100;
}

.create-pending-banner button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.create-pending-banner button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Zoom info */
.zoom-info {
    font-size: 0.85rem;
    min-width: 50px;
    text-align: center;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-darker);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Connection arrows - more visible */
.connection-arrow {
    fill: var(--accent);
}

/* Direction select in link item */
.link-item select {
    padding: 0.2rem;
    font-size: 0.75rem;
    width: auto;
}

/* Filter Panel */
.filter-panel {
    flex-shrink: 0;
}

/* Filter Lists */
.filter-list-container {
    max-height: 150px;
    overflow-y: auto;
    background: var(--bg-darker);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.filter-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.filter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 1px solid var(--border);
}

.filter-item:last-child {
    border-bottom: none;
}

.filter-item:hover {
    background: var(--bg-input);
}

.filter-item.active {
    background: var(--accent);
    color: white;
}

.filter-item.active .filter-count {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.filter-count {
    font-size: 0.75rem;
    background: var(--bg-input);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    color: var(--text-muted);
}

/* Indicateur de l'environnement/niveau actuel du canvas */
.filter-item.canvas-current {
    border-left: 3px solid var(--success);
}

/* Nom de l'environnement dans la liste */
.filter-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Bouton renommer environnement */
.filter-rename-btn {
    background: none;
    border: none;
    padding: 0 0.25rem;
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.filter-item:hover .filter-rename-btn {
    opacity: 0.6;
}

.filter-rename-btn:hover {
    opacity: 1 !important;
}

/* Input de renommage */
.filter-rename-input {
    width: 100%;
    padding: 0.1rem 0.3rem;
    font-size: 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: 3px;
    color: var(--text-primary);
    outline: none;
}

/* Boutons Tous/Aucun pour les filtres */
.filter-toggle-buttons {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.filter-toggle-btn {
    flex: 1;
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-toggle-btn:hover {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--text-primary);
}

/* Boutons filtre liens à déverrouiller */
.unlock-filter-buttons {
    display: flex;
    gap: 0.25rem;
}

.unlock-filter-btn {
    flex: 1;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.unlock-filter-btn:hover {
    background: var(--bg-card);
    border-color: var(--accent);
}

.unlock-filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Style pour les liens dans le panel - affichage 2 lignes */
.link-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem;
    background: var(--bg-darker);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    border-left: 3px solid var(--accent);
}

.link-item.link-unlock {
    border-left-color: #a855f7;
    background: rgba(168, 85, 247, 0.1);
}

.link-line1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.link-line1 .link-name {
    font-weight: 600;
    font-size: 0.95rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.link-line2 {
    display: flex;
    gap: 0.5rem;
}

.link-type-select,
.link-direction-select {
    flex: 1;
    padding: 0.3rem 0.4rem;
    font-size: 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
}

.btn-remove-link {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.3rem;
    line-height: 1;
}

.btn-remove-link:hover {
    color: #ff6b6b;
}

/* Rectangle de sélection */
.selection-rect {
    position: absolute;
    border: 2px dashed var(--accent);
    background: rgba(59, 130, 246, 0.1);
    pointer-events: none;
    z-index: 1000;
}

/* Sélection multiple */
.location-card.multi-selected {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.location-card.multi-selected::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}
