/* ============================================================
   AlcatechFinanças — CSS Principal
   ============================================================ */

/* ── Variáveis e Reset ── */
:root {
    --primary:        #2563eb;
    --primary-dark:   #1d4ed8;
    --primary-light:  #dbeafe;
    --success:        #16a34a;
    --success-light:  #dcfce7;
    --danger:         #dc2626;
    --danger-light:   #fee2e2;
    --warning:        #d97706;
    --warning-light:  #fef3c7;
    --info:           #0891b2;
    --info-light:     #cffafe;

    --bg:             #f1f5f9;
    --surface:        #ffffff;
    --surface-2:      #f8fafc;
    --border:         #e2e8f0;
    --text:           #1e293b;
    --text-muted:     #64748b;
    --text-light:     #94a3b8;

    --sidebar-bg:     #1e293b;
    --sidebar-text:   #94a3b8;
    --sidebar-hover:  #334155;
    --sidebar-active: #2563eb;
    --sidebar-w:      260px;

    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  16px;
    --radius-xl:  24px;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,.10);
    --shadow-lg:  0 8px 24px rgba(0,0,0,.12);

    --font:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 200ms ease;
}

[data-theme="dark"] {
    --bg:         #0f172a;
    --surface:    #1e293b;
    --surface-2:  #334155;
    --border:     #334155;
    --text:       #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --sidebar-bg: #0f172a;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo span { color: var(--primary); }

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.nav-section-title {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-light);
    padding: 16px 20px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-size: .875rem;
    font-weight: 500;
    border-radius: 0;
    transition: background var(--transition), color var(--transition);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #ffffff;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(37,99,235,.2);
    color: #60a5fa;
    border-right: 3px solid var(--primary);
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .875rem;
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name  { font-size: .8rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: .7rem; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.session-timer {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--border);
    transition: color .3s, background .3s;
    user-select: none;
}
.session-timer--warn {
    color: #ef4444;
    background: #fef2f2;
    animation: session-pulse 1.2s ease-in-out infinite;
}
[data-theme="dark"] .session-timer--warn { background: #450a0a; }
@keyframes session-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .5; }
}
@media (max-width: 480px) {
    .session-timer { display: none; }
}

.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.015em;
    position: relative;
    padding-left: 14px;
}

.page-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 65%;
    width: 3px;
    background: linear-gradient(180deg, var(--primary) 0%, #7c3aed 100%);
    border-radius: 2px;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    border-radius: var(--radius-sm);
}

.hamburger:hover { background: var(--bg); }

.page-body {
    padding: 24px;
    flex: 1;
}

/* ── Cards ── */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
}

.card-body { padding: 20px; }

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: box-shadow var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card-clicavel { cursor: pointer; }
.stat-card-clicavel:hover { transform: translateY(-1px); transition: transform var(--transition), box-shadow var(--transition); }
.stat-card.receitas { border-left-color: var(--success); }
.stat-card.despesas { border-left-color: var(--danger); }
.stat-card.saldo     { border-left-color: var(--primary); }
.stat-card.cartoes   { border-left-color: var(--warning); }

.stat-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }

.stat-meta {
    font-size: .78rem;
    color: var(--text-muted);
}

/* ── Dashboard Grid ── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.dashboard-grid.three {
    grid-template-columns: 1fr 1fr 1fr;
}

.chart-container {
    position: relative;
    height: 280px;
}

/* ── Botões ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: .01em;
}

.btn:hover { text-decoration: none; filter: brightness(.93); transform: translateY(-1px); }
.btn:active { transform: scale(.97) translateY(0); filter: brightness(.88); }

.btn-primary:hover { box-shadow: 0 4px 14px rgba(37,99,235,.35); }
.btn-success:hover  { box-shadow: 0 4px 14px rgba(22,163,74,.35); }
.btn-danger:hover   { box-shadow: 0 4px 14px rgba(220,38,38,.35); }
.btn-warning:hover  { box-shadow: 0 4px 14px rgba(217,119,6,.35); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-success   { background: var(--success);  color: #fff; }
.btn-danger    { background: var(--danger);   color: #fff; }
.btn-warning   { background: var(--warning);  color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-outline   { background: transparent; color: var(--primary); border: 1px solid var(--primary); }

/* ── Formulários ── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

label {
    display: block;
    font-size: .83rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    font-family: var(--font);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-control.is-invalid { border-color: var(--danger); }
.form-control::placeholder { color: var(--text-light); }

select.form-control {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.invalid-feedback {
    font-size: .78rem;
    color: var(--danger);
    margin-top: 4px;
}

/* ── Tabelas ── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

thead th {
    background: var(--surface-2);
    padding: 12px 16px;
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

.td-actions { display: flex; gap: 6px; align-items: center; }

/* ── Ordenação de tabelas ── */
thead th.sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 28px;
    position: relative;
    transition: color .15s, background .15s;
}

