/* ============================================================
   Design system do Financeiro W&A -- CSS puro (sem build step,
   compativel com hospedagem compartilhada). Tailwind (via CDN)
   e usado so pra utilitarios pontuais de layout (grid/flex/spacing).
   Paleta propria deste sistema (nao reaproveita o indigo do
   hotspot-mikrotik) -- teal/petroleo transmite solidez financeira
   sem cair no verde-dinheiro cliche.
   ============================================================ */

:root {
    --color-primary: #0d9488;
    --color-primary-dark: #0f766e;
    --color-primary-soft: #ecfdf9;
    --color-bg: #f6f8f8;
    --color-surface: #ffffff;
    --color-border: #e2e8e7;
    --color-text: #10201d;
    --color-text-muted: #5b6b68;
    --color-text-faint: #93a29f;
    --color-success: #16a34a;
    --color-success-soft: #f0fdf4;
    --color-warning: #d97706;
    --color-warning-soft: #fffbeb;
    --color-danger: #dc2626;
    --color-danger-soft: #fef2f2;
    --color-neutral-soft: #eef2f1;
    --sidebar-width: 252px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-card: 0 1px 2px rgba(9, 30, 26, .04), 0 1px 3px rgba(9, 30, 26, .06);
    --shadow-pop: 0 4px 14px rgba(9, 30, 26, .10), 0 2px 4px rgba(9, 30, 26, .06);
    --font-display: 'Lexend', 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    font-variant-numeric: tabular-nums;
}

/* ===== Shell / layout ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width); flex-shrink: 0; background: #0a1917;
    color: #cbd8d5; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0;
    z-index: 40; transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px; padding: 22px 20px 18px; color: #fff;
    font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: -.01em;
    border-bottom: 1px solid #ffffff14;
}
.sidebar-brand .brand-mark {
    width: 30px; height: 30px; border-radius: 9px; background: var(--color-primary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    box-shadow: 0 0 0 3px #0d948833;
}
.sidebar-brand .brand-mark svg { width: 16px; height: 16px; color: #fff; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.sidebar-section-label {
    font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
    color: #62726f; padding: 14px 12px 6px;
}
.sidebar-link {
    display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 500; color: #b9c7c4; text-decoration: none; margin-bottom: 2px;
    transition: background .15s ease, color .15s ease;
}
.sidebar-link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.sidebar-link:hover { background: #ffffff0d; color: #fff; }
.sidebar-link.active { background: var(--color-primary); color: #fff; }
.sidebar-link.active svg { opacity: 1; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid #ffffff14; }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--color-primary);
    display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-name { font-size: 13px; color: #e7efed; font-weight: 600; line-height: 1.2; }
.sidebar-logout { font-size: 11.5px; color: #8ca19d; text-decoration: none; }
.sidebar-logout:hover { color: #fca5a5; }

.main { flex: 1; margin-left: var(--sidebar-width); min-width: 0; }

.topbar {
    position: sticky; top: 0; z-index: 30; background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; color: var(--color-text); }
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; color: var(--color-text); }

.content { padding: 28px; max-width: 1180px; }

.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .sidebar-toggle { display: inline-flex; }
    .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
    .content { padding: 20px; }
}

/* ===== Page header ===== */
.page-header { margin-bottom: 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title { font-family: var(--font-display); font-size: 23px; font-weight: 700; letter-spacing: -.02em; color: var(--color-text); margin: 0; }
.page-subtitle { font-size: 13.5px; color: var(--color-text-muted); margin: 4px 0 0; }

/* ===== Card ===== */
.card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
    box-shadow: var(--shadow-card); padding: 22px;
}
.card + .card { margin-top: 20px; }
.card-title { font-size: 14.5px; font-weight: 700; color: var(--color-text); margin: 0 0 4px; }
.card-subtitle { font-size: 12.5px; color: var(--color-text-muted); margin: 0 0 16px; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; text-decoration: none; transition: all .15s ease; line-height: 1.2;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: 0 1px 2px rgba(13,148,136,.35); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-neutral-soft); }
.btn-danger-ghost { background: transparent; color: var(--color-danger); padding: 4px 8px; font-size: 12.5px; }
.btn-danger-ghost:hover { background: var(--color-danger-soft); }
.btn-ghost { background: transparent; color: var(--color-text-muted); padding: 4px 8px; font-size: 12.5px; }
.btn-ghost:hover { background: var(--color-neutral-soft); color: var(--color-text); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ===== Badges ===== */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 700; text-transform: capitalize; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-neutral { background: var(--color-neutral-soft); color: var(--color-text-muted); }
.badge-primary { background: var(--color-primary-soft); color: var(--color-primary-dark); }

/* ===== Barra de progresso (teto MEI, orcamento por categoria) ===== */
.progress-wrap { display: flex; align-items: center; gap: 10px; }
.progress-label { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; }
.progress-track { flex: 1; height: 8px; border-radius: 999px; background: var(--color-neutral-soft); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.progress-good { background: var(--color-success); }
.progress-warning { background: var(--color-warning); }
.progress-critical { background: var(--color-danger); }
.progress-percent { font-size: 12px; font-weight: 700; color: var(--color-text); white-space: nowrap; min-width: 42px; text-align: right; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th {
    text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--color-text-faint); padding: 0 14px 10px; border-bottom: 1px solid var(--color-border);
}
.data-table tbody td { padding: 13px 14px; border-bottom: 1px solid #eef1f0; color: var(--color-text); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background .1s ease; }
.data-table tbody tr:hover { background: #fafcfb; }
.data-table .mono { font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.data-table .muted { color: var(--color-text-muted); }
.data-table .valor-positivo { color: var(--color-success); font-weight: 700; }
.data-table .valor-negativo { color: var(--color-danger); font-weight: 700; }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--color-text-muted); }
.empty-state-icon { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--color-text-faint); }
.empty-state-text { font-size: 13.5px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--color-text); margin-bottom: 6px; }
.form-hint { font-size: 11.5px; color: var(--color-text-faint); margin-top: 5px; }
.form-input, select.form-input, textarea.form-input {
    width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
    background: var(--color-surface); color: var(--color-text); font-size: 13.5px; font-family: inherit;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--color-text); }
