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

:root {
    --primary-color: #4A90E2;
    --secondary-color: #2C3E50;
    --accent-color: #F39C12;
    --success-color: #27AE60;
    --danger-color: #E74C3C;
    --light-bg: #ECF0F1;
    --dark-text: #2C3E50;
    --light-text: #7F8C8D;
    --border-color: #BDC3C7;
    --card-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--dark-text);
}

#navbar {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    padding: 0.75rem 2rem;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* Botão Hamburger */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.3s;
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
}

.logo img {
    height: 100px;
}

.main-nav {
    display: flex;
    justify-content: flex-start;
    flex-shrink: 1; /* Permite que o menu encolha um pouco antes de quebrar */
}

.main-nav ul {
    list-style: none;
    display: flex;
    gap: 0.2rem;
    align-items: center;
    margin: 0;
    padding: 0;
}

.main-nav a {
    text-decoration: none;
    color: white;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.07rem;
    white-space: nowrap;
}

.main-nav a:hover {
    background: rgba(255, 255, 255, 0.1);
}

.main-nav a.active {
    background: var(--primary-color);
    color: white;
}

.main-nav .btn-logout {
    background: var(--danger-color);
    color: white;
}

.main-nav .btn-logout:hover {
    background: #C0392B;
}

.user-area {
    display: flex !important;
    flex-direction: column !important; /* Força Bandeiras em cima, Nome no meio, Botão em baixo */
    align-items: center !important;    /* Centraliza tudo horizontalmente */
    gap: 5px !important;               /* Espaço entre as 3 linhas */
    justify-content: center !important;
    min-width: 150px;                  /* Garante espaço para o conteúdo */
}

.idioma-selector {
    display: flex;
    gap: 10px;
    margin-right: 0.5rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
    z-index: 9999;
    padding: 6px 10px;
}

.idioma-selector .idioma-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    text-decoration: none;
    font-size: 1.5rem;
    opacity: 0.6;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.1);
}

.idioma-selector .idioma-btn:hover {
    opacity: 1;
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.2);
}

.idioma-selector .idioma-btn.active {
    opacity: 1;
    background: rgba(102, 126, 234, 0.15);
}

.user-name {
    color: white;
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.user-name i {
    font-size: 1rem;
    line-height: 1;
}

.user-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.user-buttons .btn-secondary,
.user-buttons .btn-admin {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.user-buttons .btn-admin {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.user-buttons .btn-admin:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-2px);
}

.btn-logout {
    background: var(--danger-color) !important;
    color: white !important;
}

.container {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.page-header {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}

.page-header h1 {
    color: var(--primary-color);
    font-size: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.subtitle {
    color: var(--light-text);
    font-size: 1.1rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}

.btn-primary:hover {
    background: #357ABD;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--dark-text);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s;
    border: none;
    cursor: pointer;
}

.btn-icon {
    background: transparent;
    color: var(--primary-color);
    padding: 0.5rem;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.3s;
    border: none;
    cursor: pointer;
}

.btn-icon:hover {
    background: var(--light-bg);
}

.btn-icon.btn-danger {
    color: var(--danger-color);
}

.content-wrapper {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--card-shadow);
}

.tema-section {
    margin-bottom: 2.5rem;
}

.tema-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, #357ABD 100%);
    color: white;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.tema-header h2 {
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sermoes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.sermao-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1.5rem;
    transition: all 0.3s;
}

.sermao-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.sermao-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.8rem;
}

.sermao-resumo {
    color: var(--light-text);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.sermao-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-view, .btn-info, .btn-edit {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.btn-view {
    background: var(--primary-color);
    color: white;
}

.btn-info {
    background: var(--accent-color);
    color: white;
}

.btn-edit {
    background: var(--light-bg);
    color: var(--dark-text);
}

.visitacao-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: all 0.3s;
}

.visitacao-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.visitacao-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--light-bg);
}

.visitacao-info h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.visitacao-date {
    color: var(--light-text);
    font-size: 0.95rem;
}

.visitacao-actions {
    display: flex;
    gap: 0.5rem;
}

