/**
 * Syrus Sales OS – Modern Design System
 * Based on Material Design 3 (Google) + Human Interface Guidelines (Apple)
 * Brand: Syrus Industry S.r.l.
 */

:root {
    /* Backgrounds */
    --color-bg-base: #FFFFFF;
    --color-bg-subtle: #F8FAFC;
    --color-bg-muted: #F1F5F9;
    --color-bg-emphasis: #E2E8F0;

    /* Brand */
    --color-brand-primary: #1B3A5C;
    --color-brand-accent: #2E75B6;
    --color-brand-light: #EBF3FB;
    --color-brand-hover: #1A5FA8;

    /* Text */
    --color-text-primary: #0F172A;
    --color-text-secondary: #475569;
    --color-text-muted: #94A3B8;
    --color-text-disabled: #CBD5E1;
    --color-text-inverse: #FFFFFF;
    --color-text-brand: #2E75B6;

    /* Borders */
    --color-border-default: #E2E8F0;
    --color-border-strong: #CBD5E1;
    --color-border-brand: #2E75B6;

    /* States */
    --color-success: #10B981;
    --color-warning: #F59E0B;
    --color-error: #EF4444;
    --color-info: #3B82F6;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

    /* Sidebar */
    --sidebar-width: 240px;
    --top-header-height: 56px;
    --mobile-nav-height: 64px;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--color-bg-muted);
    color: var(--color-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--color-text-primary);
    font-weight: 600;
}

a {
    color: var(--color-brand-accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--color-brand-hover);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--color-bg-base);
    border-right: 1px solid var(--color-border-default);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-logo {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 12px;
    border-bottom: 1px solid var(--color-bg-subtle);
}

.sidebar-logo img {
    max-height: 70px;
    max-width: 100%;
}

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

.sidebar-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    padding: 16px 24px 8px;
    font-weight: 600;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    color: var(--color-text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.sidebar .nav-link i {
    font-size: 18px;
    width: 24px;
    text-align: center;
    color: var(--color-text-muted);
    transition: color 0.2s ease;
}

.sidebar .nav-link:hover {
    background: var(--color-bg-subtle);
    color: var(--color-text-primary);
}

.sidebar .nav-link.active {
    background: var(--color-brand-light);
    color: var(--color-brand-primary);
    border-left-color: var(--color-brand-accent);
    font-weight: 600;
}

.sidebar .nav-link.active i {
    color: var(--color-brand-accent);
}

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

.user-profile-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 12px;
    transition: background 0.2s ease;
}

.user-profile-link:hover {
    background: var(--color-bg-subtle);
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--color-brand-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

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

/* ── Top Header ────────────────────────────────────────────────────────── */
.top-header {
    position: sticky;
    top: 0;
    height: var(--top-header-height);
    background: var(--color-bg-base);
    border-bottom: 1px solid var(--color-border-default);
    z-index: 1040;
}

.page-title {
    font-size: 18px;
    margin-bottom: 0;
    color: var(--color-text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-icon-header {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: 18px;
    padding: 8px;
    border-radius: 8px;
    position: relative;
    transition: background 0.2s;
}

.btn-icon-header:hover {
    background: var(--color-bg-subtle);
}

.notification-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    background: var(--color-error);
    color: #fff;
    border-radius: 50%;
    border: 2px solid var(--color-bg-base);
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--color-border-default);
}

.btn-sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: 20px;
}

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

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

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-base);
    border: 1px solid var(--color-border-default);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    padding: 0;
    margin-bottom: 24px;
    overflow: hidden;
}

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

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

.card-body {
    padding: 24px;
}

/* Stat Cards */
.stat-card {
    text-align: left;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-brand-primary);
    line-height: 1;
    margin-bottom: 4px;
}

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

