:root {
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --red-hp: #e74c3c;
    --blue-def: #e1e8fa;
    --blue-def-text: #2980b9;
    --purple-san: #9b59b6;
    --border-color: #ecf0f1;
    --border-radius: 12px;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 15px;
    box-sizing: border-box;
}

.sheet-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

h3 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--text-main);
    margin-bottom: 15px;
}

/* Header */
.profile-header { display: flex; align-items: center; gap: 15px; padding: 15px 20px; }
.avatar-placeholder { width: 50px; height: 50px; background: #e9ecef; border-radius: 8px; display: flex; justify-content: center; align-items: center; font-size: 24px; }
.profile-info h1 { margin: 0; font-size: 1.2rem; }
.profile-info p { margin: 2px 0 0 0; color: var(--text-muted); font-size: 0.85rem; }

/* Vitais */
.vitals-top-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 15px; }
.vital-card { background: var(--card-bg); border-radius: var(--border-radius); padding: 15px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); text-align: center; }

/* BARRA DE PV CORRIGIDA */
.pv-card .progress-bar-container { 
    background: #fdf0f0; 
    border-radius: 6px; 
    height: 28px; 
    position: relative; 
    margin: 10px 0; 
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; 
    border: 1px solid #f5dada; 
}
.progress-bar.red-bar { 
    background: var(--red-hp); 
    height: 100%; 
    position: absolute; 
    left: 0;
    top: 0;
    z-index: 1;
    transition: width 0.3s ease; 
}
.progress-text { 
    position: relative; 
    z-index: 2;
    color: #ffffff; 
    font-weight: bold; 
    font-size: 0.95rem;
    text-shadow: 0px 1px 3px rgba(0,0,0,0.8);
    pointer-events: none;
}