.visitacao-mensagem {
    background: var(--light-bg);
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    margin: 0.5rem 0;
    line-height: 1.6;
}

.visitacao-obs {
    color: var(--light-text);
    font-style: italic;
    margin-top: 0.8rem;
}

.form-container {
    max-width: 800px;
    margin: 0 auto;
}

.form-visitacao .form-group {
    margin-bottom: 1.5rem;
}

.form-visitacao label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-text);
}

.form-visitacao input,
.form-visitacao textarea,
.form-visitacao select {
    width: 100%;
    max-width: 100%;
    padding: 0.8rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s;
    box-sizing: border-box;
}

/* Corrigir campos de data em mobile */
.form-visitacao input[type="date"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.form-visitacao input:focus,
.form-visitacao textarea:focus,
.form-visitacao select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

.categoria-section {
    margin-bottom: 3rem;
}

.categoria-header {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #34495E 100%);
    color: white;
    padding: 1.2rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.categoria-header h2 {
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.ideias-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.ideia-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1.5rem;
    transition: all 0.3s;
}

.ideia-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.1);
}

.ideia-header {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.ideia-header h3 {
    color: var(--primary-color);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.badge-padrao {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
    color: white;
    padding: 0.25rem 0.7rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ideia-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.ideia-ref {
    background: var(--accent-color);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    background: var(--light-bg);
    color: var(--dark-text);
    border: none;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.btn-icon:hover {
    transform: translateY(-2px);
}

.btn-edit {
    background: var(--primary-color);
    color: white;
}

.btn-edit:hover {
    background: #357ABD;
}

.btn-delete {
    background: var(--danger-color);
    color: white;
}

.btn-delete:hover {
    background: #C0392B;
}

.ideia-texto {
    background: var(--light-bg);
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--accent-color);
    font-style: italic;
    line-height: 1.6;
    margin-bottom: 0.8rem;
}

.ideia-obs {
    color: var(--light-text);
    font-size: 0.9rem;
}

.no-data,
.no-data-small {
    text-align: center;
    padding: 3rem;
    color: var(--light-text);
}

.no-data i {
    color: var(--border-color);
    margin-bottom: 1rem;
}

.no-data p {
    font-size: 1.2rem;
    margin: 1rem 0;
}

.temas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.tema-card {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.3s;
}

.tema-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    border-color: var(--primary-color);
}

.tema-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--light-bg);
}

.tema-card-header h3 {
    color: var(--primary-color);
    font-size: 1.3rem;
    margin: 0;
}