thead th.sortable:hover {
    color: var(--text);
    background: var(--border);
}

thead th.sortable::after {
    content: '↕';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    opacity: .25;
    font-size: .8em;
}

thead th.sort-asc::after  { content: '↑'; opacity: .85; color: var(--primary); }
thead th.sort-desc::after { content: '↓'; opacity: .85; color: var(--primary); }
thead th.sort-asc,
thead th.sort-desc { color: var(--primary); }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success  { background: var(--success-light);  color: var(--success); }
.badge-danger   { background: var(--danger-light);   color: var(--danger); }
.badge-warning  { background: var(--warning-light);  color: var(--warning); }
.badge-info     { background: var(--info-light);     color: var(--info); }
.badge-primary  { background: var(--primary-light);  color: var(--primary); }
.badge-secondary{ background: var(--surface-2);       color: var(--text-muted); border: 1px solid var(--border); }

/* ── Alertas / Flash ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid transparent;
}

.alert-success { background: var(--success-light); color: #14532d; border-color: #bbf7d0; }
.alert-error   { background: var(--danger-light);  color: #7f1d1d; border-color: #fecaca; }
.alert-info    { background: var(--info-light);    color: #0c4a6e; border-color: #a5f3fc; }
.alert-warning { background: var(--warning-light); color: #78350f; border-color: #fde68a; }
.alert-close   { margin-left: auto; cursor: pointer; opacity: .6; background: none; border: none; font-size: 1.1rem; }
.alert-close:hover { opacity: 1; }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
    transform: scale(.95);
    transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.3rem; }
.modal-body   { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Utilitários ── */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger)  !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-600       { font-weight: 600; }
.fw-700       { font-weight: 700; }
.fs-sm        { font-size: .8rem; }
.mt-0  { margin-top: 0; }
.mt-1  { margin-top: 8px; }
.mt-2  { margin-top: 16px; }
.mt-3  { margin-top: 24px; }
.mb-0  { margin-bottom: 0; }
.mb-1  { margin-bottom: 8px; }
.mb-2  { margin-bottom: 16px; }
.mb-3  { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-100 { width: 100%; }

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p   { margin-top: 8px; font-size: .9rem; }

/* ── Progress Bar ── */
.progress {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 4px;
    transition: width .5s ease;
}

.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* ── Color Dot ── */
.color-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* ── Cartão Visual ── */
.card-visual {
    border-radius: var(--radius-md);
    padding: 20px;
    color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 110px;
}

.card-visual::after {
    content: '';
    position: absolute;
    right: -20px; top: -20px;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: rgba(255,255,255,.1);
}

/* ── Paginação ── */
.pagination { display: flex; gap: 4px; margin-top: 16px; }
.page-btn {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: .83rem;
    text-decoration: none;
}
.page-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); text-decoration: none; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Responsividade ── */
@media (max-width: 1024px) {
    .dashboard-grid.three { grid-template-columns: 1fr 1fr; }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content { margin-left: 0; }

    .hamburger { display: flex; }

    .dashboard-grid, .dashboard-grid.three { grid-template-columns: 1fr; }

    .stats-grid { grid-template-columns: 1fr 1fr; }

    .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }

    .page-body { padding: 16px; }

    .topbar { padding: 0 16px; }

    .stat-value { font-size: 1.3rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .modal { max-width: 100%; }
}