.form-check input { width: 16px; height: 16px; accent-color: var(--color-primary); }
.input-money-prefix { position: relative; }
.input-money-prefix::before {
    content: 'R$'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    font-size: 13px; color: var(--color-text-faint); font-weight: 600; pointer-events: none;
}
.input-money-prefix input { padding-left: 34px; text-align: right; }

@media (max-width: 700px) {
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ===== Alerts ===== */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-danger { background: var(--color-danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--color-primary-soft); color: var(--color-primary-dark); border-color: #99e6da; }
.alert-warning { background: var(--color-warning-soft); color: #92400e; border-color: #fde68a; }

/* ===== Stat grid ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; }
.stat-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--stat-accent, var(--color-primary)); }
.stat-card.stat-good { --stat-accent: var(--color-success); }
.stat-card.stat-warning { --stat-accent: var(--color-warning); }
.stat-card.stat-danger { --stat-accent: var(--color-danger); }
.stat-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-faint); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.stat-label svg { width: 14px; height: 14px; }
.stat-value { font-family: var(--font-display); font-size: 24px; font-weight: 700; color: var(--color-text); letter-spacing: -.02em; }
.stat-hint { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; }

/* ===== Links ===== */
a.link { color: var(--color-primary-dark); text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }

/* ===== Login page ===== */
.auth-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(circle at 15% 0%, #0d948822, transparent 50%),
        radial-gradient(circle at 100% 100%, #0d94881a, transparent 45%),
        var(--color-bg);
    padding: 20px;
}
.auth-card {
    width: 100%; max-width: 380px; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 18px; padding: 36px 32px; box-shadow: var(--shadow-pop);
}
.auth-logo {
    width: 46px; height: 46px; border-radius: 13px; background: var(--color-primary); color: #fff;
    display: flex; align-items: center; justify-content: center; margin: 0 auto 18px; box-shadow: 0 0 0 5px #0d948822;
}
.auth-logo svg { width: 22px; height: 22px; }
.auth-title { font-family: var(--font-display); text-align: center; font-size: 19px; font-weight: 700; margin: 0 0 4px; }
.auth-subtitle { text-align: center; font-size: 13px; color: var(--color-text-muted); margin: 0 0 26px; }

/* ===== Modo escuro ===== */
:root[data-theme="dark"] {
    --color-bg: #0a1211;
    --color-surface: #101a18;
    --color-border: #223330;
    --color-text: #e6efed;
    --color-text-muted: #98aba7;
    --color-text-faint: #647c78;
    --color-neutral-soft: #182523;
    --color-success-soft: #052e1c;
    --color-warning-soft: #2e2205;
    --color-danger-soft: #2e0a0a;
    --color-primary-soft: #0c2624;
}
:root[data-theme="dark"] .sidebar { background: #050b0a; }
:root[data-theme="dark"] .data-table tbody tr:hover { background: #142320; }
:root[data-theme="dark"] .auth-shell { background: radial-gradient(circle at 15% 0%, #0d948822, transparent 50%), var(--color-bg); }

.theme-toggle {
    background: none; border: 1px solid var(--color-border); color: var(--color-text-muted); cursor: pointer;
    border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px;
}
.theme-toggle:hover { color: var(--color-text); }

/* ===== Toasts ===== */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--color-text); color: var(--color-surface); padding: 11px 18px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500; box-shadow: var(--shadow-pop); opacity: 0; transform: translateY(8px); transition: all .25s ease;
    max-width: 320px;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--color-success); color: #fff; }
.toast-error { background: var(--color-danger); color: #fff; }

/* ===== Modal de confirmação ===== */
.confirm-overlay {
    position: fixed; inset: 0; background: rgba(9,20,18,.5); z-index: 150; display: none;
    align-items: center; justify-content: center; backdrop-filter: blur(2px);
}
.confirm-overlay.open { display: flex; }
.confirm-box {
    background: var(--color-surface); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 340px;
    box-shadow: var(--shadow-pop); border: 1px solid var(--color-border);
}
.confirm-text { font-size: 13.5px; color: var(--color-text); margin-bottom: 18px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Chart wrapper ===== */
.chart-box { position: relative; height: 240px; }
.chart-box-sm { position: relative; height: 160px; }

/* ===== Rodapé de autoria ===== */
.app-footer { text-align: center; font-size: 11px; color: var(--color-text-faint); margin-top: 32px; padding: 16px 0; }
.app-footer-auth { position: fixed; bottom: 0; left: 0; right: 0; }

/* ===== Impressao (extrato/fatura/recibo com timbre) ===== */
@media print {
    .no-print, .sidebar, .topbar, .app-footer, #toast-container { display: none !important; }
    .main { margin-left: 0 !important; }
    .content { padding: 0 !important; max-width: none !important; }
    body { background: #fff !important; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
    .print-header {
        display: flex !important; align-items: center; justify-content: space-between; gap: 16px;
        border-bottom: 2px solid #10201d; padding-bottom: 12px; margin-bottom: 20px;
    }
    .print-footer {
        display: flex !important; align-items: center; justify-content: space-between; gap: 16px;
        border-top: 1px solid #ccc; padding-top: 10px; margin-top: 24px; font-size: 10.5px; color: #666;
    }
}
.print-header, .print-footer { display: none; }