.tema-count {
    background: var(--accent-color);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.tema-card-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tema-card-actions .btn-icon {
    flex: 1;
    min-width: 100px;
    justify-content: center;
    padding: 0.7rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.btn-disabled {
    background: var(--light-bg);
    color: var(--light-text);
    cursor: not-allowed;
    opacity: 0.6;
}

.alert {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 1rem;
}

.alert-error {
    background: #FFEBEE;
    border-left: 4px solid var(--danger-color);
    color: #C62828;
}

.alert-success {
    background: #E8F5E9;
    border-left: 4px solid var(--success-color);
    color: #2E7D32;
}

.info-box {
    background: linear-gradient(135deg, #E3F2FD 0%, #BBDEFB 100%);
    border-left: 4px solid var(--primary-color);
    padding: 1.5rem;
    border-radius: 8px;
    margin-top: 2rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.info-box i {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-top: 0.2rem;
}

.editor-container {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.ql-toolbar {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: var(--light-bg);
}

.ql-container {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    min-height: 300px;
    font-size: 1rem;
}

.data-table {
    width: 100% !important;
    border-collapse: collapse;
    display: table !important; /* Força comportamento de tabela */
    table-layout: auto !important;
}

/* Coluna 1 (Data): Ocupa apenas o necessário */
.data-table th:nth-child(1), 
.data-table td:nth-child(1) {
    width: 1% !important;
    white-space: nowrap !important;
    padding-right: 20px !important;
}

/* Colunas 2 e 3 (Sermão e Igreja): Expandem */
.data-table th:nth-child(2), 
.data-table td:nth-child(2),
.data-table th:nth-child(3), 
.data-table td:nth-child(3) {
    width: auto !important;
}

/* Última coluna (Ações): Compacta */
.data-table th:last-child, 
.data-table td:last-child {
    width: 1% !important;
    white-space: nowrap !important;
}


.data-table thead {
    background: linear-gradient(135deg, var(--primary-color) 0%, #357ABD 100%);
    color: white;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    font-weight: 600;
}

.data-table tbody tr:hover {
    background: var(--light-bg);
}

.form-card {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--card-shadow);
}

.form-ideia .form-group {
    margin-bottom: 1.5rem;
}

.form-ideia label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-ideia input[type="text"],
.form-ideia textarea,
.form-ideia select {
    width: 100%;
    padding: 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s;
    font-family: inherit;
}

.form-ideia input[type="text"]:focus,
.form-ideia textarea:focus,
.form-ideia select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.form-ideia textarea {
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--light-bg);
}

/* ========================================
   RESPONSIVIDADE GERAL - TABLETS E MOBILE
   ======================================== */
@media (max-width: 1024px) {
    /* Ajustes de Container e Layout */
    .container {
        padding: 1rem !important;
        max-width: 100% !important;
    }

    .main-content {
        padding: 1rem !important;
        margin-top: 1rem !important;
    }

    .header-content h1 {
        font-size: 1.5rem !important;
    }


    .data-table tr {
        margin-bottom: 1.5rem !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
        border-radius: 12px !important;
        overflow: visible !important;
        background: rgba(255,255,255,0.05) !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.2) !important;
    }

    .data-table td {
        text-align: left !important;
        padding: 0.8rem 1rem !important;
        padding-left: 50% !important;
        position: relative !important;
        border-bottom: 1px solid rgba(255,255,255,0.05) !important;
        min-height: 45px !important;
        display: flex !important;
        align-items: center !important;
    }

    .data-table td::before {
        position: absolute !important;
        left: 1rem !important;
        width: 40% !important;
        font-weight: 600 !important;
        color: rgba(255,255,255,0.6) !important;
        font-size: 0.85rem !important;
        text-transform: uppercase !important;
    }

    /* Mantenha aqui todos os seus seletores .data-table tbody td:nth-child(...) 
       que inserem o conteúdo e ícones específicos da sua tabela */
}

/* ========================================
   NAVBAR DINÂMICO - IPAD E IPHONE
   ======================================== */

/* DESKTOP E TELAS GRANDES (1025px+): Menu sempre horizontal */
@media (min-width: 1025px) {
    #navbar {
        display: flex !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        padding: 0.75rem 2rem !important;
    }

    .menu-toggle { display: none !important; }

    .main-nav {
        display: flex !important;
        position: static !important;
        background: transparent !important;
        box-shadow: none !important;
        width: auto !important;
        pointer-events: auto !important;
    }

    .main-nav ul {
        flex-direction: row !important;
        gap: 0.2rem !important;
    }

    .main-nav a {
        font-size: 1.07rem !important;
        padding: 0.6rem 1rem !important;
    }

    .logo img { height: 100px !important; }

    .user-area {
       flex-direction: column !important; /* MUDAR DE row PARA column */
        align-items: center !important;
        gap: 0.3rem !important;
    }
}

/* MODO PAISAGEM (iPad deitado): Menu em linha única, mas otimizado */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    #navbar {
        display: flex !important;
        flex-wrap: nowrap !important;
        justify-content: space-between !important;
        padding: 0.75rem 1.5rem !important;
    }

    .menu-toggle { display: none !important; }

    .main-nav {
        display: flex !important;
        position: static !important;
        background: transparent !important;
        box-shadow: none !important;
        width: auto !important;
        pointer-events: auto !important;
    }

    .main-nav ul {
        flex-direction: row !important;
        gap: 0.5rem !important;
    }

    .main-nav a {
        font-size: 1rem !important;
        padding: 0.5rem 0.8rem !important;
    }

    .logo img { height: 70px !important; }

    .user-area {
        flex-direction: column !important; /* MUDAR DE row PARA column */
        align-items: center !important;
        gap: 0.3rem !important;
    }
}

