/* ============================================
   ZERO NETWORK - Contact Manager
   Mobile-First CSS
   ============================================ */

/* --- Reset & Variabili --- */
:root {
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-border: #e2e8f0;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #ef4444;
    --color-success: #22c55e;
    --color-warning: #eab308;
    --color-info: #3b82f6;
    
    --color-caldo-bg: rgba(34, 197, 94, 0.08);
    --color-caldo-border: #22c55e;
    --color-tiepido-bg: rgba(234, 179, 8, 0.08);
    --color-tiepido-border: #eab308;
    --color-freddo-bg: rgba(59, 130, 246, 0.08);
    --color-freddo-border: #3b82f6;
    
    --header-height: 56px;
    --bottom-nav-height: 64px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Login Page --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.login-logo h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.login-logo h1 span {
    color: var(--color-primary);
}

.login-logo p {
    font-size: 0.9rem;
    opacity: 0.7;
    margin-top: 4px;
}

.login-form {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.login-footer {
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 0.8rem;
    margin-top: 24px;
}

/* --- App Layout --- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

#page-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.user-badge {
    font-size: 0.8rem;
    background: var(--color-bg);
    padding: 4px 10px;
    border-radius: 20px;
    color: var(--color-text-secondary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 16px);
    -webkit-overflow-scrolling: touch;
}

/* --- Bottom Navigation --- */
#bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-area-bottom);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    max-width: 800px;
    margin: 0 auto;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    height: 100%;
    border: none;
    background: none;
    color: var(--color-text-secondary);
    font-size: 0.65rem;
    cursor: pointer;
    transition: color 0.2s;
    padding: 4px;
}

.nav-item.active {
    color: var(--color-primary);
}

.nav-item svg {
    width: 22px;
    height: 22px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    min-height: 44px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--color-border);
    color: var(--color-text);
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    min-height: 36px;
}

.btn-lg {
    padding: 14px 24px;
    font-size: 1.05rem;
    min-height: 52px;
}

.btn-loader {
    display: inline-flex;
    align-items: center;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--color-text);
    border-radius: 50%;
    cursor: pointer;
}

.icon-btn:active {
    background: var(--color-bg);
}

/* --- Forms --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--color-text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.error-message {
    background: #fef2f2;
    color: var(--color-danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
    border-left: 3px solid var(--color-danger);
}

.success-message {
    background: #f0fdf4;
    color: #166534;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
    border-left: 3px solid var(--color-success);
}

/* --- Cards --- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.caldo .stat-value { color: var(--color-caldo-border); }
.stat-card.tiepido .stat-value { color: var(--color-tiepido-border); }
.stat-card.freddo .stat-value { color: var(--color-freddo-border); }
.stat-card.follow-up .stat-value { color: var(--color-danger); }

/* --- Contact List --- */
.contact-list {
    list-style: none;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    border-left: 4px solid transparent;
    cursor: pointer;
    transition: background 0.15s;
    gap: 12px;
}

.contact-item:active {
    background: var(--color-bg);
}

.contact-item.caldo {
    background: var(--color-caldo-bg);
    border-left-color: var(--color-caldo-border);
}

.contact-item.tiepido {
    background: var(--color-tiepido-bg);
    border-left-color: var(--color-tiepido-border);
}

.contact-item.freddo {
    background: var(--color-freddo-bg);
    border-left-color: var(--color-freddo-border);
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: white;
    flex-shrink: 0;
}

.contact-item.caldo .contact-avatar { background: var(--color-caldo-border); }
.contact-item.tiepido .contact-avatar { background: var(--color-tiepido-border); }
.contact-item.freddo .contact-avatar { background: var(--color-freddo-border); }

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-badge {
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}

.badge-caldo { background: #dcfce7; color: #166534; }
.badge-tiepido { background: #fef9c3; color: #854d0e; }
.badge-freddo { background: #dbeafe; color: #1e40af; }

/* --- Search Bar --- */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.search-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background: var(--color-surface);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* --- Filter Chips --- */
.filter-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.filter-chip {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1.5px solid var(--color-border);
    background: var(--color-surface);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s;
}

.filter-chip.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* --- Scheda contatto --- */
.detail-section {
    margin-bottom: 20px;
}

.detail-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.95rem;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

.detail-value {
    font-weight: 500;
    text-align: right;
}

/* --- Timeline --- */
.timeline {
    list-style: none;
}

.timeline-item {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    font-size: 0.85rem;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary);
    margin-top: 6px;
    flex-shrink: 0;
}

.timeline-content {
    flex: 1;
}

.timeline-action {
    font-weight: 600;
}

.timeline-date {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

/* --- Import Preview --- */
.import-preview-table {
    width: 100%;
    overflow-x: auto;
    font-size: 0.8rem;
}

.import-preview-table table {
    width: 100%;
    border-collapse: collapse;
}

.import-preview-table th,
.import-preview-table td {
    padding: 8px;
    border: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}

.import-preview-table th {
    background: var(--color-bg);
    font-weight: 600;
    font-size: 0.75rem;
}

.duplicate-row {
    background: #fef2f2;
}

/* --- Toast --- */
#toast-container {
    position: fixed;
    top: calc(var(--header-height) + 8px);
    right: 8px;
    left: 8px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 800px;
    margin: 0 auto;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    pointer-events: auto;
}

.toast-success {
    background: #166534;
    color: white;
}

.toast-error {
    background: #991b1b;
    color: white;
}

.toast-info {
    background: #1e40af;
    color: white;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--color-text-secondary);
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    opacity: 0.7;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 1.2rem;
}

/* --- Utilities --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.flex-1 { flex: 1; }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.text-secondary { color: var(--color-text-secondary); }

/* --- Loading Spinner --- */
.spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
}

.spinner svg {
    width: 32px;
    height: 32px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Responsive (tablet/desktop) --- */
@media (min-width: 768px) {
    #app {
        border-left: 1px solid var(--color-border);
        border-right: 1px solid var(--color-border);
    }
    
    .stats-grid {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .form-row {
        gap: 16px;
    }
    
    #main-content {
        padding: 24px;
        padding-bottom: calc(var(--bottom-nav-height) + 24px);
    }
}