/* MODERN UI OVERRIDES - Extracted from index.html */

* {
    box-sizing: border-box;
    /* Accessibilité: outline: none supprimé pour le focus */
}

body {
    background-color: var(--bg-body);
    background-image: radial-gradient(circle at 15% 50%, rgba(251, 191, 36, 0.03), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(59, 130, 246, 0.03), transparent 25%);
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: 14px;
    margin: 0;
    overflow: hidden;
    height: 100vh;
}

/* --- Focus Styles (Accessibilité) --- */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* --- Scrollbars Modernes --- */
::-webkit-scrollbar {
    width: var(--scrollbar-width, 8px);
    height: var(--scrollbar-width, 8px);
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* --- Header Premium --- */
header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 50;
}

.tools-label {
    margin-left: 5px;
    display: none;
}

@media(min-width: 700px) {
    .tools-label {
        display: inline;
    }
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-container img {
    height: 32px;
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.2));
}

/* --- Sidebar & Layout --- */
#main {
    height: calc(100vh - 64px);
    display: flex !important;
    padding: 0;
    max-width: 100%;
    margin: 0;
}

.sidebar-panel {
    flex: 0 0 320px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    overflow-y: auto;
}

.content-panel {
    flex: 1;
    padding: 24px 32px;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(255, 255, 255, 0.02), transparent 40%);
}

/* --- Buttons & Inputs --- */
button {
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-family: var(--font-main);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
}

button:not(.secondary):not(.danger) {
    background: linear-gradient(135deg, var(--score-gold), #d97706);
    color: var(--text-inverse);
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.25);
}

button:not(.secondary):not(.danger):hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(251, 191, 36, 0.4);
    filter: brightness(1.1);
}

button.secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
}

button.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-add {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    font-weight: 600;
}

input,
select,
textarea {
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    width: 100%;
    font-family: var(--font-main);
    font-size: 14px;
    transition: all 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--score-gold);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.2);
    outline: none;
}

/* --- Cards (Projects & Parts) --- */
.project-card,
.part-row {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

/* Simulated Project Item Class */
.project-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid transparent;
    padding: 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.project-item:hover {
    border-color: rgba(251, 191, 36, 0.4);
    transform: translateX(4px);
    background: var(--bg-surface-hover);
    border-left-color: var(--score-gold);
}

.project-item.active {
    border-color: var(--score-gold);
    background: rgba(251, 191, 36, 0.05);
    border-left-color: var(--score-gold);
}

.project-item.archived {
    opacity: 0.6;
    filter: grayscale(0.5);
    border-left-style: dashed;
}

#toggleArchivedBtn.active {
    background: rgba(251, 191, 36, 0.15);
    color: var(--score-gold);
    border-color: var(--score-gold);
}

.reference-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--score-gold);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reference-item:hover {
    background: var(--bg-surface-hover);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* --- Nested References Tree --- */
.ref-node {
    margin-bottom: 8px;
}

.ref-node>.reference-item {
    margin-bottom: 0;
    display: flex;
    align-items: center;
}

.ref-children {
    padding-left: 12px;
    margin-left: 12px;
    border-left: 1px dashed rgba(251, 191, 36, 0.3);
    overflow: hidden;
    transition: all 0.3s ease;
    max-height: 5000px;
    opacity: 1;
    margin-top: 4px;
}

.ref-children.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding: 0;
}

.ref-chevron {
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    margin-right: 8px;
    color: var(--text-muted);
    border-radius: 4px;
    z-index: 2;
}

.ref-chevron:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--score-gold);
}

.ref-chevron.collapsed {
    transform: rotate(-90deg);
}

/* --- Modals (The "Critical Fix" made Beautiful) --- */
.modal-overlay {
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: rgba(16, 18, 22, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    overflow-y: auto;
    pointer-events: auto;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

/* Detail Modal Specifics */
#detailModal .modal-content {
    width: 98vw !important;
    height: 96vh !important;
    max-width: none !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 150px 100px -20px rgba(0, 0, 0, 0.9);
}

.detail-grid {
    display: grid !important;
    grid-template-columns: 420px 1fr !important;
    height: 100%;
    width: 100% !important;
    margin: 0 !important;
    gap: 0 !important;
}

.detail-left {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    padding: 0;
}

.detail-header-group {
    padding: 16px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.detail-scroll-area,
.viewer-content {
    flex: 1;
    overflow-y: scroll !important;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
}

/* Explicit Scrollbar for Detail Area & Viewer Content */
.detail-scroll-area,
.viewer-content {
    scrollbar-width: auto;
    scrollbar-color: #fbbf24 rgba(0, 0, 0, 0.4);
}

.detail-scroll-area::-webkit-scrollbar,
.viewer-content::-webkit-scrollbar {
    width: 16px;
    height: 16px;
}

.detail-scroll-area::-webkit-scrollbar-track,
.viewer-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.4);
    border-left: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-scroll-area::-webkit-scrollbar-thumb,
.viewer-content::-webkit-scrollbar-thumb {
    background-color: #fbbf24;
    border-radius: 8px;
    border: 4px solid #1a1d21;
    background-clip: padding-box;
}

.detail-scroll-area::-webkit-scrollbar-thumb:hover,
.viewer-content::-webkit-scrollbar-thumb:hover {
    background-color: #f59e0b;
}

.detail-footer {
    padding: 15px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
}

.detail-right {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-body);
    padding: 0;
    position: relative;
}

.detail-right::before {
    display: none;
}

.viewer-tabs {
    display: flex;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    gap: 12px;
    padding: 10px 16px 0 16px;
    /* Added padding, 0 bottom to align with border */
}

.viewer-tab {
    flex: 1;
    padding: 12px;
    text-align: center;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-bottom: 3px solid transparent;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    border-radius: 8px 8px 0 0;
    /* Rounded top corners */
}

.viewer-tab:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.02);
}

.viewer-tab.active {
    color: var(--score-gold);
    border-bottom-color: var(--score-gold);
    background: rgba(251, 191, 36, 0.05);
}

.viewer-content {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    position: relative;
}

.viewer-content.active {
    display: flex;
}

.viewer-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
}

.viewer-canvas-area {
    flex: 1;
    background: #08090b;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    overflow: hidden;
}

@media (max-width: 768px) {
    .detail-grid {
        grid-template-columns: 1fr !important;
    }

    .detail-right {
        height: 50vh;
        border-top: 1px solid var(--border-subtle);
    }
}

.modal-header h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
    line-height: 1.2;
    background: linear-gradient(180deg, #fff 0%, #ccc 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.meta-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    padding: 10px 12px;
    border-radius: 12px;
    transition: all 0.2s;
}

.meta-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.meta-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.meta-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
    color: var(--score-gold);
    display: flex;
    align-items: center;
    gap: 8px;
}

.viewer-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.viewer-header {
    padding: 16px 20px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.03), transparent);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.viewer-canvas-area {
    background: #08090b;
    min-height: 400px;
    position: relative;
}

.actions-bar {
    display: flex;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
    margin-top: auto;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 200px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 6px;
    z-index: 100;
    margin-top: 8px;
    animation: slideDown 0.2s ease-out;
}

.dropdown-content a {
    border-radius: 4px;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.15s;
}

.dropdown-content a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    transform: translateX(2px);
}

.score-box {
    background: rgba(251, 191, 36, 0.1);
    color: var(--score-gold);
    border: 1px solid rgba(251, 191, 36, 0.2);
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 15px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    #main {
        flex-direction: column;
    }

    .sidebar-panel {
        flex: none;
        height: 30vh;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }
}