/* ═══════════════════════════════════════════════════════════════════════════
   Masterop Financeiro — Design System
   Dark / Light Mode com variáveis CSS
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Variáveis: Dark Mode (padrão) ─────────────────────────────────────── */
:root,
[data-theme="dark"] {
    --bg-body:       #0b1120;
    --bg-sidebar:    #0f172a;
    --bg-card:       #1e293b;
    --bg-card-hover: #263347;
    --bg-input:      #162032;
    --bg-modal:      #1e293b;
    --bg-table-head: #162032;
    --bg-table-row:  #1e293b;
    --bg-table-alt:  #192334;

    --text-primary:  #f1f5f9;
    --text-secondary:#94a3b8;
    --text-muted:    #64748b;
    --text-inverse:  #0f172a;

    --border-color:  #2d3f55;
    --border-input:  #334155;

    --accent:        #6366f1;
    --accent-hover:  #4f46e5;
    --accent-light:  rgba(99,102,241,0.15);

    --success:       #22c55e;
    --success-light: rgba(34,197,94,0.15);
    --danger:        #ef4444;
    --danger-light:  rgba(239,68,68,0.15);
    --warning:       #f59e0b;
    --warning-light: rgba(245,158,11,0.15);
    --info:          #38bdf8;
    --info-light:    rgba(56,189,248,0.15);

    --shadow-sm:     0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.5);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.6);

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --header-height: 60px;
    --radius:        10px;
    --radius-sm:     6px;
    --radius-lg:     16px;
}

/* ── Variáveis: Light Mode ──────────────────────────────────────────────── */
[data-theme="light"] {
    --bg-body:       #f0f4f8;
    --bg-sidebar:    #ffffff;
    --bg-card:       #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-input:      #f8fafc;
    --bg-modal:      #ffffff;
    --bg-table-head: #f1f5f9;
    --bg-table-row:  #ffffff;
    --bg-table-alt:  #f8fafc;

    --text-primary:  #0f172a;
    --text-secondary:#475569;
    --text-muted:    #94a3b8;
    --text-inverse:  #f1f5f9;

    --border-color:  #e2e8f0;
    --border-input:  #cbd5e1;

    --accent:        #4f46e5;
    --accent-hover:  #4338ca;
    --accent-light:  rgba(79,70,229,0.10);

    --success:       #16a34a;
    --success-light: rgba(22,163,74,0.10);
    --danger:        #dc2626;
    --danger-light:  rgba(220,38,38,0.10);
    --warning:       #d97706;
    --warning-light: rgba(217,119,6,0.10);
    --info:          #0284c7;
    --info-light:    rgba(2,132,199,0.10);

    --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:     0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg:     0 8px 32px rgba(0,0,0,0.12);
}

/* ── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

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

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 100;
    transition: width 0.25s ease, transform 0.25s ease, background 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

.sidebar-logo {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 12px 0 20px;
    border-bottom: 1px solid var(--border-color);
    gap: 10px;
    justify-content: space-between;
}

.sidebar-logo img {
    max-height: 36px;
    max-width: 140px;
    object-fit: contain;
}

.sidebar-logo .logo-text {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s, transform 0.25s;
}

.sidebar-collapse-btn svg {
    width: 18px;
    height: 18px;
}

.sidebar-collapse-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 12px 8px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    transition: all 0.2s ease;
    margin-bottom: 2px;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

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

.nav-item:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

/* ── Conteúdo Principal ─────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
    min-width: 0;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
    height: var(--header-height);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    transition: background 0.3s ease;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
}

.menu-toggle svg {
    width: 22px;
    height: 22px;
}

.menu-toggle:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* ── Toggle Dark/Light ──────────────────────────────────────────────────── */
.theme-toggle {
    width: 44px; height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    border: none;
    transition: background 0.3s;
}

.theme-toggle::after {
    content: '';
    position: absolute;
    top: 3px; left: 3px;
    width: 18px; height: 18px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.3s ease;
}

[data-theme="light"] .theme-toggle::after {
    transform: translateX(20px);
}

