/* ===================================================================
   SpeedMail — folha de estilo principal
   Inspiração visual: LaraClaud (sidebar dark glassmorphism, paleta indigo)
   =================================================================== */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1e293b;
    --darker: #0f172a;
    --light: #f8fafc;
    --gray: #64748b;
    --gray-light: #e2e8f0;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --navbar-height: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f1f5f9;
    color: var(--dark);
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; }

/* ============== SIDEBAR ============== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: #cbd5e1;
    z-index: 1000;
    overflow-y: auto;
    transition: width 0.25s ease;
    border-right: 1px solid rgba(255,255,255,0.05);
}
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }
.sidebar.collapsed .sidebar-text { display: none; }

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: var(--navbar-height);
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
}
.sidebar-logo-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.sidebar-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    padding: 1rem 1.5rem 0.5rem;
    font-weight: 600;
}

.sidebar-nav {
    list-style: none;
    padding: 0.5rem 0;
}
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem;
    color: #94a3b8;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    font-size: 0.92rem;
}
.sidebar-nav li a:hover {
    background: rgba(255,255,255,0.04);
    color: #fff;
}
.sidebar-nav li a.active {
    background: rgba(99,102,241,0.12);
    color: #fff;
    border-left-color: var(--primary);
}
.sidebar-nav li a i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
}

/* ============== TOPBAR ============== */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--navbar-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-light);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    transition: left 0.25s ease;
}
.sidebar.collapsed ~ .topbar { left: var(--sidebar-collapsed-width); }

.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-toggle {
    background: none; border: none; color: var(--gray);
    font-size: 1.2rem; cursor: pointer;
    width: 36px; height: 36px; border-radius: 6px;
}
.topbar-toggle:hover { background: var(--gray-light); }

.topbar-title { font-weight: 600; color: var(--dark); }

.topbar-right { display: flex; align-items: center; gap: 1rem; }

.tenant-badge {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    padding: 0.35rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.user-menu {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
}
.user-menu:hover { background: var(--gray-light); }
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

/* ============== MAIN CONTENT ============== */
.main {
    margin-left: var(--sidebar-width);
    margin-top: var(--navbar-height);
    padding: 1.5rem;
    min-height: calc(100vh - var(--navbar-height));
    transition: margin-left 0.25s ease;
}
.sidebar.collapsed ~ .main { margin-left: var(--sidebar-collapsed-width); }

/* ============== CARDS ============== */
.card-modern {
    background: #fff;
    border: 1px solid var(--gray-light);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.card-modern:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.06); }

