/* ============================================================
   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; }

.page-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.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: .95rem;
    font-weight: 600;
    color: var(--text);
}

.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.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;
}

.btn:hover { text-decoration: none; filter: brightness(.92); }
.btn:active { transform: scale(.98); }
.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; }

.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; }

/* ── 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; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-overlay {
        display: block !important;
    }

    .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%; }
    thead th:nth-child(n+4), tbody td:nth-child(n+4) { display: none; }
}

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

/* ── 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); }
