/* =============================================
   ClientLog v2 — Estilos Principais
   ============================================= */

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --secondary: #f1f5f9;
    --secondary-hover: #e2e8f0;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --warning: #f59e0b;
    --warning-light: #fffbeb;

    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

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

    --sidebar-width: 240px;
    --topbar-height: 60px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,.10);
    --shadow-lg: 0 10px 40px rgba(0,0,0,.15);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* =============================================
   LOGIN PAGE
   ============================================= */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(var(--login-gradient, 135deg, #1d4ed8 0%, #3b82f6 100%));
    padding: 20px;
}
.login-container { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.login-card { width: 100%; background: var(--surface); border-radius: var(--radius-lg); padding: 40px 36px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.logo-icon { display: flex; align-items: center; }
.logo-text { font-size: 20px; font-weight: 700; color: var(--text); }
.login-title { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 28px; font-size: 14px; }
.login-footer { color: rgba(255,255,255,.7); font-size: 13px; }

/* =============================================
   APP LAYOUT
   ============================================= */
.app-page { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar { width: var(--sidebar-width); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 200; transition: transform .25s ease; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px; border-bottom: 1px solid var(--border-light); }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-size: 17px; font-weight: 700; }
.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); }
.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.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-size: 14px; font-weight: 500; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--secondary); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item svg { flex-shrink: 0; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border-light); display: flex; align-items: center; gap: 10px; }
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.user-details { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); }
.btn-logout { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 6px; border-radius: var(--radius-sm); transition: background .15s, color .15s; flex-shrink: 0; }
.btn-logout:hover { background: var(--danger-light); color: var(--danger); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; }

/* MAIN CONTENT */
.main-content { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* TOPBAR */
.topbar { height: var(--topbar-height); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 100; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: 4px; border-radius: var(--radius-sm); }
.page-title { font-size: 17px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

/* VIEWS */
.view { display: none; padding: 24px; }
.view.active { display: block; }

/* =============================================
   DASHBOARD
   ============================================= */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stat-card-icon { width: 40px; height: 40px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
.stat-card-icon.purple { background: var(--primary-light); color: var(--primary); }
.stat-card-icon.green { background: var(--success-light); color: #16a34a; }
.stat-card-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-card-icon.orange { background: var(--warning-light); color: #b45309; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.chart-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-card h3 { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 16px; }
.chart-wrap { position: relative; height: 220px; }

.dashboard-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dashboard-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px; }
.dashboard-card h3 { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 16px; }
.top-client-item { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-light); }
.top-client-item:last-child { border-bottom: none; }
.top-client-rank { width: 24px; height: 24px; border-radius: 50%; background: var(--primary-light); color: var(--primary); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.top-client-info { flex: 1; min-width: 0; }
.top-client-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-client-sub { font-size: 11px; color: var(--text-muted); }
.top-client-count { font-size: 13px; font-weight: 600; color: var(--primary); flex-shrink: 0; }

/* =============================================
   COMPONENTS
   ============================================= */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; cursor: pointer; border: none; transition: background .15s, transform .1s; white-space: nowrap; font-family: var(--font); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--text); }
.btn-secondary:hover { background: var(--secondary-hover); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 6px; border-radius: var(--radius-sm); transition: background .15s, color .15s; display: inline-flex; align-items: center; }
.btn-icon:hover { background: var(--secondary); color: var(--text); }

/* FORMS */
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea { padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-family: var(--font); color: var(--text); background: var(--surface); transition: border-color .15s; outline: none; width: 100%; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.form-group textarea { resize: vertical; }
.form-row { display: flex; gap: 16px; }
.required { color: var(--danger); }
.input-password-wrap { position: relative; }
.input-password-wrap input { padding-right: 40px; }
.toggle-password { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; }

/* ALERTS */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: #16a34a; }

/* SEARCH BAR */
.search-bar { margin-bottom: 20px; }
.search-input-wrap { position: relative; max-width: 400px; }
.search-input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-input-wrap input { width: 100%; padding: 9px 12px 9px 38px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-family: var(--font); background: var(--surface); outline: none; transition: border-color .15s; }
.search-input-wrap input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }

/* FILTERS BAR */
.filters-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group label { font-size: 13px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; }
.filter-group select { padding: 6px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font); background: var(--surface); color: var(--text); outline: none; cursor: pointer; }
.filter-group select:focus { border-color: var(--primary); }

/* CLIENTS GRID */
.clients-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.client-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .1s; }
.client-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.client-card-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.client-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; flex-shrink: 0; }
.client-card-info { flex: 1; min-width: 0; }
.client-card-name { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-card-company { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-card-meta { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--border-light); }
.client-meta-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); }

