:root {
    --azul: #2563eb;
    --azul-escuro: #1e40af;
    --verde: #16a34a;
    --amarelo: #ca8a04;
    --cinza: #6b7280;
    --vermelho: #dc2626;
    --fundo: #f3f4f6;
    --branco: #ffffff;
    --borda: #e5e7eb;
    --texto: #111827;
    --texto-claro: #6b7280;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--fundo);
    color: var(--texto);
}

/* ---------- TOPBAR ---------- */
.topbar {
    background: var(--azul-escuro);
    color: white;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar-nav a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    margin-left: 18px;
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 6px;
}
.topbar-nav a.active { background: rgba(255,255,255,0.15); color: white; font-weight: 600; }
.topbar-nav a.logout { color: #fca5a5; }
.topbar-nav a:hover { background: rgba(255,255,255,0.1); }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

/* ---------- LOGIN ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, var(--azul-escuro), var(--azul));
}
.login-card {
    background: white;
    padding: 36px 32px;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .subtitle { color: var(--texto-claro); margin-bottom: 20px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login-form label { font-size: 13px; font-weight: 600; margin-top: 6px; }
.login-form input {
    padding: 10px 12px;
    border: 1px solid var(--borda);
    border-radius: 8px;
    font-size: 15px;
}
.login-form button {
    margin-top: 14px;
    padding: 12px;
    background: var(--azul);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.login-form button:hover { background: var(--azul-escuro); }
.alerta-erro {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 14px;
}

/* ---------- BENTO GRID ---------- */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto auto;
    gap: 14px;
    margin-bottom: 20px;
}

/* Card base */
.bento-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
    min-height: 110px;
    transition: box-shadow 0.18s ease;
}
.bento-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }

/* Acento decorativo */
.bento-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 16px 16px 0 0;
    background: var(--borda);
}
.bento-card.acento-verde::before  { background: var(--verde); }
.bento-card.acento-azul::before   { background: var(--azul); }
.bento-card.acento-amarelo::before { background: #f59e0b; }
.bento-card.acento-cinza::before  { background: var(--cinza); }
.bento-card.acento-roxo::before   { background: #7c3aed; }

/* Posicionamento no grid */
.bento-fat-exec   { grid-column: 1 / 3; grid-row: 1; } /* largo — faturamento executado */
.bento-fat-prev   { grid-column: 3 / 5; grid-row: 1; } /* largo — faturamento previsto */
.bento-total      { grid-column: 1;     grid-row: 2; }
.bento-pendentes  { grid-column: 2;     grid-row: 2; }
.bento-ocupacao   { grid-column: 3;     grid-row: 2; }
.bento-proximo    { grid-column: 4;     grid-row: 2; }

/* Tipografia interna */
.bento-icone { font-size: 22px; line-height: 1; }
.bento-label { font-size: 12px; color: var(--texto-claro); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.bento-valor {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--texto);
    margin-top: 2px;
}
.bento-fat-exec .bento-valor { color: var(--verde); font-size: 32px; }
.bento-fat-prev .bento-valor { color: var(--azul);  font-size: 32px; }
.bento-sub {
    font-size: 12px;
    color: var(--texto-claro);
    margin-top: 2px;
}

/* Barra de progresso (ocupação) */
.bento-barra-wrap {
    margin-top: 8px;
    background: var(--fundo);
    border-radius: 999px;
    height: 6px;
    overflow: hidden;
}
.bento-barra-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--azul);
    transition: width 0.5s ease;
}

/* Próximo agendamento — texto menor */
.bento-proximo .bento-valor { font-size: 18px; }
.bento-proximo .bento-sub   { font-size: 11px; line-height: 1.5; }

@media (max-width: 900px) {
    .bento-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
    }
    .bento-fat-exec,
    .bento-fat-prev { grid-column: span 2; grid-row: auto; }
    .bento-total, .bento-pendentes,
    .bento-ocupacao, .bento-proximo { grid-column: span 1; grid-row: auto; }
}
@media (max-width: 640px) {
    .bento-grid { grid-template-columns: 1fr; }
    .bento-fat-exec,
    .bento-fat-prev,
    .bento-total, .bento-pendentes,
    .bento-ocupacao, .bento-proximo { grid-column: 1; grid-row: auto; }
    .bento-fat-exec .bento-valor,
    .bento-fat-prev .bento-valor { font-size: 26px; }
}