/* ── Mobile: tabelas viram cards ── */
@media (max-width: 1024px) {

    /* Reset estrutura da tabela */
    .table-wrapper table,
    .table-wrapper tbody { display: block; width: 100%; }
    .table-wrapper thead { display: none; }

    /* Tfoot: só mostra o total */
    .table-wrapper tfoot { display: block; }
    .table-wrapper tfoot tr { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 8px 4px; }
    .table-wrapper tfoot td { display: none; padding: 0; border: none; width: auto; }
    .table-wrapper tfoot td:last-child,
    .table-wrapper tfoot td:nth-last-child(2) { display: block; }

    /* Cada linha = card */
    .table-wrapper tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        padding: 12px 14px;
        margin-bottom: 10px;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background: var(--surface);
        box-shadow: var(--shadow-sm);
        gap: 2px 8px;
    }

    /* Esconde todos os td por padrão */
    .table-wrapper tbody td { display: none; border: none; padding: 0; }

    /* Descrição — linha 1, coluna 1 */
    .table-wrapper tbody td:nth-child(2) {
        display: block;
        grid-row: 1; grid-column: 1;
        font-size: .9rem;
        padding-bottom: 4px;
    }

    /* Valor — linha 1, coluna 2 (sempre penúltimo) */
    .table-wrapper tbody td:nth-last-child(2) {
        display: flex;
        align-items: flex-start;
        justify-content: flex-end;
        grid-row: 1; grid-column: 2;
        font-size: 1rem;
        white-space: nowrap;
    }

    /* Tipo badge — linha 2, coluna 1 */
    .table-wrapper tbody td:nth-child(3) {
        display: flex;
        align-items: center;
        grid-row: 2; grid-column: 1;
        font-size: .78rem;
        gap: 6px;
    }

    /* Status (pago/pendente) nas despesas — linha 2, coluna 2 */
    .table-despesas tbody td:nth-child(6) {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        grid-row: 2; grid-column: 2;
    }

    /* Ações — linha 3, largura total */
    .table-wrapper tbody td:last-child {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
        grid-row: 3; grid-column: 1 / -1;
        border-top: 1px solid var(--border);
        padding-top: 10px;
        margin-top: 6px;
    }

    /* Botões de ação maiores (toque fácil) */
    .td-actions { display: flex; gap: 8px; }
    .td-actions .btn { min-height: 38px; min-width: 38px; padding: 6px 10px; }

    /* Botão + Nova no topo em telas pequenas */
    .page-header-actions { flex-wrap: wrap; gap: 8px; }
    .page-header-actions .btn { width: 100%; justify-content: center; }
}

/* ── Sidebar Overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
}

/* ── PDF / Impressão ── */
#pdf-content .card         { page-break-inside: avoid; break-inside: avoid; }
#pdf-content .stats-grid   { page-break-inside: avoid; break-inside: avoid; }
#pdf-content .dashboard-grid { page-break-inside: avoid; break-inside: avoid; }
#pdf-content .table-wrapper  { page-break-inside: avoid; break-inside: avoid; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ── Checkbox e Radio customizados ── */
input[type="checkbox"],
input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    flex-shrink: 0;
    vertical-align: middle;
    border-radius: 4px;
}

input[type="radio"] { border-radius: 50%; }

input[type="checkbox"]:hover,
input[type="radio"]:hover { border-color: var(--primary); }

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 6px;
    height: 10px;
    border: 2px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    inset: 3px;
    background: #fff;
    border-radius: 50%;
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37,99,235,.18);
}

input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── SweetAlert2 — Tema ── */
.swal2-popup {
    font-family: var(--font) !important;
    border-radius: var(--radius-lg) !important;
    border: 1px solid var(--border) !important;
    background: var(--surface) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 2rem !important;
}

.swal2-title {
    color: var(--text) !important;
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    letter-spacing: -.01em !important;
}

.swal2-html-container {
    color: var(--text-muted) !important;
    font-size: .9rem !important;
    line-height: 1.6 !important;
}

.swal2-icon { margin-bottom: 1rem !important; }
.swal2-icon.swal2-warning { border-color: var(--warning) !important; color: var(--warning) !important; }
.swal2-icon.swal2-error   { border-color: var(--danger)  !important; color: var(--danger)  !important; }
.swal2-icon.swal2-success { border-color: var(--success) !important; color: var(--success) !important; }
.swal2-icon.swal2-info    { border-color: var(--info)    !important; color: var(--info)    !important; }
.swal2-icon.swal2-success .swal2-success-ring { border-color: rgba(22,163,74,.3) !important; }

.swal2-actions { gap: 10px !important; margin-top: 1.5rem !important; }