/* DETAIL VIEW */
.detail-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.btn-back { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; cursor: pointer; color: var(--text-secondary); font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: var(--radius-sm); transition: background .15s; }
.btn-back:hover { background: var(--secondary); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.client-detail-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 16px; }
.client-detail-top { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.client-detail-avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; flex-shrink: 0; }
.client-detail-name { font-size: 20px; font-weight: 700; margin-bottom: 2px; }
.client-detail-company { font-size: 14px; color: var(--text-muted); }
.client-detail-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.detail-field label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; display: block; margin-bottom: 4px; }
.detail-field span, .detail-field a { font-size: 14px; color: var(--text); }
.detail-field a { color: var(--primary); text-decoration: none; }
.detail-field a:hover { text-decoration: underline; }

/* CONTACTS */
.contacts-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.contacts-section-header h3 { font-size: 16px; font-weight: 600; }
.contact-item { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.contact-item-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.contact-item-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.contact-type-badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.type-chamada_recebida { background: #dbeafe; color: #1d4ed8; }
.type-chamada_efetuada { background: #ede9fe; color: #6d28d9; }
.type-email { background: #fef3c7; color: #b45309; }
.type-presencial { background: #dcfce7; color: #15803d; }
.type-outro { background: #f1f5f9; color: #475569; }
.contact-date { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.contact-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.contact-user { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.contact-user-avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; }
.contact-notes { font-size: 14px; color: var(--text); line-height: 1.6; white-space: pre-wrap; }

/* FILES */
.contact-files { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-light); }
.contact-files-title { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.file-list { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; color: var(--text-secondary); cursor: pointer; transition: background .15s; text-decoration: none; }
.file-chip:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.file-chip-del { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 0 0 0 4px; font-size: 14px; line-height: 1; }
.file-chip-del:hover { color: var(--danger); }

/* UPLOAD AREA */
.upload-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; color: var(--text-muted); }
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.upload-area p { font-size: 14px; font-weight: 500; margin-top: 8px; }
.upload-area small { font-size: 12px; }
.file-preview-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file-preview-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--primary-light); border: 1px solid #c7d2fe; border-radius: 20px; font-size: 12px; color: var(--primary); }
.file-preview-chip button { background: none; border: none; cursor: pointer; color: var(--primary); font-size: 14px; padding: 0; line-height: 1; }

/* RECENT CONTACTS */
.contacts-timeline { max-width: 800px; }
.recent-contact-item { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.recent-contact-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.recent-contact-client { font-size: 15px; font-weight: 600; color: var(--primary); margin-bottom: 6px; }

/* GLOBAL SEARCH */
.search-result-item { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s; }
.search-result-item:hover { border-color: var(--primary); }
.search-result-client { font-size: 15px; font-weight: 600; color: var(--primary); margin-bottom: 6px; }
.search-result-notes { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.search-result-notes mark { background: #fef08a; color: var(--text); border-radius: 2px; padding: 0 2px; }
.search-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* USERS TABLE */
.users-table { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.users-table table { width: 100%; border-collapse: collapse; }
.users-table th { background: var(--surface-2); padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
.users-table td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--border-light); }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--bg); }
.role-badge { display: inline-flex; padding: 3px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.role-admin { background: var(--primary-light); color: var(--primary); }
.role-user { background: var(--secondary); color: var(--text-secondary); }
.status-badge { display: inline-flex; padding: 3px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.status-active { background: var(--success-light); color: #16a34a; }
.status-inactive { background: var(--danger-light); color: var(--danger); }

/* SECTION HEADER */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h2 { font-size: 18px; font-weight: 600; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn .2s ease; }
.modal-lg { max-width: 680px; }
@keyframes modalIn { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; margin-bottom: 20px; }
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: var(--radius-sm); transition: background .15s; }
.modal-close:hover { background: var(--secondary); }
.modal form { padding: 0 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 20px 24px; border-top: 1px solid var(--border-light); margin-top: 4px; }

/* PAGINATION */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 24px; }
.page-btn { min-width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); transition: background .15s, border-color .15s; }
.page-btn:hover { background: var(--secondary); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* LOADING / EMPTY */
.loading-state, .empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--text-muted); text-align: center; gap: 12px; grid-column: 1 / -1; }
.empty-state svg { color: var(--border); }
.empty-state p { font-size: 15px; }
.empty-state small { font-size: 13px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* TOAST */
.toast { position: fixed; bottom: 24px; right: 24px; background: #1e293b; color: white; padding: 12px 18px; border-radius: var(--radius); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 2000; animation: toastIn .25s ease; max-width: 320px; }
.toast.success { background: #15803d; }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* =============================================
   THEME PICKER
   ============================================= */
.theme-picker { position: relative; }
.btn-theme-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); transition: background .15s, border-color .15s; font-family: var(--font); }
.btn-theme-toggle:hover { background: var(--secondary); border-color: var(--primary); color: var(--primary); }
.theme-dropdown { position: absolute; top: calc(100% + 8px); right: 0; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-lg); z-index: 500; min-width: 200px; }
.theme-dropdown-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: transform .15s, border-color .15s; }
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--text); }
.theme-modes { display: flex; gap: 6px; }
.mode-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 10px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); transition: background .15s, border-color .15s, color .15s; font-family: var(--font); }
.mode-btn:hover { background: var(--secondary); }
.mode-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* =============================================
   DARK MODE
   ============================================= */
