/* ===========================
   Variáveis e reset
   =========================== */
:root {
    --verde-escuro:  #1b4332;
    --verde:         #2d6a4f;
    --verde-medio:   #40916c;
    --verde-claro:   #52b788;
    --verde-pale:    #d8f3dc;
    --bg:            #f0f7f2;
    --text:          #1b2e23;
    --text-muted:    #52735f;
    --border:        #b7e4c7;
    --white:         #ffffff;
    --danger:        #c62828;
    --danger-bg:     #ffebee;
    --warning:       #e65100;
    --warning-bg:    #fff3e0;
    --success:       #2e7d32;
    --success-bg:    #e8f5e9;
    --sidebar-w:     240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

dialog {
    margin: auto;
    max-height: 90vh;
    overflow-y: auto;
}
dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1rem;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

a { color: var(--verde-medio); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===========================
   Layout de login (guest)
   =========================== */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, var(--verde-escuro) 0%, var(--verde-medio) 100%);
    padding: 1rem;
}

.login-card {
    background: var(--white);
    border-radius: 14px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    max-width: 220px;
    height: auto;
    display: block;
    margin: 0 auto 0.5rem;
}

.login-brand p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===========================
   Formulários
   =========================== */
.form-group {
    margin-bottom: 1.1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.875rem;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--verde-claro);
    box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.2);
}

/* ===========================
   Botões
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 7px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, opacity 0.15s, transform 0.1s;
    min-height: 42px;
}

.btn:active    { transform: translateY(1px); }
.btn:hover     { text-decoration: none; }
.btn-full      { width: 100%; margin-top: 0.4rem; }

.btn-primary   { background: var(--verde);        color: var(--white); }
.btn-primary:hover { background: var(--verde-medio); }

.btn-secondary { background: var(--verde-pale);   color: var(--verde-escuro); }
.btn-secondary:hover { background: var(--border); }

.btn-danger    { background: var(--danger);        color: var(--white); }
.btn-danger:hover { opacity: 0.88; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; min-height: 32px; }

/* ===========================
   Alertas
   =========================== */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 7px;
    margin-bottom: 1.1rem;
    font-size: 0.875rem;
    border: 1px solid transparent;
}

.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: #ef9a9a; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #ffcc80; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #a5d6a7; }

/* ===========================
   Layout autenticado (app)
   =========================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--verde-escuro);
    color: var(--white);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand strong {
    font-size: 1.1rem;
    font-weight: 700;
    display: block;
}

.sidebar-brand span {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.55);
}

.sidebar-nav {
    list-style: none;
    padding: 0.75rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1.25rem;
    color: rgba(255,255,255,0.75);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    text-decoration: none;
}

.sidebar-nav .nav-section {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.35);
    padding: 1rem 1.25rem 0.35rem;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.8rem;
    color: rgba(255,255,255,0.55);
}

.sidebar-footer strong {
    display: block;
    color: rgba(255,255,255,0.85);
    font-size: 0.875rem;
}

.sidebar-footer form { margin-top: 0.5rem; }

/* Conteúdo principal */
.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--verde-escuro);
}

.page-content {
    padding: 1.5rem;
    flex: 1;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--verde-escuro);
    margin-bottom: 1.5rem;
}

/* ===========================
   Cards e tabelas
   =========================== */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--verde-escuro);
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead th {
    background: var(--verde-pale);
    color: var(--verde-escuro);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.55rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
}

tbody td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7fdf9; }

/* Badges de status */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-muted   { background: #f0f0f0;           color: #666;            }
.badge-info    { background: #dbeafe;           color: #1e40af;         }

/* ===========================
   Responsividade — menu hambúrguer
   =========================== */

/* Botão hambúrguer (só visível em mobile) */
.nav-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 200;
    background: var(--verde-escuro);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 42px;
    height: 42px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    flex-direction: column;
    gap: 5px;
    padding: 0;
}
.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: all 0.25s;
}

/* Overlay escuro quando sidebar aberta */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 150;
}
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
    .nav-toggle { display: flex; }

    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        z-index: 160;
    }
    .sidebar.open { transform: translateX(0); }

    .main-wrapper {
        margin-left: 0;
        padding-top: 3.5rem; /* espaço para o botão hambúrguer */
    }
    .app-layout { flex-direction: row; }
}

