/* =====================================================
   CHATTY Dashboard - Custom Styles
   Design: Dark sidebar + Light content (AdminLTE inspired)
   ===================================================== */

:root {
    /* Primary Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;

    /* Status Colors */
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;

    /* Neutral Colors */
    --sidebar-bg: #1e1e2d;
    --sidebar-hover: #2a2a3d;
    --sidebar-active: #6366f1;
    --sidebar-text: #9ca3af;
    --sidebar-text-active: #ffffff;

    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;

    /* Sizing */
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
}

/* =====================================================
   Base Styles
   ===================================================== */

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

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

/* =====================================================
   Sidebar
   ===================================================== */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
}

.logo i {
    color: var(--primary);
    font-size: 28px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
}

.sidebar-tenant {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tenant-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    color: #fff;
}

.tenant-info {
    display: flex;
    flex-direction: column;
}

.tenant-name {
    font-weight: 600;
    color: #fff;
    font-size: 14px;
}

.tenant-plan {
    font-size: 12px;
    color: var(--sidebar-text);
}

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

.sidebar-nav ul {
    list-style: none;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: var(--sidebar-text);
    transition: all 0.2s ease;
    position: relative;
}

.nav-item a:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active a {
    background: var(--sidebar-active);
    color: #fff;
}

.nav-item.active a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #fff;
    border-radius: 0 3px 3px 0;
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item .badge {
    margin-left: auto;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.15);
}

.nav-item .badge-warning {
    background: var(--warning);
    color: #000;
}

.nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 16px 24px;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.bot-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.bot-status i {
    font-size: 8px;
}

.bot-status.online {
    color: var(--success);
}

.bot-status.offline {
    color: var(--danger);
}

/* =====================================================
   Main Content
   ===================================================== */

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

.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-search {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.topbar-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.topbar-search input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    background: var(--bg-main);
    transition: all 0.2s ease;
}

.topbar-search input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.topbar-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    position: relative;
    transition: all 0.2s ease;
}

.topbar-btn:hover {
    background: var(--bg-main);
    color: var(--primary);
}

.topbar-btn i {
    font-size: 18px;
}

.topbar-user {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    padding: 0 8px;
}

.topbar-btn.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.notification-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid var(--bg-card);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    margin-left: 8px;
    transition: background 0.2s ease;
}

.user-menu:hover {
    background: var(--bg-main);
}

.user-menu img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.user-menu span {
    font-weight: 500;
    font-size: 14px;
}

.user-menu i {
    font-size: 12px;
    color: var(--text-muted);
}

/* =====================================================
   Page Content
   ===================================================== */

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

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

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-header p {
    font-size: 14px;
    margin: 0;
}

.page-actions {
    display: flex;
    gap: 12px;
}

.form-select {
    padding: 10px 36px 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background-color: var(--bg-card);
    font-size: 14px;
    cursor: pointer;
}

/* =====================================================
   Stat Cards
   ===================================================== */

.stat-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon i {
    font-size: 22px;
    color: #fff;
}

.stat-icon.bg-primary { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.stat-icon.bg-success { background: linear-gradient(135deg, #22c55e, #16a34a); }
.stat-icon.bg-warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.bg-info { background: linear-gradient(135deg, #0ea5e9, #0284c7); }

.stat-content {
    flex: 1;
}

.stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.stat-trend {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-trend.positive {
    color: var(--success);
}

.stat-trend.negative {
    color: var(--danger);
}

/* =====================================================
   Cards
   ===================================================== */

.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.card-actions {
    display: flex;
    gap: 8px;
}

.card-actions .btn {
    font-size: 12px;
}

.card-body {
    padding: 20px;
}

.btn-link {
    color: var(--primary);
    font-weight: 500;
    font-size: 13px;
}

.btn-link:hover {
    color: var(--primary-dark);
}

/* =====================================================
   Conversation List
   ===================================================== */

.conversation-list {
    display: flex;
    flex-direction: column;
}

.conversation-item {
    display: flex;
    gap: 14px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
    cursor: pointer;
}

.conversation-item:last-child {
    border-bottom: none;
}

.conversation-item:hover {
    background: var(--bg-main);
}

.conversation-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #25D366, #128C7E);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.conversation-avatar i {
    font-size: 20px;
    color: #fff;
}

.conversation-content {
    flex: 1;
    min-width: 0;
}

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

.conversation-header .phone {
    font-weight: 600;
    font-size: 14px;
}

.conversation-header .time {
    font-size: 12px;
    color: var(--text-muted);
}

.conversation-content .preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 0 8px;
}

.conversation-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge-sede {
    background: var(--bg-main);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
}

.status {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.status.completed {
    color: var(--success);
}

.status.in-progress {
    color: var(--warning);
}

.status.abandoned {
    color: var(--text-muted);
}

/* =====================================================
   Tables
   ===================================================== */

.table {
    margin: 0;
}

.table thead th {
    background: var(--bg-main);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 12px 16px;
    border-bottom: none;
}

.table tbody td {
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-hover tbody tr:hover {
    background: var(--bg-main);
}

.sede-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.online {
    background: var(--success);
}

.status-dot.warning {
    background: var(--warning);
}

.status-dot.offline {
    background: var(--danger);
}

/* =====================================================
   Buttons
   ===================================================== */

.btn {
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    padding: 10px 18px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-secondary {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-outline-secondary:hover,
.btn-outline-secondary.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* =====================================================
   Responsive
   ===================================================== */

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

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .topbar .sidebar-toggle {
        display: flex;
    }
}

@media (min-width: 992px) {
    .topbar .sidebar-toggle {
        display: none;
    }
}

@media (max-width: 575.98px) {
    .page-content {
        padding: 16px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 24px;
    }

    .topbar-search {
        display: none;
    }
}