/* ── Page Content ───────────────────────────────────────────────────────── */
.page-content {
    padding: 24px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    transition: background 0.3s ease, border-color 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.card-hover:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    transition: all 0.2s ease;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.kpi-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.kpi-icon svg { width: 22px; height: 22px; }

.kpi-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Botões ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; }

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.4); }

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--bg-card-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

/* ── Badges / Status ────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    gap: 4px;
}
.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-muted    { background: var(--bg-table-head);  color: var(--text-muted); }
.badge-accent   { background: var(--accent-light);   color: var(--accent);  }

/* ── Tabelas ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: var(--bg-table-head);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

tbody tr {
    background: var(--bg-table-row);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}
tbody tr:nth-child(even) { background: var(--bg-table-alt); }
tbody tr:hover { background: var(--bg-card-hover); }

td {
    padding: 10px 14px;
    font-size: 13.5px;
    color: var(--text-primary);
    vertical-align: middle;
}

/* ── Formulários ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 14px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.input-error {
    border-color: var(--danger) !important;
}
.error-text {
    font-size: 11.5px;
    color: var(--danger);
    margin-top: 4px;
}

.form-row { display: grid; gap: 16px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Modais ──────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
}

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

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
}
.modal-close:hover { color: var(--danger); }

.modal-body { padding: 22px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--border-color);
}

/* ── Alertas e Notificações ─────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger   { background: var(--danger-light);  color: var(--danger);  }
.alert-warning  { background: var(--warning-light); color: var(--warning); }
.alert-info     { background: var(--info-light);    color: var(--info);    }

/* ── Saldo Financeiro ───────────────────────────────────────────────────── */
.saldo-positivo { color: var(--success); font-weight: 700; }
.saldo-negativo { color: var(--danger);  font-weight: 700; }
.saldo-zero     { color: var(--text-muted); font-weight: 600; }

.valor-debito   { color: var(--danger);  font-weight: 600; }
.valor-credito  { color: var(--success); font-weight: 600; }

/* ── Avatar do Usuário ──────────────────────────────────────────────────── */
.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nav-user-meta {
    overflow: hidden;
    min-width: 0;
}

.nav-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.agencia-logo-thumb {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    background: var(--bg-tertiary, var(--bg-input));
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.agencia-logo-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.profile-avatar-lg {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}

.profile-avatar-lg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

.upload-preview {
    margin-bottom: 10px;
    padding: 12px;
    background: var(--bg-tertiary, var(--bg-input));
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Sidebar recolhida (desktop) ─────────────────────────────────────────── */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-section-title,
body.sidebar-collapsed .nav-user-meta,
body.sidebar-collapsed .sidebar-logo .logo-text,
body.sidebar-collapsed .sidebar-logo img {
    display: none;
}

body.sidebar-collapsed .sidebar-logo {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .sidebar-collapse-btn {
    transform: rotate(180deg);
}

body.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 10px;
}

body.sidebar-collapsed .sidebar-footer .nav-item {
    justify-content: center;
}

/* ── Animações ───────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsivo ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: flex; }
    .sidebar-collapse-btn { display: none; }
    body.sidebar-collapsed .sidebar { width: var(--sidebar-width); }
    body.sidebar-collapsed .main-content { margin-left: 0; }
    body.sidebar-collapsed .nav-label,
    body.sidebar-collapsed .nav-section-title,
    body.sidebar-collapsed .nav-user-meta,
    body.sidebar-collapsed .sidebar-logo .logo-text,
    body.sidebar-collapsed .sidebar-logo img {
        display: initial;
    }
    body.sidebar-collapsed .sidebar-logo img { display: block; }
    body.sidebar-collapsed .nav-user-meta { display: block; }
    body.sidebar-collapsed .nav-item { justify-content: flex-start; padding: 9px 12px; }
    .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .profile-grid { grid-template-columns: 1fr; }
    .page-content { padding: 16px; }
    .app-header { padding: 0 16px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .btn-label { display: none; }
    body.sidebar-open { overflow: hidden; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

/* ── Utilitários ─────────────────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.divider { height: 1px; background: var(--border-color); margin: 20px 0; }
.w-full { width: 100%; }