/* ===========================
   Utilitários — Módulos
   =========================== */

/* Classe .input standalone (fora de .form-group) */
.input {
    padding: 0.6rem 0.875rem;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
    outline: none;
    border-color: var(--verde-claro);
    box-shadow: 0 0 0 3px rgba(82, 183, 136, 0.2);
}
select.input { width: auto; }

/* Cabeçalho de página (título + botão lado a lado) */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.page-header .page-title { margin-bottom: 0; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Barra de filtros */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.filter-bar .input-text { flex: 1; min-width: 200px; }

/* Grid de formulário */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0 1rem;
}
.form-group-wide { grid-column: 1 / -1; }

/* Checkbox */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Ações de formulário */
.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

/* Cabeçalho de card com botão */
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-header-row .card-title { margin-bottom: 0; }

/* Row de cards lado a lado */
.cards-row {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 768px) { .cards-row { grid-template-columns: 1fr; } }

/* Definition list em grid */
.dl-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1.25rem;
    font-size: 0.9rem;
}
.dl-grid dt { font-weight: 600; color: var(--text-muted); }

/* Métricas */
.metric-row { display: flex; flex-direction: column; gap: 1rem; }
.metric-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
}
.metric-value { font-size: 1.25rem; font-weight: 700; color: var(--verde-escuro); }

/* Badges de status de projeto */
.badge-aguardando   { background: #f0f0f0;           color: #555; }
.badge-em_andamento { background: var(--success-bg); color: var(--success); }
.badge-concluido    { background: var(--verde-pale);  color: var(--verde-escuro); }
.badge-cancelado    { background: var(--danger-bg);   color: var(--danger); }

/* Botão link em tabelas */
.btn-link {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--verde-medio);
    padding: 0;
    font-weight: 500;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.btn-danger-link { color: var(--danger); }

/* Coluna de ações em tabela */
td.actions { display: flex; gap: 0.75rem; align-items: center; white-space: nowrap; }
td.actions form { margin: 0; }

/* Alerta de erro genérico */
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #ef9a9a; border-radius: 7px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
.alert-danger ul { margin: 0.4rem 0 0 1rem; }

/* Modal de confirmação */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--white);
    border-radius: 12px;
    padding: 1.75rem;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}
.modal-title  { font-size: 1.1rem; font-weight: 700; color: var(--verde-escuro); margin-bottom: 0.75rem; }
.modal-body   { font-size: 0.95rem; margin-bottom: 1.25rem; color: var(--text); }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }

/* Bloco de seção interna de formulário */
.section-block {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1rem 0.25rem;
    margin-top: 0.5rem;
    background: #fafff8;
}

/* ── Tag Cloud (Apelidos de Cliente) ─────────────────────── */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.4rem;
}
.tag-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--verde-pale, #e6f4ea);
    color: var(--verde-escuro, #1b5e20);
    border: 1px solid var(--verde-medio, #4caf50);
    border-radius: 999px;
    padding: 0.15rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 500;
}
.tag-item .tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0;
    opacity: 0.6;
}
.tag-item .tag-remove:hover { opacity: 1; }
.tag-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}
.tag-input-row input { flex: 1; }

/* ===========================
   Sidebar — accordion + mini
   =========================== */

/* Variável de largura mini */
:root { --sidebar-mini-w: 56px; }

/* Transições suaves */
.sidebar      { transition: width 0.25s ease; }
.main-wrapper { transition: margin-left 0.25s ease; }

/* ── Brand (flex para acomodar botão recolher) ── */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1.1rem 0.75rem 1rem 1.25rem;
}
.brand-full        { flex: 1; min-width: 0; overflow: hidden; }
.brand-full strong { font-size: 1rem; font-weight: 700; display: block; white-space: nowrap; }
.brand-full span   { font-size: 0.72rem; color: rgba(255,255,255,0.5); white-space: nowrap; }