/* MODO RETRATO (iPad em pé) E IPHONE: Menu Sanduíche */
@media (max-width: 1024px) and (orientation: portrait), (max-width: 768px) {

    .main-nav {
        display: none;
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        width: 100% !important;
        background: #2c3e50 !important;
        padding: 1rem 0 !important;
        border-top: 1px solid rgba(255,255,255,0.1);
        box-shadow: 0 10px 20px rgba(0,0,0,0.3);
        z-index: 10000 !important;
    }

    .menu-toggle {
        display: flex !important;
        z-index: 100000 !important;
        pointer-events: auto !important;
        padding: 10px; 
        margin-left: -10px;
        font-size: 2rem;
        width: 50px;
        height: 50px;
    }
    
    .menu-toggle i {
        font-size: 2rem;
    }

    .logo {
        grid-column: 2;
        display: flex;
        justify-content: center;
    }

    .logo img {
        height: 92px !important; /* Logo maior como solicitado */
    }

    .user-area {
        grid-column: 3;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-end !important;
        justify-content: center;
        gap: 2px !important;
    }


    .main-nav.active { display: block !important; }

    .main-nav ul {
        flex-direction: column !important;
        width: 100%;
    }

    .main-nav a {
        display: flex !important;
        align-items: center;
        padding: 1.2rem 2rem !important; /* Área de toque grande para iPad */
        font-size: 1.2rem !important;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }

    .user-name { font-size: 0.85rem !important; }
    .idioma-selector { scale: 1.1; margin-bottom: 5px; }

    /* Forçamos a tabela a se comportar como no Desktop */
    .data-table {
        display: table !important;
    }
    .data-table thead {
        display: table-header-group !important;
    }
    .data-table tbody {
        display: table-row-group !important;
    }
    .data-table tr {
        display: table-row !important;
    }
    .data-table td {
        display: table-cell !important;
        padding: 0.8rem !important;
        text-align: left !important;
    }
    .data-table td::before {
        display: none !important; /* Remove os nomes das colunas que apareciam no mobile */
    }
}

@media (min-width: 501px) and (max-width: 768px) {
    #navbar {
        display: flex !important; /* Muda de grid para flex para facilitar a quebra */
        flex-direction: row;
        flex-wrap: wrap; /* Permite descer a área do usuário */
        justify-content: space-between;
        padding: 1rem !important;
    }

    /* Força o menu a ocupar a linha de cima junto com a logo */
    .logo { order: 1; }
    .main-nav { 
        order: 2;
        display: flex !important; /* Mantém o menu visível (não vira hambúrguer ainda) */
    }
    
    /* Força a área do usuário para a linha de baixo, centralizada ou à direita */
    .user-area {
        order: 3;
        width: 100%; /* Ocupa a largura total para forçar a quebra */
        flex-direction: row !important;
        justify-content: flex-end; 
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid rgba(255,255,255,0.1);
        gap: 1.5rem !important;
    }

    .main-nav a {
        font-size: 1.15rem !important; /* Fonte bem legível no tablet */
        padding: 0.7rem 0.9rem !important;
    }

    .user-name, .user-buttons .btn-secondary {
        font-size: 1.05rem !important;
    }

    .logo img {
        height: 80px !important;
    }
}

/* ========================================
   RESPONSIVIDADE - MOBILE (até 768px)
   ======================================== */
