/* ============================================================
   CRMZap — Estilos Globais (main.css)
   ============================================================ */

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

:root {
    /* Cores principais */
    --wa-green:        #25D366;
    --wa-green-dark:   #128C7E;
    --wa-green-light:  #dcfce7;
    --accent:          #25D366;
    --accent-hover:    #1ebe5d;

    /* Escala de cinza escuro */
    --bg-base:         #0d1117;
    --bg-surface:      #161b22;
    --bg-elevated:     #1c2128;
    --bg-card:         #21262d;
    --bg-hover:        #2d333b;
    --border:          #30363d;
    --border-subtle:   #21262d;

    /* Texto */
    --text-primary:    #e6edf3;
    --text-secondary:  #8b949e;
    --text-muted:      #484f58;
    --text-inverse:    #0d1117;

    /* Status */
    --success:         #3fb950;
    --warning:         #d29922;
    --danger:          #f85149;
    --info:            #58a6ff;

    /* Gradientes */
    --grad-green:      linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    --grad-blue:       linear-gradient(135deg, #58a6ff 0%, #1d4ed8 100%);
    --grad-purple:     linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    --grad-orange:     linear-gradient(135deg, #f97316 0%, #c2410c 100%);

    /* Glassmorphism */
    --glass-bg:        rgba(255,255,255,0.04);
    --glass-border:    rgba(255,255,255,0.08);
    --glass-blur:      blur(12px);

    /* Sombras */
    --shadow-sm:       0 1px 3px rgba(0,0,0,.4);
    --shadow-md:       0 4px 12px rgba(0,0,0,.5);
    --shadow-lg:       0 8px 32px rgba(0,0,0,.6);
    --shadow-glow:     0 0 20px rgba(37,211,102,.15);

    /* Raios */
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --radius-xl:   20px;
    --radius-full: 9999px;

    /* Fontes */
    --font-sans:   'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Animações */
    --transition: 0.2s ease;
    --transition-slow: 0.35s cubic-bezier(.4,0,.2,1);

    /* Sidebar */
    --sidebar-w:       240px;
    --sidebar-w-min:   68px;
    --topbar-h:        64px;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

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

/* --- Links ------------------------------------------------- */
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* --- App Layout ------------------------------------------- */
.app-body {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    margin-left: var(--sidebar-w);
    transition: margin-left var(--transition-slow);
}

.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-w-min);
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* --- Topbar ----------------------------------------------- */
.topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

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

.topbar-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.topbar-menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.topbar-title-group { display: flex; flex-direction: column; }
.topbar-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.topbar-subtitle { font-size: 0.75rem; color: var(--text-secondary); }

.topbar-btn {
    position: relative;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    width: 38px; height: 38px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }

.topbar-notif-badge {
    position: absolute;
    top: 4px; right: 4px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    width: 15px; height: 15px;
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
}

.topbar-user-mini { cursor: pointer; }
.topbar-user-avatar {
    width: 34px; height: 34px;
    background: var(--grad-green);
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700; color: #fff;
    letter-spacing: 0.5px;
}

/* --- Buttons ----------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 18px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-sans);
    white-space: nowrap;
    text-decoration: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background: var(--grad-green);
    color: #fff;
    box-shadow: var(--shadow-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 0 28px rgba(37,211,102,.28); filter: brightness(1.08); }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent); }

.btn-danger {
    background: rgba(248,81,73,.15);
    color: var(--danger);
    border-color: rgba(248,81,73,.3);
}
.btn-danger:hover { background: rgba(248,81,73,.25); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-icon { padding: 8px; width: 36px; height: 36px; }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 11px 24px; font-size: 1rem; }
.btn-full { width: 100%; }

/* --- Cards ------------------------------------------------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: border-color var(--transition);
}
.card:hover { border-color: rgba(37,211,102,.2); }

.card-glass {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }

/* --- Stat Cards -------------------------------------------- */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    position: relative;
    overflow: hidden;
    transition: all var(--transition);
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--stat-color, var(--accent));
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--stat-color, var(--accent)); }

.stat-icon {
    width: 46px; height: 46px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--stat-color, var(--accent)) 15%, transparent);
    flex-shrink: 0;
}
.stat-icon svg { color: var(--stat-color, var(--accent)); }

.stat-body { flex: 1; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.stat-change { font-size: 0.75rem; font-weight: 600; margin-top: 6px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* --- Tables ----------------------------------------------- */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--bg-elevated); }
th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
td {
    padding: 12px 16px;
    font-size: 0.875rem;
    color: var(--text-primary);
    border-top: 1px solid var(--border-subtle);
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--bg-hover); }

/* --- Badges ----------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 600;
    gap: 4px;
}
.badge-green  { background: rgba(37,211,102,.15); color: #25D366; }
.badge-blue   { background: rgba(88,166,255,.15); color: #58a6ff; }
.badge-orange { background: rgba(249,115,22,.15);  color: #f97316; }
.badge-red    { background: rgba(248,81,73,.15);   color: #f85149; }
.badge-gray   { background: rgba(139,148,158,.15); color: #8b949e; }
.badge-purple { background: rgba(139,92,246,.15);  color: #8b5cf6; }

/* --- Forms ------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    padding: 10px 14px;
    transition: all var(--transition);
    outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,211,102,.12);
    background: var(--bg-card);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }
.form-select { appearance: none; cursor: pointer; }
.form-textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Input with icon */
.input-wrapper { position: relative; }
.input-icon {
    position: absolute;
    left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.input-wrapper .form-input { padding-left: 40px; }
.input-toggle-pass {
    position: absolute;
    right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    padding: 4px;
    transition: color var(--transition);
}
.input-toggle-pass:hover { color: var(--text-primary); }

/* --- Alerts ----------------------------------------------- */
.alert {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 16px;
    animation: slideDown .3s ease;
}
.alert-error   { background: rgba(248,81,73,.12); color: var(--danger); border: 1px solid rgba(248,81,73,.25); }
.alert-success { background: rgba(63,185,80,.12); color: var(--success); border: 1px solid rgba(63,185,80,.25); }
.alert-warning { background: rgba(210,153,34,.12); color: var(--warning); border: 1px solid rgba(210,153,34,.25); }
.alert-info    { background: rgba(88,166,255,.12); color: var(--info); border: 1px solid rgba(88,166,255,.25); }

/* --- Modal ------------------------------------------------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    width: 90%; max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px) scale(.97);
    transition: transform var(--transition-slow);
    box-shadow: var(--shadow-lg);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 22px;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
    background: none; border: none;
    color: var(--text-secondary); cursor: pointer;
    padding: 4px; border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* --- Grid layouts ----------------------------------------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* --- Avatar ----------------------------------------------- */
.avatar {
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; flex-shrink: 0;
    background: var(--grad-green); color: #fff;
}
.avatar-sm { width: 30px; height: 30px; font-size: 0.7rem; }
.avatar-md { width: 40px; height: 40px; font-size: 0.85rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1rem; }

/* --- Spinner / Loading ------------------------------------- */
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* --- Utility ---------------------------------------------- */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; 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-muted { color: var(--text-secondary); }
.text-sm { font-size: 0.8rem; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Responsive -------------------------------------------- */
@media (max-width: 900px) {
    .main-content { margin-left: 0 !important; }
    .topbar-menu-btn { display: flex; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .page-content { padding: 16px; }
}