/* ── Botão recolher sidebar ── */
.sidebar-mini-btn {
    flex-shrink: 0;
    width: 28px; height: 28px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.sidebar-mini-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.sidebar-mini-btn svg   { transition: transform 0.25s ease; flex-shrink: 0; }

/* Esconde em mobile (hamburger já cobre) */
@media (max-width: 768px) { .sidebar-mini-btn { display: none; } }

/* ── Item solo (Dashboard / Minhas Visitas) ── */
.nav-solo a {
    display: flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    color: rgba(255,255,255,0.75);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    gap: 0.5rem;
}
.nav-solo a:hover,
.nav-solo a.active {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    text-decoration: none;
}
.nav-item-abbr { display: none; font-size: 0.7rem; font-weight: 700; }
.nav-item-icon { display: none; flex-shrink: 0; }

/* ── Grupos accordion ── */
.nav-group-btn {
    width: 100%;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.25rem;
    color: rgba(255,255,255,0.5);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
}
.nav-group-btn:hover {
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.8);
}
.nav-group.open .nav-group-btn {
    color: rgba(255,255,255,0.85);
}
.grp-label  { flex: 1; }
.grp-abbr   { display: none; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em; }
.grp-icon   { display: none; flex-shrink: 0; }

.nav-chevron {
    flex-shrink: 0;
    opacity: 0.55;
    transition: transform 0.2s ease;
}
.nav-group.open .nav-chevron { transform: rotate(180deg); opacity: 0.8; }

/* Items dentro do grupo — altura animada */
.nav-group-items {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.nav-group.open .nav-group-items {
    max-height: 240px; /* cobre até 6 itens */
}

/* Links dentro do grupo: recuo visual */
.nav-group-items li a {
    display: flex;
    align-items: center;
    padding: 0.55rem 1.25rem 0.55rem 1.6rem;
    color: rgba(255,255,255,0.7);
    font-size: 0.855rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 2px solid transparent;
}
.nav-group-items li a:hover {
    background: rgba(255,255,255,0.07);
    color: var(--white);
    text-decoration: none;
}
.nav-group-items li a.active {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border-left-color: var(--verde-claro);
}

/* ── Footer — ajustes para sidebar mini ── */
.sidebar-footer .footer-role  { display: block; margin-top: 0.1rem; }
.sidebar-logout-btn {
    background: none; border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer; font-size: 0.8rem;
    padding: 0; margin-top: 0.3rem;
}
.sidebar-logout-btn:hover { color: rgba(255,255,255,0.9); }

/* ===========================
   Estado sidebar-mini
   =========================== */
body.sidebar-mini .sidebar      { width: var(--sidebar-mini-w); }
body.sidebar-mini .main-wrapper { margin-left: var(--sidebar-mini-w); }

/* Seta aponta para direita no estado mini */
body.sidebar-mini .sidebar-mini-btn svg { transform: rotate(180deg); }

/* Brand: oculta texto, centraliza botão */
body.sidebar-mini .sidebar-brand  { padding: 0.9rem 0; justify-content: center; }
body.sidebar-mini .brand-full      { display: none; }

/* Items solo: mostra ícone, centraliza */
body.sidebar-mini .nav-solo a          { padding: 0.65rem 0; justify-content: center; }
body.sidebar-mini .nav-item-label      { display: none; }
body.sidebar-mini .nav-item-abbr       { display: none; }
body.sidebar-mini .nav-item-icon       { display: block; }

/* Grupos: mostra ícone, oculta texto e seta, centraliza */
body.sidebar-mini .nav-group-btn       { padding: 0.65rem 0; justify-content: center; }
body.sidebar-mini .grp-label           { display: none; }
body.sidebar-mini .nav-chevron         { display: none; }
body.sidebar-mini .grp-abbr            { display: none; }
body.sidebar-mini .grp-icon            { display: block; }

/* Fecha todos os sub-itens no modo mini */
body.sidebar-mini .nav-group-items     { max-height: 0 !important; }

/* Footer: oculta nome/perfil, centraliza botão */
body.sidebar-mini .sidebar-footer      { padding: 0.75rem 0; text-align: center; }
body.sidebar-mini .sidebar-footer strong,
body.sidebar-mini .sidebar-footer .footer-role { display: none; }
body.sidebar-mini .sidebar-footer form { margin: 0; }
