/* File: /assets/style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --sidebar-bg: #1f2937;
    --sidebar-text: #d1d5db;
    --sidebar-text-active: #ffffff;
    --sidebar-hover: #374151;
    --text-color: #1f2937;
    --text-light: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #10B981;
    --error-color: #EF4444;
    --warning-color: #F59E0B;
    --border-radius: 8px;
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}
.app-container {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.logo { padding: 1.5rem; text-align: center; border-bottom: 1px solid #374151; }
.logo h1 { margin: 0; color: var(--sidebar-text-active); font-size: 1.5rem; }
.sidebar-nav ul { list-style: none; padding: 1rem 0; margin: 0; }
.sidebar-nav li a {
    display: block;
    padding: 0.8rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    border-radius: 0 8px 8px 0; /* Arrotondamento a destra */
    margin-right: 1rem; /* Spazio per l'arrotondamento */
}
.sidebar-nav li a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.sidebar-nav li a.active {
    background: var(--primary-color);
    color: var(--sidebar-text-active);
    font-weight: 600;
}
.main-content {
    flex-grow: 1;
    min-width: 0;
    overflow-y: auto;
}
header {
    background: var(--card-bg);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-soft);
}
header h1 { margin: 0; font-size: 1.8rem; font-weight: 700; }
.container-fluid { padding: 2rem; }
.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}
.card h2 { margin-top: 0; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}
.stat-card {
    padding: 1.5rem;
    text-align: center;
}
.stat-card h3 {
    font-size: 1.1rem;
    color: var(--text-light);
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
}
.stat-card .stat-number {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--primary-color);
}
.stat-card .stat-number .spinner {
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(0,0,0,0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Tabelle */
.table-container { overflow-x: auto; }
.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: 0.95em;
}
.results-table th, .results-table td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: middle;
}
.results-table th { background-color: #f9fafb; font-weight: 600; color: var(--text-light); }
.results-table tbody tr:hover { background-color: #f9fafb; }

/* Form Impostazioni */
.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.5rem; }
.form-group small { color: var(--text-light); font-size: 0.85em; margin-top: 0.5rem; display: block; }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], textarea, select {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    background-color: #fdfdfd;
    transition: all 0.2s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0,123,255,0.2);
}
textarea { resize: vertical; min-height: 120px; }
.btn-save {
    padding: 0.8rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none; border-radius: 6px;
    font-size: 1rem; font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-save:hover { background: var(--primary-hover); }
.btn-save:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Status */
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }
.status-dot.attivo { background-color: var(--success-color); }
.status-dot.parking { background-color: var(--text-light); }
.site-url { color: var(--text-light); font-size: 0.9em; text-decoration: none; }
.site-url:hover { text-decoration: underline; }

/* ================================================= */
/* == Stili per Pulsanti Analisi e Modale (v3.5) == */
/* ================================================= */

.btn-scan, .btn-view-analysis, .btn-send-now {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 5px 10px;
    font-size: 0.9em;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap; /* Non manda a capo il testo */
    margin-right: 5px;
    margin-top: 5px; /* Spazio se vanno a capo su mobile */
}
.btn-scan:hover, .btn-send-now:hover {
    background-color: var(--primary-hover);
}
.btn-scan:disabled, .btn-send-now:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}
.btn-send-now {
    background-color: var(--warning-color);
    color: #000;
}

.btn-view-analysis {
    background-color: var(--text-light); /* Grigio per "Vedi" */
}
.btn-view-analysis:hover {
    background-color: var(--text-color); /* Grigio scuro */
}
.btn-view-analysis[data-type="error"] {
    background-color: var(--warning-color); /* Arancione per "Vedi Errore" */
    color: #000;
}
.btn-view-analysis[data-type="error"]:hover {
    filter: brightness(0.9);
}

.analysis-action-cell {
    min-width: 170px; /* Spazio per i pulsanti */
}
.analysis-status-cell .spinner {
    display: inline-block;
    vertical-align: middle;
    margin-right: 5px;
}

/* Stili Modale */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); display: flex; align-items: center;
    justify-content: center; z-index: 1000; animation: fadeIn 0.2s ease-out;
}
.modal-content {
    background: var(--card-bg); padding: 1.5rem 2rem 2rem 2rem;
    border-radius: var(--border-radius); width: 90%; max-width: 700px;
    max-height: 80vh; display: flex; flex-direction: column;
    position: relative; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    animation: zoomIn 0.2s ease-out;
}
.modal-content h2 {
    margin-top: 0; padding-bottom: 1rem; border-bottom: 1px solid var(--border-color);
}
.modal-close-btn {
    position: absolute; top: 10px; right: 15px; background: none;
    border: none; font-size: 2rem; color: var(--text-light);
    cursor: pointer; line-height: 1;
}
.modal-close-btn:hover { color: var(--error-color); }
.modal-pre {
    flex-grow: 1; overflow-y: auto; background: var(--bg-color);
    padding: 1rem; border-radius: 6px; white-space: pre-wrap;
    word-wrap: break-word; font-family: monospace; font-size: 0.9em;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ================================================= */
/* == Stili per "Crea Campagna" (v3.5) == */
/* ================================================= */

#keywords-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 6px;
    background: #fdfdfd;
}
.kw-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
}
.kw-header label {
    font-weight: 600;
}
.keyword-checkbox {
    display: block;
    margin-bottom: 0.5rem;
}
.keyword-checkbox label {
    margin-left: 0.5rem;
    font-size: 0.95em;
    cursor: pointer;
}
.keyword-checkbox input {
    width: auto; /* Sovrascrive lo stile globale */
    cursor: pointer;
}
#generation-status, #schedule-status {
    font-weight: 600;
    color: var(--primary-color);
    margin-left: 1rem;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 768px) {
    .form-grid { grid-template-columns: 1fr; }
}
.results-table select {
    width: 100%;
    max-width: 350px;
}