.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--gray-light);
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    color: #fff;
}
.stat-icon.primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }
.stat-icon.success { background: linear-gradient(135deg, #10b981, #059669); }
.stat-icon.warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.danger { background: linear-gradient(135deg, #ef4444, #dc2626); }

.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--dark); line-height: 1; }
.stat-label { font-size: 0.85rem; color: var(--gray); margin-top: 0.25rem; }

/* ============== BUTTONS ============== */
.btn-primary-modern {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    padding: 0.55rem 1.2rem;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.15s;
}
.btn-primary-modern:hover { filter: brightness(1.1); color: #fff; }

/* ============== STATUS BADGES ============== */
.status-badge {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.status-badge.active { background: #dcfce7; color: #15803d; }
.status-badge.pending { background: #fef3c7; color: #92400e; }
.status-badge.suspended { background: #fee2e2; color: #b91c1c; }
.status-badge.trial { background: #dbeafe; color: #1e40af; }

/* ============== TABLES ============== */
table.table-modern {
    width: 100%;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}
table.table-modern thead th {
    background: #f8fafc;
    color: var(--gray);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--gray-light);
    text-align: left;
    font-weight: 600;
}
table.table-modern tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.9rem;
}
table.table-modern tbody tr:hover { background: #f8fafc; }

/* ============== LOGIN ============== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}
.login-card {
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-logo-icon {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 16px;
    display: inline-flex;
    align-items: center; justify-content: center;
    color: #fff;
    font-size: 1.8rem;
    box-shadow: 0 8px 24px rgba(99,102,241,0.4);
}
.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
    margin-top: 1rem;
}
.login-subtitle {
    color: var(--gray);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* ============== WEBMAIL — 3 colunas estilo Outlook/Zimbra ============== */
.webmail-layout {
    display: grid;
    grid-template-columns: 240px 380px 1fr;
    height: calc(100vh - var(--navbar-height));
    margin-top: var(--navbar-height);
    background: #fff;
}
.wm-folders {
    border-right: 1px solid var(--gray-light);
    background: #f8fafc;
    overflow-y: auto;
    padding: 1rem 0;
}
.wm-folder {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--dark);
}
.wm-folder:hover { background: rgba(99,102,241,0.06); }
.wm-folder.active {
    background: rgba(99,102,241,0.12);
    color: var(--primary-dark);
    font-weight: 500;
}
.wm-folder i { width: 18px; margin-right: 0.6rem; color: var(--gray); }
.wm-folder.active i { color: var(--primary); }
.wm-folder-count {
    background: var(--gray-light);
    border-radius: 10px;
    padding: 0.1rem 0.5rem;
    font-size: 0.72rem;
    color: var(--gray);
}
.wm-folder.active .wm-folder-count {
    background: var(--primary);
    color: #fff;
}

.wm-list {
    border-right: 1px solid var(--gray-light);
    overflow-y: auto;
}
.wm-list-toolbar {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wm-list-search {
    flex: 1;
    border: 1px solid var(--gray-light);
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
}

.wm-message {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.wm-message:hover { background: #f8fafc; }
.wm-message.unread { background: #fff; }
.wm-message.unread .wm-message-from,
.wm-message.unread .wm-message-subject { font-weight: 600; color: var(--dark); }
.wm-message.selected { background: rgba(99,102,241,0.08); border-left: 3px solid var(--primary); padding-left: calc(1rem - 3px); }
.wm-message-top { display: flex; justify-content: space-between; }
.wm-message-from { font-size: 0.9rem; color: var(--dark); }
.wm-message-date { font-size: 0.75rem; color: var(--gray); }
.wm-message-subject { font-size: 0.85rem; color: var(--dark); }
.wm-message-preview { font-size: 0.8rem; color: var(--gray); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wm-ai-tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-top: 0.2rem;
    font-weight: 500;
}
.wm-ai-tag.urgent     { background: #fee2e2; color: #b91c1c; }
.wm-ai-tag.client     { background: #dbeafe; color: #1e40af; }
.wm-ai-tag.fornecedor { background: #fef3c7; color: #92400e; }
.wm-ai-tag.newsletter { background: #f3e8ff; color: #6b21a8; }
.wm-ai-tag.interno    { background: #ccfbf1; color: #0f766e; }
.wm-ai-tag.fatura     { background: #dcfce7; color: #15803d; }
.wm-ai-tag.pessoal    { background: #e2e8f0; color: #475569; }
.wm-ai-tag.spam-sutil { background: #fecaca; color: #991b1b; }
.wm-ai-tag.outro      { background: #f1f5f9; color: #64748b; }

.wm-preview {
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.wm-preview-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--gray-light);
}
.wm-preview-subject {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 0.5rem;
}
.wm-preview-from {
    font-size: 0.9rem;
    color: var(--gray);
}
.wm-preview-body {
    padding: 1.5rem;
    flex: 1;
    min-height: 0;            /* deixa o filho (iframe) preencher e/ou rolar */
    display: flex;
    flex-direction: column;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--dark);
}
/* Iframe do corpo do email: ocupa TODO o espaco vertical disponivel do preview.
   O wmResizeFrame (JS) aumenta a altura alem disto quando o email e' mais alto
   que a area visivel — o scroll fica no .wm-preview. Assim emails curtos enchem
   a tela e emails longos rolam, sem corte. */
.wm-mail-frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 70vh;
    border: 0;
    background: #fff;
}

.wm-actions {
    display: flex;
    gap: 0.4rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-light);
}
.wm-action-btn {
    background: #fff;
    border: 1px solid var(--gray-light);
    color: var(--dark);
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.wm-action-btn:hover { background: var(--gray-light); }
.wm-action-btn.primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.wm-action-btn.primary:hover { background: var(--primary-dark); }

/* ============== TOM SELECT ============== */
.ts-wrapper .ts-control {
    border: 1px solid var(--gray-light);
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    min-height: 38px;
    font-size: 0.875rem;
    background: #fff;
}
.ts-wrapper .ts-control:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(99,102,241,0.15);
}
.ts-wrapper .ts-dropdown {
    border: 1px solid var(--gray-light);
    border-radius: 0.375rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    font-size: 0.875rem;
}
.ts-wrapper .ts-dropdown .ts-dropdown-content .option.active {
    background: var(--primary);
    color: #fff;
}
.ts-wrapper .ts-dropdown .ts-dropdown-content .option:hover {
    background: rgba(99,102,241,0.08);
}
.ts-wrapper .ts-dropdown .ts-dropdown-content .option.active:hover {
    background: var(--primary-dark);
    color: #fff;
}
.ts-wrapper .ts-dropdown .dropdown-input {
    border: none;
    border-bottom: 1px solid var(--gray-light);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}
.ts-wrapper .ts-dropdown .dropdown-input:focus {
    outline: none;
    box-shadow: none;
}