[data-mode="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #263348;
    --border: #334155;
    --border-light: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --secondary: #263348;
    --secondary-hover: #334155;
}
[data-mode="dark"] .login-page { background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%); }
[data-mode="dark"] .users-table tr:hover td { background: #263348; }
[data-mode="dark"] .client-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.4); }
[data-mode="dark"] .modal-overlay { background: rgba(0,0,0,.7); }

/* =============================================
   USERS — CARDS MOBILE (substitui tabela em ecrãs pequenos)
   ============================================= */
.user-card-list { display: none; flex-direction: column; gap: 10px; }
.user-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.user-card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.user-card-info { flex: 1; min-width: 0; }
.user-card-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-email { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.user-card-actions { display: flex; gap: 8px; }
.user-card-actions .btn { flex: 1; justify-content: center; }

/* =============================================
   THEME PICKER
   ============================================= */
.theme-picker { position: relative; }
.btn-theme-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); transition: background .15s, border-color .15s; font-family: var(--font); }
.btn-theme-toggle:hover { background: var(--secondary); border-color: var(--primary); color: var(--primary); }
.theme-dropdown { position: absolute; top: calc(100% + 8px); right: 0; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-lg); z-index: 500; min-width: 210px; }
.theme-dropdown-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: transform .15s, border-color .15s; outline: none; }
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--text) !important; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.theme-modes { display: flex; gap: 6px; }
.mode-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 10px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); transition: background .15s, border-color .15s, color .15s; font-family: var(--font); }
.mode-btn:hover { background: var(--secondary); }
.mode-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* =============================================
   DARK MODE
   ============================================= */
[data-mode="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #263348;
    --border: #334155;
    --border-light: #263348;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --secondary: #263348;
    --secondary-hover: #334155;
}
[data-mode="dark"] .login-page { background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%); }
[data-mode="dark"] .users-table tr:hover td { background: #263348; }
[data-mode="dark"] .client-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.5); }
[data-mode="dark"] .modal-overlay { background: rgba(0,0,0,.7); }
[data-mode="dark"] .form-group input,
[data-mode="dark"] .form-group select,
[data-mode="dark"] .form-group textarea { background: var(--surface-2); color: var(--text); border-color: var(--border); }
[data-mode="dark"] .search-input-wrap input { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-mode="dark"] .filter-group select { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-mode="dark"] .upload-area { border-color: var(--border); color: var(--text-muted); }
[data-mode="dark"] .upload-area:hover { background: rgba(99,102,241,.1); }
[data-mode="dark"] .file-chip { background: var(--surface-2); border-color: var(--border); }
[data-mode="dark"] .toast { background: #334155; }

/* =============================================
   USERS — CARDS MOBILE
   ============================================= */
.user-card-list { display: none; flex-direction: column; gap: 10px; }
.user-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.user-card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.user-card-info { flex: 1; min-width: 0; }
.user-card-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-email { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.user-card-actions { display: flex; gap: 8px; }
.user-card-actions .btn { flex: 1; justify-content: center; }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 1024px) {
    .charts-grid { grid-template-columns: 1fr; }
    .dashboard-bottom { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-close { display: flex; }
    .sidebar-overlay.visible { display: block; }
    .main-content { margin-left: 0; }
    .menu-toggle { display: flex; }
    .topbar { padding: 0 16px; }
    .view { padding: 16px; }
    .clients-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 12px; }
    .detail-header { flex-direction: column; align-items: flex-start; }
    .client-detail-fields { grid-template-columns: 1fr 1fr; }
    .users-table { overflow-x: auto; }
    .topbar-actions .btn span { display: none; }
    .topbar-actions .btn { padding: 8px 10px; }
    .modal { max-height: 95vh; }
    .toast { bottom: 16px; right: 16px; left: 16px; max-width: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .detail-actions { flex-wrap: wrap; }
    .detail-actions .btn span { display: none; }
    .detail-actions .btn { padding: 8px 10px; }
}

@media (max-width: 480px) {
    .login-card { padding: 28px 20px; }
    .client-detail-fields { grid-template-columns: 1fr; }
    .contact-item-header { flex-direction: column; gap: 8px; }
    .stats-grid { grid-template-columns: 1fr; }
    .filters-bar { flex-direction: column; align-items: flex-start; }
}

/* =============================================
   USERS — CARDS GRID (substitui tabela)
   ============================================= */
.users-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}
.user-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.user-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-card-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700;
    flex-shrink: 0;
}
.user-card-info { flex: 1; min-width: 0; }
.user-card-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card-email { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.user-card-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.user-card-actions { display: flex; gap: 8px; }
.user-card-actions .btn { flex: 1; justify-content: center; }

/* =============================================
   CONFIGURAÇÕES & PERFIL
   ============================================= */
.settings-container {
    max-width: 680px;
}
.settings-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
}
.settings-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}
.settings-card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