/* ================================================= */
/* == Stili per "Elenco Guest post" (v3.5) == */
/* ================================================= */
.tabs-container {
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 2rem;
}
.tab-link {
    padding: 0.8rem 1.2rem;
    cursor: pointer;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-light);
    transform: translateY(2px); /* Allinea con il bordo */
}
.tab-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

/* ================================================= */
/* ==       CSS RESPONSIVE PER SCHERMI MOBILI       == */
/* ================================================= */

@media (max-width: 768px) {

    /* 1. Layout Principale: Trasforma la Sidebar in una Topbar */
    .app-container {
        /* Stack verticale invece che orizzontale */
        flex-direction: column;
        min-height: 100vh;
    }

    .sidebar {
        /* La sidebar diventa una barra superiore al 100% */
        width: 100%;
        height: auto;
        flex-shrink: 0;
        box-shadow: var(--shadow-soft);
        z-index: 10;
    }

    .main-content {
        flex-grow: 1;
        /* La larghezza 100% è implicita */
    }
    
    .logo {
        padding: 1rem 1.5rem;
        text-align: left; /* Allinea a sx */
        border-bottom: none;
        display: flex;
        align-items: center;
    }
    .logo h1 {
        font-size: 1.25rem; /* Riduci dimensione font logo */
    }

    /* 2. Navigazione: Da verticale a orizzontale scrollabile */
    .sidebar-nav ul {
        display: flex;
        flex-direction: row; /* Menu in riga */
        overflow-x: auto;   /* Permette lo scroll orizzontale se le voci non entrano */
        white-space: nowrap;  /* Impedisce ai link di andare a capo */
        padding: 0 1.5rem;
        border-top: 1px solid #374151; /* Separatore dal logo */
    }

    .sidebar-nav li {
        flex-shrink: 0; /* Impedisce ai link di stringersi */
    }

    .sidebar-nav li a {
        padding: 0.8rem 1rem;
        border-left: none; /* Rimuovi bordo sx */
        border-bottom: 3px solid transparent; /* Aggiungi bordo sotto per l'active */
        margin-right: 0;
        border-radius: 0;
        font-size: 0.9rem;
    }

    .sidebar-nav li a.active {
        /* Stile "active" per la topbar */
        border-bottom-color: var(--primary-color);
        background: transparent;
        color: var(--sidebar-text-active);
    }
    .sidebar-nav li a:hover {
        background: var(--sidebar-hover);
    }

    /* 3. Header e Contenuto Principale */
    header {
        padding: 1rem 1.5rem;
    }
    header h1 {
        font-size: 1.5rem; /* Riduci titolo pagina */
    }
    .container-fluid {
        padding: 1rem; /* Riduci padding generale */
    }
    .card {
        padding: 1rem;
        margin-bottom: 1.5rem;
    }

    /* 4. Dashboard Grid (Statistiche) */
    .stat-card .stat-number {
        font-size: 2rem; /* Riduci numeri grandi */
    }
    .dashboard-grid {
        grid-template-columns: 1fr 1fr; /* 2 colonne fisse su mobile */
    }

    /* 5. Tabelle e Pulsanti nelle Tabelle */
    /* .table-container con overflow-x: auto è già una buona soluzione */
    
    .results-table th, .results-table td {
        padding: 0.7rem 0.8rem;
        font-size: 0.9rem;
        /* Il testo può andare a capo se necessario */
        white-space: normal; 
    }

    /* Corregge i pulsanti nelle celle (es. "Siti Amazon") */
    .analysis-action-cell {
        display: flex;
        flex-direction: column; /* Impila i pulsanti verticalmente */
        gap: 5px;
        min-width: 120px; /* Riduci la larghezza minima */
    }
    .btn-scan, .btn-view-analysis, .btn-send-now {
        width: 100%; /* Pulsanti a piena larghezza della cella */
        margin-right: 0;
        margin-top: 0;
        text-align: center;
    }
    
    /* Corregge il select nella tabella di "Crea Campagna" */
    .results-table select {
        max-width: 100%; /* Rimuovi il max-width fisso */
        font-size: 0.9rem;
    }

    /* 6. Form e Input */
    /* .form-grid è già gestito nel CSS originale, ottimo! */

    input[type="text"], input[type="password"], input[type="date"], 
    input[type="number"], textarea, select {
        padding: 0.7rem 0.8rem;
        font-size: 0.95rem; /* Rende il testo più leggibile su mobile */
    }

    /* 7. Tabs (Pagina "Elenco Guest post") */
    .tabs-container {
        flex-direction: column; /* Impila le tab verticalmente */
        align-items: stretch; /* Allarga le tab al 100% */
        gap: 0;
    }
    .tab-link {
        width: 100%;
        text-align: center;
        border-bottom-width: 2px;
        transform: translateY(0);
        font-size: 1rem;
        border-radius: 4px 4px 0 0;
    }
    .tab-link.active {
        /* Dà uno sfondo alla tab attiva per chiarezza */
        background: var(--border-color); 
    }

    /* 8. Modali */
    .modal-content {
        width: 95%; /* Leggermente più largo */
        padding: 1rem 1.5rem 1.5rem 1.5rem;
        max-height: 85vh;
    }
    .modal-content h2 {
        font-size: 1.25rem;
    }
    .modal-pre {
        font-size: 0.85em;
    }
}