/* IbiSense CRM - Design System */
:root {
    --primary: #1E40AF;
    --primary-light: #3B82F6;
    --primary-dark: #1E3A8A;
    --accent: #0EA5E9;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --purple: #8B5CF6;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    --sidebar-width: 260px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
}

/* ========== AUTH PAGES ========== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--accent) 100%);
    padding: 20px;
}
.auth-card {
    background: white;
    border-radius: 16px;
    padding: 48px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}
.auth-logo h1 {
    font-size: 28px;
    color: var(--primary);
    font-weight: 800;
}
.auth-logo p {
    color: var(--gray-500);
    font-size: 14px;
    margin-top: 4px;
}
.auth-card h2 {
    font-size: 22px;
    color: var(--gray-800);
    margin-bottom: 24px;
    text-align: center;
}

/* ========== FORMS ========== */
.form-group {
    margin-bottom: 18px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-300);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font);
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
select.form-control {
    cursor: pointer;
}
textarea.form-control {
    resize: vertical;
    min-height: 80px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #059669; }
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #DC2626; }
.btn-outline {
    background: white;
    color: var(--gray-700);
    border: 1.5px solid var(--gray-300);
}
.btn-outline:hover { border-color: var(--primary-light); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

/* ========== ALERTS ========== */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-warning { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s;
}
.sidebar-brand {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand h1 {
    font-size: 22px;
    font-weight: 800;
    color: white;
}
.sidebar-brand small {
    font-size: 11px;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.sidebar-nav {
    padding: 16px 0;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--gray-400);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}
.sidebar-nav a.active {
    color: white;
    background: rgba(59,130,246,0.15);
    border-left-color: var(--primary-light);
}
.sidebar-nav a .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
}
.sidebar-section {
    padding: 12px 20px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gray-500);
    font-weight: 600;
}
.sidebar-user {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.2);
}
.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
}
.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: white;
}
.sidebar-user-plan {
    font-size: 11px;
    color: var(--gray-400);
    text-transform: uppercase;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}
.topbar {
    background: white;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-800);
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.content {
    padding: 32px;
}

/* ========== CARDS ========== */
.card {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    overflow: hidden;
}
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-800);
}
.card-body {
    padding: 24px;
}

/* ========== STATS GRID ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}
.stat-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.blue { background: #DBEAFE; color: var(--primary); }
.stat-icon.green { background: #D1FAE5; color: var(--success); }
.stat-icon.yellow { background: #FEF3C7; color: var(--warning); }
.stat-icon.red { background: #FEE2E2; color: var(--danger); }
.stat-icon.purple { background: #EDE9FE; color: var(--purple); }
.stat-info h4 {
    font-size: 28px;
    font-weight: 800;
    color: var(--gray-800);
    line-height: 1;
}
.stat-info p {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* ========== TABLE ========== */
.table-container {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--gray-200);
    background: var(--gray-50);
}
table td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
table tr:hover td {
    background: var(--gray-50);
}
table .actions {
    display: flex;
    gap: 8px;
}

/* ========== BADGE ========== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-free { background: #DBEAFE; color: var(--primary); }
.badge-premium { background: #FEF3C7; color: #92400E; }
.badge-enterprise { background: #EDE9FE; color: var(--purple); }
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-info { background: #DBEAFE; color: var(--primary); }

/* ========== KANBAN ========== */
.kanban {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 20px;
    min-height: 500px;
}
.kanban-column {
    min-width: 280px;
    max-width: 300px;
    flex-shrink: 0;
    background: var(--gray-100);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
}
.kanban-column-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid;
}
.kanban-column-header h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--gray-700);
}
.kanban-column-count {
    background: white;
    color: var(--gray-600);
    padding: 2px 8px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 600;
}
.kanban-cards {
    padding: 12px;
    flex: 1;
    min-height: 100px;
}
.kanban-card {
    background: white;
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 10px;
    border: 1px solid var(--gray-200);
    cursor: grab;
    transition: box-shadow 0.2s, transform 0.2s;
}
.kanban-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}
.kanban-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 8px;
}
.kanban-card-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--success);
}
.kanban-card-contact {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 6px;
}
.kanban-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-100);
}

/* ========== CONTACT DETAIL ========== */
.contact-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 28px;
}
.contact-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}
.contact-info h2 {
    font-size: 24px;
    font-weight: 700;
}
.contact-info p {
    color: var(--gray-500);
    font-size: 14px;
}
.contact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
}
.detail-row .label {
    font-size: 13px;
    color: var(--gray-500);
    font-weight: 500;
}
.detail-row .value {
    font-size: 14px;
    color: var(--gray-800);
    font-weight: 500;
}

/* ========== NOTES ========== */
.note-item {
    padding: 16px;
    border-bottom: 1px solid var(--gray-100);
}
.note-item:last-child { border-bottom: none; }
.note-date {
    font-size: 12px;
    color: var(--gray-400);
    margin-bottom: 6px;
}
.note-text {
    font-size: 14px;
    color: var(--gray-700);
    white-space: pre-wrap;
}

/* ========== ACTIVITY ========== */
.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 0;
    border-bottom: 1px solid var(--gray-100);
}
.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.activity-icon.chiamata { background: #DBEAFE; color: var(--primary); }
.activity-icon.email { background: #D1FAE5; color: var(--success); }
.activity-icon.riunione { background: #EDE9FE; color: var(--purple); }
.activity-icon.nota { background: #FEF3C7; color: var(--warning); }
.activity-icon.compito { background: #FEE2E2; color: var(--danger); }
.activity-content { flex: 1; }
.activity-content h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
}
.activity-content p {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 2px;
}
.activity-meta {
    font-size: 12px;
    color: var(--gray-400);
    white-space: nowrap;
}

/* ========== PAGINATION ========== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
}
.pagination a, .pagination span {
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
}
.pagination a:hover { border-color: var(--primary-light); color: var(--primary); }
.pagination .active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ========== SEARCH BAR ========== */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.search-bar input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid var(--gray-300);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font);
}
.search-bar input:focus {
    outline: none;
    border-color: var(--primary-light);
}

/* ========== MODAL ========== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white;
    border-radius: 16px;
    padding: 32px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.modal h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}
.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
}
.empty-state h3 {
    font-size: 18px;
    color: var(--gray-600);
    margin-bottom: 8px;
}
.empty-state p {
    font-size: 14px;
    margin-bottom: 20px;
}

/* ========== PROGRESS BAR ========== */
.progress-bar {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

/* ========== RESPONSIVE ========== */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-700);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .mobile-toggle {
        display: block;
    }
    .content {
        padding: 20px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .contact-grid {
        grid-template-columns: 1fr;
    }
    .kanban {
        flex-direction: column;
    }
    .kanban-column {
        min-width: 100%;
        max-width: 100%;
    }
}