/* Upload de logótipo */
.logo-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.logo-upload-area:hover, .logo-upload-area.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.logo-upload-area p { font-size: 14px; color: var(--text-secondary); margin: 8px 0 4px; }
.logo-upload-area small { font-size: 12px; color: var(--text-muted); }
#logo-upload-prompt { display: flex; flex-direction: column; align-items: center; pointer-events: none; }
#logo-preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.logo-preview-img { max-height: 80px; max-width: 200px; object-fit: contain; border-radius: 6px; }
.sidebar-logo-img { max-height: 36px; max-width: 140px; object-fit: contain; }
.company-logo-img { max-height: 52px; max-width: 200px; object-fit: contain; margin-bottom: 4px; }

/* =============================================
   2FA / MFA
   ============================================= */
.mfa-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 16px 0 20px;
    color: var(--text-secondary);
    font-size: 14px;
    gap: 10px;
}
.mfa-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 8px;
    text-align: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color .2s;
    background: var(--surface);
    color: var(--text);
}
.mfa-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.mfa-status {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px;
    border-radius: var(--radius);
}
.mfa-enabled { background: var(--success-light); border: 1px solid #bbf7d0; }
.mfa-disabled { background: var(--surface-2); border: 1px solid var(--border); }
.mfa-status strong { font-size: 14px; font-weight: 600; }
.mfa-status p { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.mfa-setup { display: flex; flex-direction: column; gap: 4px; }
.mfa-qr-wrap { display: flex; justify-content: center; padding: 12px 0; }
.mfa-qr { width: 180px; height: 180px; border: 2px solid var(--border); border-radius: var(--radius); }

/* =============================================
   DARK MODE — novas secções
   ============================================= */
[data-mode="dark"] .settings-card { background: var(--surface); border-color: var(--border); }
[data-mode="dark"] .logo-upload-area { border-color: var(--border); }
[data-mode="dark"] .logo-upload-area:hover, [data-mode="dark"] .logo-upload-area.drag-over { background: rgba(99,102,241,.1); }
[data-mode="dark"] .mfa-input { background: var(--surface); border-color: var(--border); color: var(--text); }
[data-mode="dark"] .mfa-enabled { background: rgba(34,197,94,.1); border-color: rgba(34,197,94,.3); }
[data-mode="dark"] .mfa-disabled { background: var(--surface-2); }
[data-mode="dark"] .user-card { background: var(--surface); border-color: var(--border); }

/* =============================================
   2FA BADGE NA EQUIPA
   ============================================= */
.mfa-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.mfa-on  { background: #dcfce7; color: #16a34a; }
.mfa-off { background: #f1f5f9; color: #94a3b8; }
.btn-warning { background: #f59e0b; color: #fff; border: none; }
.btn-warning:hover { background: #d97706; }
[data-mode="dark"] .mfa-on  { background: rgba(34,197,94,.15); color: #4ade80; }
[data-mode="dark"] .mfa-off { background: var(--surface-2); color: var(--text-muted); }

/* =============================================
   DASHBOARD — SELETOR DE PERÍODO
   ============================================= */
.dashboard-period-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
}
.period-btn {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .18s;
}
.period-btn:hover { border-color: var(--primary); color: var(--primary); }
.period-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-mode="dark"] .period-btn { background: var(--surface-2); border-color: var(--border); color: var(--text-secondary); }
[data-mode="dark"] .period-btn.active { background: var(--primary); color: #fff; }