.stat-trend {
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.trend-up { color: var(--color-success); }
.trend-down { color: var(--color-error); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    padding: 10px 20px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-sm {
    padding: 6px 12px;
    height: 32px;
    font-size: 13px;
}

.btn-md { height: 40px; }
.btn-lg { height: 48px; padding: 12px 24px; }

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

.btn-primary:hover {
    background-color: var(--color-brand-hover);
    border-color: var(--color-brand-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--color-brand-light);
    border-color: transparent;
    color: var(--color-brand-accent);
}

.btn-secondary:hover {
    background-color: #D6E9F8;
    color: var(--color-brand-primary);
}

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

.btn-outline-secondary:hover {
    background-color: var(--color-bg-subtle);
    border-color: var(--color-border-strong);
    color: var(--color-text-primary);
}

.btn-brand-success { background-color: var(--color-success); color: white; border: none; }
.btn-brand-danger { background-color: var(--color-error); color: white; border: none; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-label {
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}

.form-control, .form-select {
    height: 40px;
    border: 1px solid var(--color-border-default);
    border-radius: 8px;
    padding: 0 12px;
    font-size: 14px;
    color: var(--color-text-primary);
    transition: all 0.2s ease;
    background-color: var(--color-bg-base);
}

.form-control:focus, .form-select:focus {
    border-color: var(--color-brand-accent);
    box-shadow: 0 0 0 3px rgba(46,117,182,0.15);
    outline: none;
}

textarea.form-control {
    height: auto;
    padding: 12px;
}

.input-group-text {
    background-color: var(--color-bg-subtle);
    border-color: var(--color-border-default);
    color: var(--color-text-secondary);
    border-radius: 8px;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table {
    margin-bottom: 0;
}

.table thead th {
    background: var(--color-bg-subtle);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748B;
    font-weight: 600;
    border-bottom: 2px solid var(--color-border-default);
    padding: 12px 16px;
}

.table tbody td {
    height: 52px;
    vertical-align: middle;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-bg-muted);
    font-size: 14px;
}

.table-hover tbody tr {
    transition: background 0.15s ease;
    cursor: pointer;
}

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

.table tbody tr td:first-child {
    font-weight: 500;
    color: var(--color-text-primary);
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
    padding: 6px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Status Badges - New System */
.badge-status-new { background-color: #FEF3C7; color: #92400E; } /* Warning style */
.badge-status-contacted { background-color: #EBF3FB; color: #1B3A5C; } /* Info style */
.badge-status-qualified { background-color: #E0E7FF; color: #3730A3; }
.badge-status-proposal_sent { background-color: #DBEAFE; color: #1E40AF; }
.badge-status-negotiation { background-color: #FCE7F3; color: #9D174D; }
.badge-status-won { background-color: #D1FAE5; color: #065F46; }
.badge-status-lost { background-color: #FEE2E2; color: #991B1B; }
.badge-status-dormant { background-color: #F1F5F9; color: #475569; }

/* Priority Badges */
.badge-priority-hot { background-color: #FEE2E2; color: #B91C1C; }
.badge-priority-warm { background-color: #FFEDD5; color: #9A3412; }
.badge-priority-cold { background-color: #DBEAFE; color: #1E40AF; }

/* Channel Badges */
.badge-channel-email { background-color: #E0F2FE; color: #0369A1; }
.badge-channel-sms { background-color: #F0FDF4; color: #15803D; }
.badge-channel-whatsapp { background-color: #DCFCE7; color: #166534; }
.badge-channel-phone { background-color: #F5F3FF; color: #6D28D9; }

/* ── Webphone Widget ─────────────────────────────────────────────────────── */
.webphone-widget {
    position: fixed;
    bottom: 0;
    right: 24px;
    width: 280px;
    background: var(--color-bg-base);
    border-radius: 12px 12px 0 0;
    box-shadow: var(--shadow-lg);
    z-index: 1060;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.webphone-header {
    background: var(--color-brand-primary);
    color: white;
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.wp-status-dot {
    width: 8px;
    height: 8px;
    background: var(--color-text-muted);
    border-radius: 50%;
}

.webphone-widget.calling .wp-status-dot { background: var(--color-success); animation: pulse 1s infinite; }
.webphone-widget.ringing .wp-status-dot { background: var(--color-warning); animation: pulse 1s infinite; }

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 1; }
}

.webphone-body {
    padding: 16px;
}

.webphone-dialpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.webphone-dialpad button {
    height: 52px;
    border: 1px solid var(--color-border-default);
    background: var(--color-bg-subtle);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.webphone-dialpad button:hover { background: var(--color-bg-emphasis); }
.webphone-dialpad button:active { background: var(--color-border-strong); transform: scale(0.95); }

.webphone-dialpad button span { font-size: 18px; font-weight: 600; line-height: 1; }
.webphone-dialpad button small { font-size: 9px; color: var(--color-text-muted); font-weight: 500; }

/* ── Mobile Navigation ────────────────────────────────────────────────────── */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--mobile-nav-height);
    background: var(--color-bg-base);
    border-top: 1px solid var(--color-border-default);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1050;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--color-text-secondary);
    font-size: 11px;
    font-weight: 500;
    gap: 4px;
}

.mobile-nav-item i { font-size: 20px; }
.mobile-nav-item.active { color: var(--color-brand-accent); }

/* ── Empty States ────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state-icon {
    font-size: 48px;
    color: var(--color-text-disabled);
    margin-bottom: 16px;
}

.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}

.empty-state-text {
    font-size: 14px;
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

/* ── Loading Skeletons ───────────────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #F1F5F9 25%, #E2E8F0 50%, #F1F5F9 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── WhatsApp Chat UI Redesign ───────────────────────────────────────────── */
.chat-window {
    height: 600px;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-base);
    border-radius: 12px;
    border: 1px solid var(--color-border-default);
    overflow: hidden;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--color-border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #F8FAFC;
    background-image: radial-gradient(var(--color-border-default) 0.5px, transparent 0.5px);
    background-size: 20px 20px;
}

.chat-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    box-shadow: var(--shadow-xs);
}

.chat-bubble.incoming {
    align-self: flex-start;
    background: white;
    color: var(--color-text-primary);
    border-bottom-left-radius: 2px;
}

.chat-bubble.outgoing {
    align-self: flex-end;
    background: var(--color-brand-primary);
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-time {
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.chat-footer {
    padding: 16px;
    border-top: 1px solid var(--color-border-default);
    background: white;
}

/* ── Responsive Overrides ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .main-content {
        margin-left: 0;
        padding-bottom: var(--mobile-nav-height);
    }
    .content-container {
        padding: 16px;
    }
    .webphone-widget {
        right: 16px;
        bottom: calc(var(--mobile-nav-height) + 16px);
        width: calc(100% - 32px);
        border-radius: 12px;
    }
}

/* ── WhatsApp Notification Animations ────────────────────────────────────── */
@keyframes waNotifSlideIn {
    from { transform: translateX(-120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes waNotifSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-120%); opacity: 0; }
}

/* WA sidebar blink when unread */
.wa-has-unread {
    position: relative;
}

.wa-has-unread::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    background: #25D366;
    border-radius: 50%;
    animation: waBlink 1.5s ease-in-out infinite;
}

@keyframes waBlink {
    0%, 100% { opacity: 1; transform: translateY(-50%) scale(1); }
    50% { opacity: 0.3; transform: translateY(-50%) scale(0.8); }
}

/* Responsive: notification card on mobile */
@media (max-width: 768px) {
    #wa-notif-container {
        left: 16px !important;
        right: 16px !important;
        max-width: none !important;
    }
}

/* ── Custom Utilities ────────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.rounded-xl { border-radius: 12px !important; }
.text-xs { font-size: 12px; }
.fw-semibold { font-weight: 600; }