@media (max-width: 768px) {
    #navbar {
        display: grid;
        grid-template-columns: 1fr auto 1fr; /* [1] Esquerda: Menu, [2] Meio: Logo, [3] Direita: User */
        grid-template-rows: auto; /* Remove a segunda linha que existia antes */
        flex-wrap: nowrap !important; /* Garante que não quebre mesmo com a mudança que fizemos para o PC */
        align-items: center;
        gap: 0.2rem;
        z-index: 9999 !important; /* Aumentamos para garantir que fique sobre qualquer conteúdo */
        position: sticky !important; /* Mantém a barra visível mesmo ao rolar */
        top: 0;
    }
    
    /* Hamburger à esquerda */
    .menu-toggle {
        grid-row: 1;
        grid-column: 1;
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 55px;
        height: 55px;
        padding: 0;
        margin-left: 1rem;
        background: transparent !important;
        border-radius: 8px;
        font-size: 2.2rem;
    }
    
    .menu-toggle:hover {
        background: rgba(255,255,255,0.1) !important;
    }
    
    .menu-toggle i {
        font-size: 2rem;
        line-height: 1;
    }
    
    /* Logo centralizada - coluna do meio */
    .logo {
        grid-row: 1;
        grid-column: 2;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        align-self: center;
        padding: 0;
    }
    
    .logo img {
        height: 90px !important;
        width: auto;
        display: block;
    }
    
    /* User area à direita - bandeiras acima, nome + coroa abaixo */
    .user-area {
        grid-column: 3;
        display: flex;
        flex-direction: column;
        align-items: flex-end; /* Alinha o nome e assinatura à direita da tela */
        gap: 0.1rem;    
    }
    
    /* Seletor de idioma em mobile - primeira linha */
    .idioma-selector {
        display: flex !important;
        gap: 8px;
        margin-right: 0;
        order: -1;
    }
    
    .idioma-selector .idioma-btn {
        width: 32px;
        height: 32px;
        font-size: 1.3rem;
    }
    
    /* Nome + coroa em linha abaixo */
    .user-name {
        display: flex;
        align-items: center;
        font-size: 0.75rem;
        color: rgba(255,255,255,0.95);
        white-space: nowrap;
    }
    
    .user-name i {
        margin-right: 0.3rem;
        font-size: 0.9rem;
    }
    
    .user-buttons {
        display: flex;
        align-items: center;
    }
    
    .user-buttons .btn-secondary {
        background: transparent;
        border: none;
        padding: 0;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .user-buttons .btn-secondary i {
        font-size: 1.2rem;
        color: #f0c14b;
        margin: 0;
    }
    
    .user-buttons .btn-secondary span,
    .user-buttons .btn-admin {
        display: none !important;
    }
    
    /* Menu Mobile - nova linha, ocupa toda largura */
    .main-nav {
        grid-row: 2;
        grid-column: 1 / -1;
        display: none;
        width: 100%;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 12px;
        padding: 1rem;
        margin-top: 0.5rem;
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        width: 100% !important;
        z-index: 10000 !important; /* O menu aberto deve ser a camada mais alta de todas */
        background: #2c3e50 !important;
        display: none; /* Só aparece com o .active */
    }
    
    .main-nav.active {
        display: block !important;
    }
    
    .main-nav ul {
        flex-direction: column;
        width: 100%;
        gap: 0.8rem;
    }
    
    .main-nav a {
        width: 100%;
        justify-content: flex-start;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.05);
        padding: 1rem 1.2rem !important; /* Aumenta o espaçamento interno para facilitar o toque */
        font-size: 1.2rem !important;    /* Aumenta o tamanho do texto (era 1rem) */
        font-weight: 500;                /* Deixa o texto um pouco mais encorpado */
    }
    
    .main-nav a i {
        display: inline-block;
        font-size: 1.3rem !important;    /* Ícone levemente maior que o texto */
        width: 30px !important;
    }
    
    .main-nav a:hover,
    .main-nav a.active {
        background: var(--primary-color);
    }
    
    .main-nav .btn-logout {
        margin-top: 0.5rem;
        background: var(--danger-color);
    }
    
    /* Container e conteúdo ocupando 100% */
    .container {
        max-width: 100%;
        width: 100%;
        padding: 0.8rem;
        margin: 0;
    }
    
    .page-header {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
        padding: 1.2rem;
        margin-bottom: 1rem;
        border-radius: 8px;
    }
    
    .page-header h1 {
        font-size: 1.4rem;
    }
    
    .page-header > div {
        display: flex;
        gap: 1rem;
        width: 100%;
        justify-content: center;
    }
    
    .page-header .btn-secondary,
    .page-header .btn-primary {
        padding: 0.7rem 1.2rem;
        font-size: 0.9rem;
    }
    
    .sermoes-grid,
    .ideias-list {
        grid-template-columns: 1fr;
    }
    
    .content-wrapper {
        padding: 0.8rem;
        border-radius: 8px;
    }
    
    .tema-section {
        margin-bottom: 1rem;
        border-radius: 8px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn-primary,
    .form-actions .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .table-responsive {
        overflow-x: hidden !important;
        overflow-y: visible !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .data-table {
        min-width: unset !important;
        width: 100% !important;
        border-collapse: separate !important;
        border-spacing: 0 !important;
        display: block !important;
        margin: 0 !important;
    }
    
    .data-table thead {
        display: none !important;
    }
    
    .data-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
    }
    
    .data-table tbody tr {
        display: flex !important;
        flex-direction: column !important;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        border-radius: 16px !important;
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
        overflow: hidden !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }
    
    .data-table tbody td {
        display: block !important;
        width: 100% !important;
        padding: 0.8rem 1rem !important;
        border-bottom: 1px solid rgba(255,255,255,0.15) !important;
        color: white !important;
        background: transparent !important;
        border-left: none !important;
        border-right: none !important;
        border-top: none !important;
        box-sizing: border-box !important;
    }
    
    .data-table tbody td:first-child {
        background: transparent !important;
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        text-align: left !important;
        padding: 1rem !important;
    }
    
    .data-table tbody td:first-child strong {
        font-size: 1.3rem !important;
        display: block !important;
        color: white !important;
    }
    
    .data-table tbody td:first-child small {
        color: rgba(255,255,255,0.8) !important;
        font-weight: 400 !important;
    }
    
    .data-table tbody td:nth-child(2),
    .data-table tbody td:nth-child(3) {
        justify-content: flex-start !important;
        gap: 0.8rem !important;
    }
    
    .data-table tbody td:nth-child(2) i,
    .data-table tbody td:nth-child(3) i {
        color: rgba(255,255,255,0.9) !important;
        font-size: 1.1rem !important;
        width: 24px !important;
        text-align: center !important;
    }
    
    .data-table tbody td:nth-child(3)::before {
        content: "\f3c5" !important;
        font-family: "Font Awesome 6 Free" !important;
        font-weight: 900 !important;
        color: rgba(255,255,255,0.9) !important;
        font-size: 1.1rem !important;
        width: 24px !important;
        text-align: center !important;
    }
    
    /* ÁREA DE BOTÕES - Último TD do card */
    .data-table tbody td:last-child {
        border-bottom: none !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 1.2rem !important;
        background: rgba(255,255,255,0.15) !important;
        gap: 2rem !important;
        min-height: 80px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .data-table tbody td:last-child::before {
        display: none !important;
        content: none !important;
    }
    
    .data-table tbody td a,
    .data-table tbody td strong {
        word-break: break-word !important;
        color: white !important;
    }
    
    /* Link de editar dentro do último td */
    .data-table tbody td:last-child > a.btn-icon {
        background: white !important;
        color: #667eea !important;
        padding: 1rem !important;
        border-radius: 12px !important;
        font-size: 1.3rem !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 60px !important;
        min-height: 60px !important;
        text-decoration: none !important;
    }
    
    /* Formulário de excluir */
    .data-table tbody td:last-child > form {
        display: inline-flex !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Botão de excluir */
    .data-table tbody td:last-child > form button.btn-icon,
    .data-table tbody td:last-child > form .btn-icon-danger {
        background: #fee2e2 !important;
        color: #dc2626 !important;
        padding: 1rem !important;
        border-radius: 12px !important;
        font-size: 1.3rem !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 60px !important;
        min-height: 60px !important;
        border: none !important;
        cursor: pointer !important;
    }
    
    .data-table .btn-icon i {
        font-size: 1.3rem !important;
    }
    
    .badge {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
}

/* ========================================
   RESPONSIVIDADE - SMARTPHONES PEQUENOS (até 480px)
   ======================================== */
@media (max-width: 480px) {
    #navbar {
        padding: 0.5rem;
        gap: 0.4rem;
    }
    
    .menu-toggle {
        font-size: 2.2rem;
        padding: 0.4rem;
        width: 55px;
        height: 55px;
    }
    
    .user-area {
        gap: 0.4rem;
        margin-top: 0.2rem;
    }
    
    .user-name {
        font-size: 0.75rem;
    }
    
    .user-buttons .btn-secondary,
    .user-buttons .btn-admin {
        padding: 0.25rem 0.4rem;
        font-size: 0.6rem;
    }
    
    .main-nav a {
        padding: 0.7rem 0.8rem;
        font-size: 0.9rem;
    }
    
    .container {
        padding: 0.5rem;
        margin: 0;
    }
    
    .page-header {
        padding: 1rem;
    }
    
    .page-header h1 {
        font-size: 1.2rem;
    }
    
    .page-header > div {
        gap: 0.8rem;
    }
    
    .page-header .btn-secondary,
    .page-header .btn-primary {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
        flex: 1;
    }
    
    .sermao-card,
    .ideia-card {
        padding: 1rem;
    }
    
    .content-wrapper {
        padding: 0.5rem;
    }
    
    /* Botões de ação nos cards - garantir visibilidade */
    .data-table tbody td:last-child {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 1rem !important;
        padding: 1rem !important;
        min-height: 70px !important;
    }
    
    .data-table .btn-icon {
        min-width: 50px !important;
        min-height: 50px !important;
        padding: 0.8rem !important;
    }
    
    .data-table form[style*="inline"] {
        display: inline-flex !important;
    }
}

/* ========================================
   RESPONSIVIDADE - LANDSCAPE (celular deitado)
   ======================================== */
@media screen and (max-height: 500px),
       screen and (orientation: landscape) and (max-height: 450px) {
    #navbar {
        padding: 0.25rem 0.8rem;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }
    
    /* Hamburger à esquerda */
    .menu-toggle {
        order: 1;
        display: flex !important;
        font-size: 1.8rem;
        padding: 0.25rem;
        width: 45px;
        height: 45px;
    }
    
    /* Logo no centro */
    .logo {
        order: 2;
        flex: 1;
        display: flex;
        justify-content: center;
    }
    
    .logo img {
        height: 35px !important;
    }
    
    /* User à direita */
    .user-area {
        order: 3;
        flex-direction: row;
        gap: 0.25rem;
    }
    
    .user-name {
        font-size: 0.65rem;
    }
    
    .user-buttons .btn-secondary,
    .user-buttons .btn-admin {
        padding: 0.15rem 0.25rem;
        font-size: 0.5rem;
    }
    
    .main-nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: rgba(44, 62, 80, 0.98);
        z-index: 999;
    }
    
    .container {
        padding: 0.3rem;
    }
    
    .page-header {
        padding: 0.4rem;
    }
    
    .page-header h1 {
        font-size: 0.95rem;
    }
}

