:root {
    --bg: #121212; --panel: #1e1e24; --border: #333; --text: #ecf0f1;
    --event: #e67e22; --mail: #3498db; --work: #9b59b6; --valid: #2ecc71;
    --danger: #e74c3c; --orange: #f39c12; --disabled: #444; --team: #1abc9c;
    --staff-illu: #e056fd; --staff-graph: #686de0; --staff-rule: #f0932b;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg); color: var(--text); margin: 0; height: 100vh;
    display: flex; flex-direction: column; overflow: hidden; user-select: none;
}

/* --- HEADER --- */
header { background: #000; padding: 10px 20px; display: grid; grid-template-columns: repeat(5, 1fr); height: 50px; align-items: center; border-bottom: 2px solid var(--border); z-index: 10; }
.stat-val { font-weight: bold; font-size: 1.1rem; }
.stat-lbl { font-size: 0.7rem; color: #888; text-transform: uppercase; }

/* --- GRID LAYOUT --- */
#game-grid { flex: 1; display: grid; grid-template-columns: 280px 320px 1fr 250px; gap: 1px; background: #444; }
.col { background: var(--panel); padding: 15px; display: flex; flex-direction: column; gap: 10px; overflow-y: hidden; border-right: 1px solid #222; position: relative; }
h2 { margin: 0; font-size: 0.9rem; color: #aaa; text-transform: uppercase; border-bottom: 1px solid #444; padding-bottom: 5px; }

/* --- BUTTONS --- */
button { width: 100%; padding: 8px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 0.75rem; transition: all 0.1s; }
button:hover:not(:disabled) { filter: brightness(1.2); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled, .btn-disabled { background: var(--disabled) !important; color: #777 !important; opacity: 0.6; cursor: not-allowed; transform: none !important; filter: grayscale(100%); }

.btn-clean { background: var(--mail); color: #fff; font-size: 0.7rem; padding: 5px;}
.btn-purge { background: var(--danger); color: #fff; font-size: 0.7rem; padding: 5px;}
.btn-trash { background: var(--danger); color: #fff; }
.btn-event { background: var(--event); color: #000; height: 40px; }
.btn-skip { background: transparent; border: 1px solid #555; color: #777; height: 30px; }
.btn-skip:hover { background: #333; color: #fff; }

.btn-act { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 45px; font-size: 0.7rem; }
.btn-sub { font-size: 0.6rem; opacity: 0.8; font-weight: normal; }
.btn-solo { background: var(--work); color: #fff; position: relative; overflow: hidden; }
.btn-author { background: var(--event); color: #000; }
.btn-team { background: var(--team); color: #fff; }
.btn-valid { background: var(--valid); color: #000; }
.btn-pivot { background: var(--orange); color: #000; }
.btn-send { background: var(--event); color: #000; margin-top:5px; }
.btn-final { background: var(--valid); color: #000; margin-top:5px; height: 40px; font-size: 0.9rem;}
.btn-job-self { background: #333; color: #fff; border: 1px solid #555; font-size: 0.65rem; padding: 4px; height: 100%; position: relative; overflow: hidden;}
.btn-job-hire { background: var(--team); color: #fff; font-size: 0.65rem; padding: 4px; height: 100%;}

/* --- EMAILS --- */
#email-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding-right: 5px; }
.email-item { 
    padding: 10px; border-radius: 3px; cursor: pointer; font-size: 0.8rem; 
    border-left: 4px solid #555; background: #252525; margin-bottom: 2px; 
    display: flex; justify-content: space-between; align-items: center;
}
.email-content { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.email-attachment { font-size: 1.2rem; margin-left: 10px; opacity: 0.7; }
.email-sender { font-weight: bold; font-size: 0.75rem; }

.email-concept { border-color: var(--mail); background: #2c3e50; }
.email-mom { border-color: #e84393; background: rgba(232, 67, 147, 0.1); }
.email-staff { border-color: #f1c40f; background: rgba(241, 196, 15, 0.1); color:#fff; }
.email-reply { border-color: var(--valid); background: rgba(46, 204, 113, 0.1); color: #fff; }
.email-spam { border-color: #7f8c8d; color: #aaa; }

/* --- STUDIO & PROJECTS --- */
#studio-list { overflow-y: auto; flex: 1; }
.project-card { background: #222; border: 1px solid #444; border-radius: 6px; padding: 10px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; transition: border-color 0.3s; position: relative; }

.card-refine { border-left: 3px solid #7f8c8d; }
.card-negotiation { border-left: 3px solid var(--event); }
.card-realization { border-left: 3px solid var(--team); }
.btn-label { font-size: 0.65rem; color: #888; text-transform: uppercase; letter-spacing: 1px; margin-top: 5px; margin-bottom: 2px; border-bottom: 1px solid #333; }

/* New Project Header & Tooltips */
.project-header-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; border-bottom: 1px solid #333; padding-bottom: 5px; }
.author-info { font-size: 0.7rem; color: #aaa; display: flex; flex-direction: column; gap: 2px; }
.author-stats { font-size: 0.65rem; color: #666; }
.mini-patience { width: 60px; height: 6px; background: #222; border: 1px solid #444; border-radius: 3px; display: inline-block; margin-left: 5px; }
.mini-patience-bar { height: 100%; transition: width 0.3s; }

.info-icon {
    display: inline-block; width: 14px; height: 14px; background: #555; color: #fff;
    border-radius: 50%; text-align: center; line-height: 14px; font-size: 0.65rem; cursor: help;
    margin-left: 5px; position: relative;
}
.info-icon:hover::after {
    content: attr(data-tooltip); position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: #000; color: #fff; padding: 5px 10px; border-radius: 4px; font-size: 0.7rem; white-space: nowrap;
    z-index: 100; border: 1px solid #444; pointer-events: none;
}

/* Grille Refine 2x2 */
.refine-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 5px; }
.btn-refine {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 50px; font-size: 0.7rem; background: #2c3e50; color: #ecf0f1;
    border: 1px solid #34495e; position: relative; overflow: hidden;
}
.btn-refine:hover:not(:disabled) { background: #34495e; }
.cost-tag { font-size: 0.6rem; color: #f1c40f; margin-top: 2px; }
.gain-tag { font-size: 0.6rem; color: #2ecc71; font-weight: bold; }

/* Metrics & Bars */
.game-meta { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; font-size: 0.7rem; color: #bbb; background: rgba(0,0,0,0.2); padding: 5px; border-radius: 4px; text-align: center; }
.meta-val { color: #fff; font-weight: bold; }
.range-container { height: 12px; background: #000; border-radius: 6px; position: relative; border:1px solid #333; overflow: hidden; margin: 5px 0; }
.range-bar { position: absolute; height: 100%; opacity: 0.8; border-radius: 6px; transition: all 0.5s; }
.bar-red { background: var(--danger); } .bar-orange { background: var(--orange); } .bar-green { background: var(--valid); }
.range-text { position: absolute; width: 100%; text-align: center; font-size: 0.65rem; line-height: 12px; color: #fff; text-shadow: 0 0 2px #000; z-index: 2; }

.patience-container { height: 4px; background: #333; margin-top: 2px; border-radius: 2px; }
.patience-bar { height: 100%; background: #e74c3c; width: 100%; transition: width 0.2s; }

.job-container { display: grid; grid-template-columns: 60px 1fr 100px; gap: 5px; align-items: center; margin-bottom: 3px; }
.job-label { font-size: 0.65rem; color: #aaa; }
.job-track { height: 10px; background: #000; border: 1px solid #444; position: relative; }
.job-fill { height: 100%; background: var(--team); width: 0%; transition: width 0.2s; }
.job-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; height: 25px; }

/* --- STAFF & OVERLAYS --- */
.employee-card {
    background: #2c3e50; border: 1px solid #34495e; border-radius: 4px; padding: 8px; margin-bottom: 8px;
    display: flex; flex-direction: column; gap: 5px; position: relative; overflow: hidden; transition: all 0.3s;
}
.employee-header { display: flex; justify-content: space-between; align-items: center; }
.employee-name { font-weight: bold; font-size: 0.8rem; color: #fff; }
.employee-job { font-size: 0.65rem; color: #bdc3c7; font-style: italic; }
.employee-lvl { font-size: 0.7rem; background: #333; padding: 1px 4px; border-radius: 3px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #2ecc71; box-shadow: 0 0 5px #2ecc71; }
.status-busy { background: #e74c3c; box-shadow: 0 0 5px #e74c3c; }

.skill-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: rgba(0,0,0,0.2); padding: 4px; border-radius: 3px; }
.skill-slot { height: 6px; background: #111; border: 1px solid #444; border-radius: 2px; }
.skill-active { background: #f1c40f; border-color: #f39c12; box-shadow: 0 0 2px #f1c40f; }

.employee-busy-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); display: flex; justify-content: center; align-items: center; z-index: 10; backdrop-filter: blur(2px);
}
.busy-text { color: #fff; font-weight: bold; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 2px; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }

#contact-list { display: flex; flex-direction: column; gap: 2px; padding: 5px; background: #1a1a1a; margin-top: auto; max-height: 200px; overflow-y: auto; border-top: 1px solid #333; }
.contact-item { font-size: 0.7rem; padding: 5px; background: #333; color: #ccc; border-left: 2px solid #555; display:flex; justify-content:space-between;}

/* --- EVENTS --- */
.event-card { 
    background: rgba(230, 126, 34, 0.05); border: 1px solid var(--event); padding: 10px; border-radius: 6px; text-align: center;
    display: flex; flex-direction: column; justify-content: space-between; height: 160px; box-sizing: border-box;
}
.event-title { font-weight: bold; font-size: 0.9rem; margin-bottom: 5px; height: 40px; display: flex; align-items: center; justify-content: center; overflow: hidden; line-height: 1.1; }
.event-actions { display:grid; grid-template-columns: 1fr 1fr; gap:5px;}

/* --- COMPTEURS (BADGES) --- */
.badge {
    background: #333;
    color: #fff;
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 10px;
    vertical-align: middle;
    margin-left: 8px;
    border: 1px solid #555;
}

/* --- HISTORIQUE (Positionnement fixe en bas de colonne) --- */
.history-container {
    height: 150px; /* Hauteur fixe pour éviter les sauts */
    border-top: 1px solid #444;
    padding-top: 5px;
    display: flex;
    flex-direction: column;
    margin-top: 10px;
}

.history-title {
    font-size: 0.6rem; 
    color: #666; 
    margin-bottom: 3px; 
    text-transform: uppercase; 
    letter-spacing: 1px;
}

#history-log {
    flex: 1;
    background: #111;
    overflow-y: auto;
    padding: 5px;
    font-family: 'Consolas', monospace;
    font-size: 0.65rem;
    color: #aaa;
    border-radius: 4px;
    border: 1px solid #222;
}

/* --- STABILISATION DES LISTES --- */
/* Cela force les listes à prendre tout l'espace restant sans pousser les bords */
#studio-list, #email-list, #employee-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Important pour le Flexbox scrolling */
}

/* Ajustement de la colonne pour le Flexbox vertical */
.col {
    display: flex;
    flex-direction: column;
    height: 100%; /* Force la colonne à faire toute la hauteur */
    box-sizing: border-box;
    overflow: hidden; /* Empêche le débordement global */
}

/* --- MISC --- */
.floater { position: absolute; pointer-events: none; animation: floatUp 0.8s forwards; font-weight: bold; z-index: 999; text-shadow: 1px 1px 0 #000; }
.cooldown-overlay { position: absolute; bottom: 0; left: 0; height: 4px; background: rgba(255,255,255,0.8); width: 0%; }
.action-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.action-footer { display: grid; grid-template-columns: 2fr 1fr; gap: 5px; margin-top: 5px; }