.defense-blue-card { background: var(--blue-def); color: var(--blue-def-text); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.defense-blue-card strong { font-size: 2rem; }

.vitals-sub-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
.border-card { border: 1px solid var(--border-color); }
.sanity-card { border-color: #ebdcf2; }
.vital-values { margin: 5px 0; }
.vital-values strong { font-size: 1.2rem; }

.mini-card { display: flex; flex-direction: column; border: 1px solid var(--border-color); justify-content: center; align-items: center;}
.mini-card span { font-size: 0.75rem; color: var(--text-muted); }
.mini-card strong { font-size: 1.2rem; margin-top: 5px; }

/* Controles Duplos */
.dual-controls { display: flex; gap: 15px; justify-content: center; width: 100%; }
.control-group { display: flex; align-items: center; gap: 8px; background: #f8f9fa; padding: 4px 8px; border-radius: 8px; }
.small-controls .control-group { padding: 2px 5px; gap: 5px; }
.control-group button { background: #e9ecef; border: none; width: 24px; height: 24px; border-radius: 4px; cursor: pointer; font-weight: bold; color: var(--text-main); }
.control-group button:active { background: #ced4da; }
.control-group span { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; font-weight: bold;}

/* Grid Principal */
.main-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; align-items: start; }
.grid-column { display: flex; flex-direction: column; gap: 15px; }

/* Atributos */
.attributes-cross { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: center; }
.attr-box { border: 1px solid var(--border-color); padding: 10px; border-radius: 8px; }
.attr-box span { display: block; font-size: 0.75rem; color: var(--text-muted); }
.attr-box strong { display: block; font-size: 1.5rem; margin: 5px 0; }
.attr-box small { color: var(--text-muted); font-size: 0.8rem; }

/* Perícias */
.skill-status { width: 18px; height: 18px; border-radius: 50%; display: inline-block; margin-right: 12px; flex-shrink: 0; cursor: pointer; transition: transform 0.1s; }
.skill-status:active { transform: scale(0.9); }
.skill-status.untrained { border: 2px solid #bdc3c7; background: transparent; }
.skill-status.trained { background: #2ecc71; border: 2px solid #2ecc71; position: relative; }
.skill-status.trained::after { content: "✓"; color: white; font-size: 12px; font-weight: bold; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -45%); }

/* Listas Limpas (Inventário e Perícias) */
.clean-list { list-style: none; padding: 0; margin: 0; }
.clean-list li { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; position: relative;}
.clean-list li:last-child { border-bottom: none; }
.item-icon { color: #e67e22; margin-right: 10px; flex-shrink: 0;}
.list-value { margin-left: auto; font-weight: bold; }

/* Cards Internos (Ataques, Habilidades, Rituais) */
.inner-card { border: 1px solid var(--border-color); border-radius: 8px; padding: 12px; margin-bottom: 10px; position: relative; }
.inner-card p { margin: 0; font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.stat-row { display: flex; justify-content: space-between; margin-top: 8px; font-size: 0.8rem; }
.stat-row strong { color: var(--red-hp); }
.tag { background: #f1f3f5; padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; color: var(--purple-san); }

/* --- BOTÕES DE ADICIONAR E REMOVER CORRIGIDOS --- */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.section-header h3 { margin: 0; }
.add-icon { background: var(--blue-def); color: var(--blue-def-text); width: 24px; height: 24px; border-radius: 50%; display: inline-flex; justify-content: center; align-items: center; font-weight: bold; cursor: pointer; transition: background 0.2s; font-size: 1.2rem; line-height: 1; }
.add-icon:hover { background: #d0dcf5; }

/* Layout da linha de título dos cards para o botão de apagar não sobrepor */
.card-header-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.card-header-row h4 { margin: 0; flex: 1; padding-right: 10px; }

/* Para inventário não quebrar linha de forma estranha */
.item-details { flex: 1; display: flex; flex-direction: column; }
.item-title { font-weight: 500; display: block; }
.item-desc { display: block; margin-top: 2px; }

.delete-btn { color: var(--red-hp); font-weight: bold; font-size: 1.2rem; cursor: pointer; opacity: 0; transition: opacity 0.2s ease; padding: 0 5px; background: transparent; border-radius: 4px; margin-left: 8px; line-height: 1; }
.inner-card:hover .delete-btn, .clean-list li:hover .delete-btn,
.inner-card:active .delete-btn, .clean-list li:active .delete-btn { opacity: 1; }

/* História */
#character-history p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 10px; }
#character-history strong { color: var(--text-main); display: block; margin-bottom: 2px; }

/* --- PAPEL DIGITAL CORRIGIDO --- */
[contenteditable="true"] {
    outline: none;
    border-bottom: 1px dashed transparent;
    transition: all 0.2s ease;
    cursor: text;
    min-width: 15px;
}
/* Importante: Apenas elementos em linha reais ganham inline-block para não quebrarem o grid/parágrafos */
span[contenteditable="true"], strong[contenteditable="true"], small[contenteditable="true"] {
    display: inline-block;
}
[contenteditable="true"]:hover, [contenteditable="true"]:focus {
    border-bottom: 1px dashed #bdc3c7;
    background: rgba(0,0,0,0.02);
    border-radius: 2px;
}

/* --- SINO DE NOTIFICAÇÃO (Estado Inativo Padrão) --- */
.floating-notif {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background-color: #bdc3c7; /* Cinza claro (igual ao botão de salvar) */
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 28px;
    z-index: 9999;
    transition: 0.3s;
    pointer-events: none; /* Impede o clique se não houver notificação */
    opacity: 0.7; /* Visual apagado */
}

/* --- SINO DE NOTIFICAÇÃO (Estado Ativo/Vermelho) --- */
.floating-notif.active {
    background-color: #ff0000; /* Vermelho sólido vibrante */
    pointer-events: auto; /* Permite o clique */
    cursor: pointer;
    opacity: 1; /* Aceso */
}

.floating-notif.active:hover {
    transform: scale(1.1);
    background-color: #cc0000;
}

.hidden {
    display: none !important;
}

/* Responsividade Mobile */
@media (max-width: 768px) {
    .vitals-top-grid { grid-template-columns: 1fr; }
    .vitals-sub-grid { grid-template-columns: 1fr 1fr; }
    .main-grid { grid-template-columns: 1fr; }
    .delete-btn { opacity: 1; /* No mobile, o X fica sempre visível para não depender de Hover */ }
}

/* Responsividade do Cabeçalho */
.char-details-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 10px;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.char-details-row strong { color: var(--text-main); }

/* Correção de Responsividade dos Vitais (Sanidade, PE, etc) */
.vitals-sub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 15px;
}

/* Novo Layout das Perícias */
.skill-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 6px 0; 
    border-bottom: 1px dashed var(--border-color); 
}
.skill-name-group { display: flex; align-items: center; gap: 8px; flex: 1; }
.skill-inputs { display: flex; align-items: center; gap: 6px; }

.skill-readonly-val { width: 20px; text-align: center; color: #7f8c8d; font-size: 0.8rem; font-weight: bold;}
.skill-bonus-input { width: 40px; padding: 4px; text-align: center; border: 1px solid var(--border-color); border-radius: 4px; font-size: 0.85rem;}
.skill-train-select { padding: 4px; border: 1px solid var(--border-color); border-radius: 4px; font-size: 0.85rem; background: #fff;}
.skill-train-select:disabled { background: #f4f6f8; color: #a0aab2; cursor: not-allowed;}

/* Correção para ecrãs de telemóvel (Mobile) */
@media (max-width: 600px) {
    /* Força os cards de Sanidade, PE e Deslocamento a ficarem 1 por linha */
    .vitals-sub-grid {
        grid-template-columns: 1fr; 
    }

    /* Garante que os botões + e - nunca quebrem o layout mesmo em telas muito finas */
    .vital-controls.dual-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    /* Transforma a área de dados numa "caixa" organizada no mobile */
    .char-details-row {
        flex-direction: column;
        align-items: stretch; /* Estica para ocupar toda a largura */
        gap: 0;
        background: #f8f9fc; /* Fundo cinza bem claro para destacar do fundo branco */
        padding: 8px 15px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        margin-top: 5px;
    }

    /* Coloca o Rótulo na esquerda e o Valor na direita */
    .detail-item {
        display: flex;
        justify-content: space-between;
        width: 100%;
        padding: 10px 0;
        border-bottom: 1px solid #e9ecef; /* Linha fina entre os itens */
        font-size: 0.95rem;
    }

    /* Remove a linha do último item (NEX) */
    .detail-item:last-child {
        border-bottom: none;
    }

    /* Deixa os rótulos com uma cor mais suave para o olhar focar nos Valores */
    .detail-item strong {
        color: var(--text-muted);
        font-weight: 600;
    }
    
    .detail-separator {
        display: none; /* Esconde as bolinhas "•" no telemóvel */
    }
}

/* Dá um respiro e uma linha abaixo do Nome do Personagem */
.profile-info h1 {
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f2f5; 
}

/* Garante que o % e o número ficam sempre colados */
.detail-item > span {
    display: inline-flex;
    align-items: center;
}

/* --- ESTILO DE ALTERAÇÕES NÃO SALVAS --- */
.unsaved-change {
    background-color: #ffeaa7 !important; /* Amarelo/Laranja bem suave */
    outline: 1px solid #fdcb6e;
    border-radius: 4px;
    transition: 0.3s;
}

/* --- BOTÃO FLUTUANTE DE SALVAR --- */
.floating-save {
    position: fixed;
    bottom: 100px; /* Fica acima do sino de notificação */
    right: 30px;
    background-color: #bdc3c7; /* Cinza claro (inativo) */
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 26px;
    z-index: 9998;
    transition: 0.3s;
    pointer-events: none; /* Impede o clique enquanto não houver edição */
    opacity: 0.7;
}

.floating-save.active {
    background-color: #e67e22; /* Laranja vibrante (ativo) */
    pointer-events: auto;
    cursor: pointer;
    opacity: 1;
}

.floating-save.active:hover {
    transform: scale(1.1);
    background-color: #d35400;
}

.save-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    padding: 2px 7px;
    border-radius: 10px;
    display: none; /* Fica escondido quando é 0 */
}

.floating-discard {
    position: fixed;
    bottom: 110px; /* Fica alinhado com o botão de salvar */
    right: 100px;  /* Fica à esquerda do botão de salvar */
    background-color: #e74c3c;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    font-size: 16px;
    z-index: 9998;
    cursor: pointer;
    transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    
    /* Escondido por padrão */
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5); 
}

/* Quando ativado, ele cresce e aparece */
.floating-discard.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.floating-discard:hover {
    background-color: #c0392b;
    transform: scale(1.1);
}

/* --- ÍCONE FLUTUANTE DO CHAT --- */
.floating-chat {
    position: fixed;
    bottom: 170px; 
    right: 30px;
    background-color: #bdc3c7;
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 26px;
    z-index: 9997;
    cursor: pointer;
    transition: 0.3s;
}
.floating-chat.active { background-color: #3498db; } /* Azul quando tem mensagem */
.floating-chat:hover { transform: scale(1.1); }

/* --- MODAL DO CHAT --- */
.chat-modal-content {
    display: flex;
    flex-direction: column;
    height: 80vh; /* Ocupa 80% da tela */
    max-width: 600px;
    padding: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #e5ddd5; /* Cor de fundo clássica de chat */
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Bolhas de Mensagem */
.msg-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.msg-bubble img {
    max-width: 100%;
    border-radius: 6px;
    margin-top: 5px;
    cursor: pointer;
}
.msg-sent {
    align-self: flex-end;
    background-color: #dcf8c6; /* Verde claro estilo Zap */
    border-top-right-radius: 0;
}
.msg-received {
    align-self: flex-start;
    background-color: #ffffff;
    border-top-left-radius: 0;
}
.msg-sender-name {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--blue-def-text);
    margin-bottom: 3px;
    display: block;
}
.msg-time {
    font-size: 0.65rem;
    color: #999;
    text-align: right;
    display: block;
    margin-top: 5px;
}

/* Área de Input */
.chat-input-area {
    padding: 10px;
    background: #f0f0f0;
    border-top: 1px solid #ddd;
}
.chat-select {
    width: 100%;
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 6px;
    border: 1px solid #ccc;
}
.chat-controls-row {
    display: flex;
    gap: 8px;
}
#chat-text-input {
    flex: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid #ccc;
    outline: none;
}
.camera-btn { font-size: 1.2rem; background: transparent; border: none; cursor: pointer; }
.send-btn { border-radius: 50%; width: 40px; height: 40px; padding: 0; display: flex; align-items: center; justify-content: center; }

/* Preview da Imagem */
.image-preview-box {
    margin-top: 10px;
    position: relative;
    display: inline-block;
}
.image-preview-box img { max-height: 100px; border-radius: 8px; }
.remove-preview {
    position: absolute; top: -10px; right: -10px;
    background: red; color: white; width: 24px; height: 24px;
    border-radius: 50%; text-align: center; line-height: 24px;
    cursor: pointer; font-weight: bold;
}

/* =========================================
   ESTILOS DO MODAL E CAIXA DE CORREIO
========================================= */

/* Fundo escuro em ecrã inteiro para o Modal */
.modal-full { 
    position: fixed !important; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.7) !important; 
    z-index: 10000; 
    display: flex; 
    flex-direction: column; 
}

/* Estilo das Abas (Inbox / Nova Mensagem) */
.msg-tabs { 
    display: flex; 
    border-bottom: 2px solid #eee; 
    background: #fafafa; 
}
.msg-tab { 
    flex: 1; 
    padding: 12px; 
    text-align: center; 
    cursor: pointer; 
    border: none; 
    background: none; 
    font-weight: bold; 
    color: var(--text-muted); 
    transition: 0.2s; 
    font-size: 0.95rem; 
}
.msg-tab.active { 
    background: white; 
    color: var(--blue-def-text); 
    border-bottom: 3px solid var(--blue-def-text); 
}
.msg-tab:hover:not(.active) { 
    background: #f0f0f0; 
}

/* Estilo dos Cartões de Mensagem */
.msg-card { 
    background: white; 
    border: 1px solid #e0e0e0; 
    border-radius: 8px; 
    padding: 15px; 
    margin-bottom: 15px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.02); 
}
.msg-card.sent { border-left: 4px solid #2ecc71; } /* Linha verde para as enviadas por mim */
.msg-card.received { border-left: 4px solid var(--blue-def-text); } /* Linha azul para as recebidas */

.msg-header { 
    display: flex; 
    justify-content: space-between; 
    margin-bottom: 10px; 
    font-size: 0.8rem; 
    color: #7f8c8d; 
    border-bottom: 1px dashed #eee; 
    padding-bottom: 5px; 
}
.msg-header strong { color: var(--text-main); font-size: 0.9rem; }
.msg-content { font-size: 0.95rem; color: #333; line-height: 1.5; white-space: pre-wrap; }

/* Grid de Checkboxes para selecionar destinatários */
.checkbox-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 10px; 
    background: #f8f9fa; 
    padding: 15px; 
    border-radius: 8px; 
    border: 1px solid #eee; 
    margin-bottom: 15px; 
}
.check-item { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    font-size: 0.9rem; 
    cursor: pointer; 
}

/* Ajustes Mobile para as Checkboxes */
@media (max-width: 600px) {
    .checkbox-grid {
        grid-template-columns: 1fr; /* Fica uma abaixo da outra no telemóvel */
    }
}

/* Estilos para as caixas de texto longo (História) */
.history-block {
    margin-bottom: 20px;
}

.editable-text-box {
    margin-top: 8px;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-height: 60px;
    white-space: pre-wrap; /* A MÁGICA ESTÁ AQUI: Preserva os Enters do usuário */
    outline: none;
    transition: all 0.2s ease;
    color: var(--text-main);
    font-size: 0.95rem;
    line-height: 1.6;
}

.editable-text-box:focus {
    border-color: var(--blue-def);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(41, 128, 185, 0.1);
}