/* ---------- NAVEGAÇÃO SEMANA ---------- */
.navegacao-semana {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    background: white;
    padding: 10px 16px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.navegacao-semana button {
    background: var(--fundo);
    border: 1px solid var(--borda);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}
.navegacao-semana button:hover { background: var(--borda); }
#labelSemana { font-weight: 600; font-size: 14px; }

/* ---------- LEGENDA ---------- */
.legenda { display: flex; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; font-size: 13px; }
.legenda-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot-livre { background: #e5e7eb; border: 1px solid #d1d5db; }
.dot-ocupado { background: var(--azul); }
.dot-servico { background: var(--amarelo); }
.dot-concluido { background: var(--cinza); }

/* ---------- CALENDÁRIO ---------- */
.calendario-wrap { overflow-x: auto; background: white; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.calendario { width: 100%; border-collapse: collapse; min-width: 700px; }
.calendario th, .calendario td {
    border: 1px solid var(--borda);
    padding: 6px;
    text-align: center;
    font-size: 12px;
}
.calendario th { background: var(--fundo); font-size: 12px; position: sticky; top: 0; }
.calendario td.hora-label { background: var(--fundo); font-weight: 600; white-space: nowrap; }
.slot {
    min-height: 36px;
    border-radius: 6px;
    padding: 4px;
    cursor: default;
    font-size: 11px;
    line-height: 1.3;
}
.slot-livre { background: #f9fafb; color: #9ca3af; }
.slot-ocupado { background: #dbeafe; color: #1e3a8a; cursor: pointer; font-weight: 600; }
.slot-em_servico, .slot-confirmado.amarelo { background: #fef3c7; color: #78350f; cursor: pointer; font-weight: 600; }
.slot-concluido { background: #e5e7eb; color: #4b5563; cursor: pointer; }
.slot-pendente { background: #dbeafe; color: #1e3a8a; cursor: pointer; font-weight: 600; }
.slot:hover:not(.slot-livre) { opacity: 0.85; }

/* ---------- TOASTS ---------- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 320px;
}
.toast {
    background: white;
    border-left: 5px solid var(--azul);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    border-radius: 8px;
    padding: 14px 16px;
    font-size: 14px;
    animation: slideIn 0.3s ease;
}
.toast strong { display: block; margin-bottom: 4px; }
@keyframes slideIn { from { transform: translateX(120%); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* ---------- MODAL ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
    background: white;
    border-radius: 14px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}
.modal-fechar {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--texto-claro);
}
.modal-box h3 { margin-top: 0; }
.modal-box label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.modal-box input, .modal-box textarea, .modal-box select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--borda);
    border-radius: 8px;
    font-size: 14px;
}
.checkbox-linha { display: flex; align-items: center; gap: 8px; }
.checkbox-linha input { width: auto; }

.btn-primario {
    background: var(--azul);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px;
}
.btn-primario:hover { background: var(--azul-escuro); }
.btn-perigo {
    background: var(--vermelho);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 14px;
    width: 100%;
}
.btn-perigo:hover { background: #b91c1c; }
.btn-secundario {
    background: var(--fundo);
    border: 1px solid var(--borda);
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

.detalhe-linha { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--borda); font-size: 14px; }
.detalhe-linha span:first-child { color: var(--texto-claro); }
.detalhe-acoes { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.detalhe-acoes button { flex: 1; padding: 10px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; }
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-pendente, .status-confirmado { background: #dbeafe; color: #1e3a8a; }
.status-em_servico { background: #fef3c7; color: #78350f; }
.status-concluido { background: #e5e7eb; color: #374151; }
.status-cancelado { background: #fee2e2; color: #991b1b; }

/* ---------- CRUD ---------- */
.painel-secao {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.painel-secao h2 { margin-top: 0; font-size: 18px; }
.painel-secao label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.painel-secao input, .painel-secao select {
    width: 100%;
    max-width: 320px;
    padding: 9px 10px;
    border: 1px solid var(--borda);
    border-radius: 8px;
    font-size: 14px;
}
.secao-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.tabela-crud { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 13px; }
.tabela-crud th, .tabela-crud td { border-bottom: 1px solid var(--borda); padding: 10px 8px; text-align: left; }
.tabela-crud th { color: var(--texto-claro); font-size: 12px; text-transform: uppercase; }
.tabela-crud .acoes-cel { display: flex; gap: 6px; }
.tabela-crud .acoes-cel button { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--borda); background: white; cursor: pointer; font-size: 12px; }
.badge-ativo { color: var(--verde); font-weight: 600; }
.badge-inativo { color: var(--texto-claro); }
.hidden { display: none !important; }
hr { border: none; border-top: 1px solid var(--borda); margin: 20px 0; }

@media (max-width: 640px) {
    .bento-grid { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: flex-start; }
    .topbar-nav { display: flex; flex-wrap: wrap; gap: 4px; }
    .topbar-nav a { margin-left: 0; }
}

/* ========== DARK MODE ========== */
[data-tema="escuro"] {
    --fundo:        #0f1117;
    --branco:       #1a1d27;
    --borda:        #2e3244;
    --texto:        #e8eaf0;
    --texto-claro:  #8b91a8;
    /* mantém azul/verde/vermelho/amarelo — só os neutros mudam */
}

[data-tema="escuro"] body            { background: var(--fundo); color: var(--texto); }
[data-tema="escuro"] .topbar          { background: #12151f; border-bottom: 1px solid var(--borda); }
[data-tema="escuro"] .bento-card,
[data-tema="escuro"] .painel-secao,
[data-tema="escuro"] .modal-box,
[data-tema="escuro"] .navegacao-semana,
[data-tema="escuro"] .calendario-wrap { background: var(--branco); border-color: var(--borda); }
[data-tema="escuro"] .calendario th,
[data-tema="escuro"] .calendario td   { border-color: var(--borda); }
[data-tema="escuro"] .calendario th,
[data-tema="escuro"] .calendario td.hora-label { background: #12151f; }
[data-tema="escuro"] .slot-livre       { background: #1e2130; color: #4b5470; }
[data-tema="escuro"] .navegacao-semana button {
    background: #12151f;
    border-color: var(--borda);
    color: var(--texto);
}
[data-tema="escuro"] .navegacao-semana button:hover { background: var(--borda); }
[data-tema="escuro"] .tabela-crud th,
[data-tema="escuro"] .tabela-crud td  { border-color: var(--borda); color: var(--texto); }
[data-tema="escuro"] .tabela-crud .acoes-cel button {
    background: #12151f;
    border-color: var(--borda);
    color: var(--texto);
}
[data-tema="escuro"] input,
[data-tema="escuro"] select,
[data-tema="escuro"] textarea {
    background: #12151f;
    border-color: var(--borda);
    color: var(--texto);
}
[data-tema="escuro"] .toast         { background: var(--branco); color: var(--texto); }
[data-tema="escuro"] .login-card    { background: var(--branco); color: var(--texto); }
[data-tema="escuro"] .login-form input { background: #12151f; border-color: var(--borda); color: var(--texto); }
[data-tema="escuro"] hr             { border-color: var(--borda); }
[data-tema="escuro"] .bento-barra-wrap { background: #12151f; }
[data-tema="escuro"] .detalhe-linha { border-color: var(--borda); }
[data-tema="escuro"] .preview-logo  { border: 1px solid var(--borda); }

/* botão toggle de tema */
.tema-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--borda);
}
.tema-toggle:last-child { border-bottom: none; }
.tema-toggle-label { font-size: 14px; font-weight: 600; }
.tema-toggle-sub   { font-size: 12px; color: var(--texto-claro); margin-top: 2px; }
.switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--borda);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s;
}
.switch-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-slider              { background: var(--azul); }
.switch input:checked + .switch-slider::before      { transform: translateX(20px); }
