:root {
    /* DARK THEME (Default) */
    --bg-main: #111111;
    --bg-secondary: #1a1a1a;
    --bg-input: #111111;
    --text-main: #f0f0f0;
    --text-muted: #888888;
    --accent: #ffb703; /* Golden/orange yellow */
    --accent-hover: #fb8500;
    --border-color: #333333;
    --border-dashed: #444444;
    --danger: #ef233c;
    --shadow: rgba(0, 0, 0, 0.5);
}

:root[data-theme="light"] {
    /* LIGHT THEME */
    --bg-main: #f9f9f9;
    --bg-secondary: #ffffff;
    --bg-input: #ffffff;
    --text-main: #222222;
    --text-muted: #666666;
    --accent: #d48b00; /* Darker golden for contrast */
    --accent-hover: #b37300;
    --border-color: #dddddd;
    --border-dashed: #bbbbbb;
    --danger: #d90429;
    --shadow: rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px;
}

/* Library Grid */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
}

.fiche-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.fiche-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-delete-fiche {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s;
    z-index: 10;
}
.btn-delete-fiche:hover {
    opacity: 1;
    transform: scale(1.1);
}

.fiche-card-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 10px;
}

.fiche-card-meta {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Controls */
.top-controls {
    /* Styles are inline or handled generically */
}

.btn-icon, .btn-primary, .btn-danger {
    font-family: 'Inter', sans-serif;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    color: var(--accent);
    border: 1px solid var(--border-color);
}

.btn-icon:hover {
    background: var(--border-color);
}

.btn-primary {
    padding: 0 16px;
    height: 40px;
    background: var(--accent);
    color: #000;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    padding: 0 16px;
    height: 40px;
    background: var(--bg-secondary);
    color: var(--danger);
    border: 1px solid var(--border-color);
}

.btn-danger:hover {
    background: var(--border-color);
}

/* Inputs & Form Base */
input, textarea {
    font-family: 'Inter', sans-serif;
    background: transparent;
    border: none;
    color: var(--text-main);
    outline: none;
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

.input-base {
    width: 100%;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px solid transparent;
    transition: border-bottom-color 0.2s;
}

.input-base:focus {
    border-bottom-color: var(--accent);
}

.textarea-resize {
    resize: vertical;
    min-height: 40px;
}

.textarea-large {
    resize: vertical;
    min-height: 120px;
    background: var(--bg-secondary);
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.textarea-large:focus {
    border-color: var(--accent);
}

/* Header */
.sheet-header {
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
}

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

.input-title {
    font-size: 40px;
    font-weight: 300;
    letter-spacing: -1px;
    flex: 1;
    border-bottom: 1px solid transparent;
}
.input-title:focus {
    border-bottom-color: var(--accent);
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-date {
    background: transparent;
    color: var(--text-main);
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 4px;
    font-family: inherit;
    font-size: 14px;
}

.header-sub {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-director {
    font-size: 14px;
    text-transform: none;
    letter-spacing: 0;
    width: 300px;
    border-bottom: 1px solid transparent;
}
.input-director:focus {
    border-bottom-color: var(--accent);
}

/* Sections */
#sortable-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 40px;
    margin-bottom: 50px;
    align-items: start;
}

@media (min-width: 768px) {
    #sortable-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

.section {
    /* removed margin-bottom to rely on gap */
    width: 100%;
    transition: grid-column 0.3s;
}

.section.section-full-width {
    grid-column: 1 / -1;
}

.section-title {
    font-size: 12px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.drag-handle {
    cursor: grab;
    font-size: 16px;
    user-select: none;
    opacity: 0.5;
}
.drag-handle:hover {
    opacity: 1;
}
.drag-handle:active {
    cursor: grabbing;
}

.editable-title {
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: all 0.2s;
    min-width: 50px;
}
.editable-title:hover {
    border-bottom-color: var(--accent);
}
.editable-title:focus {
    border-bottom-color: var(--accent);
    color: var(--text-main);
}

.sort-controls {
    display: flex;
    gap: 5px;
    margin-left: auto; /* Push to the right */
}

.btn-sort {
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-sort:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
}

.btn-full-width {
    font-size: 14px;
    transform: rotate(45deg); /* To make an arrow icon look like expanding if we use a normal character */
}

/* SortableJS Ghost */
.sortable-ghost {
    opacity: 0.8;
    background-color: var(--bg-main) !important;
    border: 2px dashed var(--accent) !important;
    border-radius: 8px;
}

/* Gear */
.gear-inputs {
    display: flex;
    gap: 20px;
}

.gear-inputs input {
    background: var(--bg-secondary);
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Tips List */
.tips-list-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 15px 0;
}

.tip-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    gap: 20px;
}
.tip-item:last-child {
    border-bottom: none;
}

.tip-number {
    color: var(--accent);
    font-family: monospace;
    font-size: 12px;
    width: 20px;
    flex-shrink: 0;
}

.tip-input {
    flex: 1;
    font-size: 14px;
}

/* Ratio */
.ratio-container {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.ratio-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.ratio-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

.ratio-btn:hover {
    border-color: var(--text-muted);
}

.ratio-btn.active {
    border-color: var(--accent);
    color: var(--accent);
}

.custom-ratio-wrapper {
    position: relative;
    display: flex;
}
.custom-ratio-wrapper input {
    width: 100%;
    text-align: center;
}
.custom-ratio-wrapper input:focus {
    border-bottom-color: transparent !important; /* fix outline on active/clear */
    outline: none;
}
#clear-custom-ratio {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
}
#clear-custom-ratio:hover {
    color: var(--danger);
}

.ratio-preview-box {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 120px;
    margin-bottom: 20px;
    position: relative;
}

.ratio-shape {
    border: 1px solid var(--accent);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    transition: all 0.3s ease;
    position: absolute;
    background-color: rgba(255, 183, 3, 0.1); /* light tint */
    color: var(--accent);
}
.ratio-shape:nth-child(2) { border-style: dashed; background-color: rgba(255, 183, 3, 0.05); }
.ratio-shape:nth-child(3) { border-style: dotted; background-color: transparent; }
.ratio-shape.no-text { color: transparent; } /* Hides text when overlapping */

/* Team Table */
.team-table-container {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.team-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
}

.team-table th {
    text-align: left;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
}

.team-table td {
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
}

.team-table tr:last-child td {
    border-bottom: none;
}

.role-input, .person-input {
    width: 100%;
    font-size: 14px;
}

.person-input {
    color: var(--text-muted);
}

.btn-remove-row {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
}

.btn-remove-row:hover {
    color: var(--danger);
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.btn-text:hover {
    color: var(--text-main);
}

/* Refs Grid */
.refs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.ref-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    position: relative;
    display: flex;
    flex-direction: column;
}

.btn-delete-ref {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    z-index: 10;
}

.btn-delete-ref:hover {
    background: var(--danger);
}

.ref-image-area {
    height: 180px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.ref-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.ref-upload-label:hover {
    color: var(--text-main);
}

.file-input {
    display: none;
}

.ref-image-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ref-content {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ref-label-input {
    font-weight: 500;
}

.ref-note-input {
    font-size: 12px;
    color: var(--text-muted);
}

.ref-add-card {
    border: 1px dashed var(--border-dashed);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 180px; /* Match image area approx */
}

.btn-add-ref {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-family: inherit;
}

.btn-add-ref span:first-child {
    font-size: 24px;
    font-weight: 300;
}

    .btn-add-ref:hover {
        color: var(--text-main);
    }

    /* Modal */
    .modal-overlay {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.8);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1000;
    }
    .modal-content {
        background: var(--bg-main);
        padding: 30px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        width: 100%;
        max-width: 400px;
    }
    
    .add-section-wrapper {
        margin: 60px 0;
        text-align: center;
    }

/* --- PDF EXPORT TEMPLATE --- */
#pdf-export-template {
    width: 1122px; /* A4 Landscape at 96dpi approx */
    background: #ffffff;
    color: #111111;
    font-family: 'Inter', sans-serif;
    position: absolute;
    left: -9999px;
    top: 0;
}

.pdf-gallery-item {
    text-align: center;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
}
.pdf-cover-page {
    text-align: center;
    height: 600px; /* Safe height for A4 landscape with 15mm margins */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.pdf-project-title {
    font-size: 60px;
    font-weight: 300;
    margin-bottom: 20px;
    letter-spacing: -2px;
}

.pdf-project-meta {
    display: flex;
    justify-content: center;
    gap: 40px;
    font-size: 18px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.pdf-project-meta span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pdf-content-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 40px;
    align-items: flex-start;
}

.pdf-section {
    width: calc(50% - 20px);
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 20px;
}

.pdf-full-width {
    width: 100%;
}

.pdf-section-title {
    font-size: 16px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.pdf-section-content {
    font-size: 14px;
    line-height: 1.6;
}

.pdf-ratios {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.pdf-ratio-badge {
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: 600;
}
.pdf-note {
    font-size: 13px;
    color: #666;
    font-style: italic;
}
.pdf-table {
    width: 100%;
    border-collapse: collapse;
}
.pdf-table td {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}
.pdf-table td:first-child {
    font-weight: 600;
    color: #444;
    width: 40%;
}
.pdf-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}
.pdf-gallery-item img {
    width: 100%;
    height: 250px;
    object-fit: contain;
    border-radius: 4px;
    margin-bottom: 5px;
    border: 1px solid #eee;
    background: #f9f9f9;
}
.pdf-list {
    padding-left: 20px;
}
.pdf-list li {
    margin-bottom: 5px;
}

/* Print Styles */
@media print {
    /* Force light mode variables for print to save ink */
    :root {
        --bg-main: #ffffff !important;
        --bg-secondary: #ffffff !important;
        --text-main: #000000 !important;
        --text-muted: #333333 !important;
        --border-color: #cccccc !important;
        --border-dashed: #aaaaaa !important;
    }

    body {
        background-color: #ffffff;
        color: #000000;
        padding: 0;
    }

    .app-container {
        padding: 20px;
        max-width: 100%;
    }

    .no-print {
        display: none !important;
    }

    /* Adjust inputs to look like plain text */
    input, textarea {
        border: none !important;
        color: #000000 !important;
        resize: none !important;
        background: transparent !important;
    }

    input::placeholder, textarea::placeholder {
        color: transparent !important;
    }

    .gear-inputs input, .textarea-large {
        border: 1px solid #ccc !important;
    }

    .ratio-container, .team-table-container, .ref-card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        break-inside: avoid;
    }
    
    .section {
        margin-bottom: 30px;
        break-inside: avoid;
    }

    /* Show only active ratio in grid, or hide the grid entirely if preview is enough */
    .ratio-btn:not(.active) {
        display: none !important;
    }
    .ratio-btn.active {
        border: none !important;
        font-weight: bold;
        color: #000 !important;
    }
    .ratio-grid {
        display: flex;
        margin-bottom: 0;
    }
}