/* Badge Styles */
.badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    border-radius: 6px;
}

.badge-success {
    background-color: #27AE60;
    color: white;
}

.badge-danger {
    background-color: #E74C3C;
    color: white;
}

.badge-warning {
    background-color: #F39C12;
    color: white;
}

/* Button Icon Colors */
.btn-icon-warning {
    color: #F39C12;
}

.btn-icon-warning:hover {
    color: #E67E22;
}

.btn-icon-success {
    color: #27AE60;
}

.btn-icon-success:hover {
    color: #229954;
}


/* ===========================================
   CORREÇÃO ESPECÍFICA PARA iOS (iPhone e iPad retrato)
   Só aplica em telas pequenas ou iPad em modo retrato
   =========================================== */
@media only screen and (max-width: 768px),
       only screen and (max-width: 1024px) and (orientation: portrait) {

  /* cria um contexto de empilhamento confiável no Safari iOS */
  #navbar { 
    isolation: isolate !important; 
  }

  /* fechado: não captura toque */
  .main-nav:not(.active) { 
    pointer-events: none !important; 
  }

  /* aberto: captura toque */
  .main-nav.active { 
    pointer-events: auto !important; 
  }

  /* garante que o botão do sanduíche sempre receba toque */
  .menu-toggle { 
    pointer-events: auto !important; 
    touch-action: manipulation !important;
  }
}