.swal2-confirm {
    background: var(--primary) !important;
    border-radius: var(--radius-sm) !important;
    font-family: var(--font) !important;
    font-weight: 500 !important;
    font-size: .875rem !important;
    padding: 10px 22px !important;
    letter-spacing: .01em !important;
    box-shadow: none !important;
    transition: all 200ms ease !important;
}
.swal2-confirm:hover { box-shadow: 0 4px 14px rgba(37,99,235,.35) !important; filter: brightness(.93) !important; }

.swal2-cancel {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    font-family: var(--font) !important;
    font-weight: 500 !important;
    font-size: .875rem !important;
    padding: 10px 22px !important;
    letter-spacing: .01em !important;
    box-shadow: none !important;
}
.swal2-cancel:hover { filter: brightness(.95) !important; }

/* Toast */
.swal2-toast {
    border-radius: var(--radius-md) !important;
    font-family: var(--font) !important;
    box-shadow: var(--shadow-md) !important;
    border: 1px solid var(--border) !important;
    background: var(--surface) !important;
    padding: 12px 16px !important;
}

.swal2-toast .swal2-title {
    font-size: .875rem !important;
    font-weight: 600 !important;
    color: var(--text) !important;
    letter-spacing: normal !important;
}

.swal2-timer-progress-bar { background: var(--primary) !important; }

/* Dark mode overrides para Swal */
[data-theme="dark"] .swal2-popup { background: var(--surface) !important; border-color: var(--border) !important; }
[data-theme="dark"] .swal2-toast  { background: var(--surface) !important; border-color: var(--border) !important; }
[data-theme="dark"] .swal2-cancel { background: var(--surface-2) !important; border-color: var(--border) !important; color: var(--text) !important; }
[data-theme="dark"] input[type="checkbox"],
[data-theme="dark"] input[type="radio"] { background: var(--surface-2); border-color: var(--border); }

/* ── Chat IA Widget ── */
#chat-fab {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 24px;
    z-index: 1000;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: background var(--transition), transform var(--transition);
}
#chat-fab:hover { background: var(--primary-dark); transform: scale(1.08); }
#chat-fab.chat-fab--open { background: var(--primary-dark); }

.chat-modal {
    position: fixed;
    bottom: 86px;
    right: 24px;
    z-index: 999;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.97);
    pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
}
.chat-modal--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--primary);
    color: #fff;
    flex-shrink: 0;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: .9rem;
}
#chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    opacity: .8;
    transition: opacity var(--transition);
}
#chat-close:hover { opacity: 1; }

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.chat-message {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: .875rem;
    line-height: 1.45;
    word-break: break-word;
}
.chat-message--user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-message--bot {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-message--bot p { margin: 0 0 8px; }
.chat-message--bot p:last-of-type { margin-bottom: 0; }

.chat-confirm-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.chat-btn-confirm, .chat-btn-cancel {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 600;
    transition: opacity var(--transition);
}
.chat-btn-confirm { background: var(--primary); color: #fff; }
.chat-btn-confirm:hover { background: var(--primary-dark); }
.chat-btn-cancel  { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.chat-btn-cancel:hover { background: var(--border); }

/* Botões de etapa (forma de pagamento, cartão, sim/não) */
.chat-step-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.chat-step-btn {
    padding: 5px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-size: .78rem;
    font-weight: 600;
    transition: background var(--transition), color var(--transition), opacity var(--transition);
    white-space: nowrap;
}
.chat-step-btn:hover:not(:disabled) { background: var(--primary); color: #fff; }
.chat-step-btn--selected { background: var(--primary); color: #fff; }
.chat-step-btn--primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.chat-step-btn--primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.chat-step-btn--danger   { border-color: var(--danger, #e74c3c); color: var(--danger, #e74c3c); }
.chat-step-btn--danger:hover:not(:disabled)  { background: var(--danger, #e74c3c); color: #fff; }
.chat-step-btn:disabled  { opacity: .45; cursor: not-allowed; }

/* Textarea de observação */
.chat-obs-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: .8rem;
    font-family: inherit;
    resize: none;
    margin-top: 8px;
    outline: none;
    box-sizing: border-box;
    transition: border-color var(--transition);
}
.chat-obs-input:focus { border-color: var(--primary); }
.chat-obs-input:disabled { opacity: .5; }

/* Resumo final antes da confirmação */
.chat-resumo {
    font-size: .8rem;
    font-family: inherit;
    white-space: pre-wrap;
    margin: 0 0 10px;
    line-height: 1.65;
    color: var(--text);
}

/* Typing indicator */
.chat-typing {
    display: flex !important;
    gap: 5px;
    align-items: center;
    padding: 12px 16px !important;
}
.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: chatBounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: .5; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface);
}
#chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text);
    font-size: .875rem;
    outline: none;
    transition: border-color var(--transition);
}
#chat-input:focus { border-color: var(--primary); }
#chat-send {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}
#chat-send:hover { background: var(--primary-dark); }
#chat-send:disabled, #chat-input:disabled { opacity: .6; cursor: not-allowed; }

@media (max-width: 1024px) {
    #chat-fab {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
    .chat-modal {
        bottom: calc(78px + env(safe-area-inset-bottom, 0px));
        right: 8px;
        left: 8px;
        width: auto;
        height: calc(100vh - 140px - env(safe-area-inset-bottom, 0px));
        max-height: calc(100vh - 140px);
    }
}

/* ── Filtros mobile ── */
@media (max-width: 1024px) {
    .card .form-row {
        grid-template-columns: 1fr 1fr !important;
    }
    .card .form-row > :last-child {
        grid-column: 1 / -1;
    }
}

/* ── Dropdown de ações mobile ── */
.mob-actions-wrap {
    position: relative;
}
.mob-actions-trigger {
    min-height: 36px;
    min-width: 36px;
    padding: 6px;
}
.mob-actions-menu {
    display: none;
    position: absolute;
    right: 0;
    bottom: calc(100% + 4px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    min-width: 150px;
    overflow: hidden;
}
.mob-actions-menu.open { display: flex; flex-direction: column; }
.mob-actions-menu .btn,
.mob-actions-menu form { width: 100%; }
.mob-actions-menu .btn {
    border-radius: 0;
    justify-content: flex-start;
    padding: 10px 14px;
    font-size: .875rem;
    border: none;
    border-bottom: 1px solid var(--border);
}
.mob-actions-menu .btn:last-child,
.mob-actions-menu form:last-child .btn { border-bottom: none; }
.mob-actions-menu form .btn { border-radius: 0; }

/* ── Relatórios mobile ── */
@media (max-width: 1024px) {

    /* Linha principal dos filtros: empilha tudo verticalmente */
    #form-relatorio .card-body > .d-flex:first-child {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    /* Botões Período (Anual/Mensal/Intervalo) em linha completa */
    #form-relatorio .card-body > .d-flex:first-child > .d-flex {
        flex-shrink: unset;
        flex-wrap: wrap;
    }

    /* Seletores de mês/ano ocupam espaço disponível */
    #filtro-anual,
    #filtro-mensal,
    #filtro-periodo {
        flex-wrap: wrap;
        gap: 6px;
    }
    #filtro-anual select,
    #filtro-mensal select,
    #filtro-periodo select {
        flex: 1 1 120px;
        min-width: 0;
        width: 100% !important;
    }

    /* Esconde o spacer flex */
    #form-relatorio [style*="flex:1;min-width:0"] { display: none !important; }

    /* Botões PDF e Aplicar em linha, cada um metade */
    #btn-pdf,
    #form-relatorio button[type="submit"] {
        flex: 1 1 0;
    }

    /* Agrupa botões PDF+Aplicar na mesma linha */
    #btn-pdf { order: 1; }
    #form-relatorio button[type="submit"] { order: 2; }

    /* Segunda linha (Tipos + Cartão): empilha */
    #form-relatorio .d-flex.flex-wrap.gap-2 {
        flex-direction: column;
        gap: 10px !important;
    }

    /* Gráfico comparativo menor no mobile */
    .chart-container[style*="height:300px"] {
        height: 200px !important;
    }

    /* Esconde coluna Economia na tabela mensal */
    .rel-col-economia { display: none; }

    /* Tabela de relatório: linhas com mais padding */
    .table-relatorio td,
    .table-relatorio th {
        padding: 10px 8px;
        font-size: .82rem;
    }

    /* Modal de itens: ocupa toda a tela */
    #modal-itens-card .modal {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    #modal-itens-card.open {
        align-items: flex-end;
    }
}

