// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

// ─── SEARCH ZONE ──────────────────────────────────────────────
.search-zone {
    background: var(--app-brand);
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 8px 10px;
}

.search-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.search-input {
    flex: 1;
    --background: rgba(255, 255, 255, 0.15);
    --color: #fff;
    --placeholder-color: rgba(255, 255, 255, 0.65);
    --icon-color: rgba(255, 255, 255, 0.7);
    --clear-button-color: rgba(255, 255, 255, 0.8);
    --border-radius: 12px;
    --box-shadow: none;
    --padding-top: 0;
    --padding-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.filter-btn {
    flex-shrink: 0;
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.18s;
    margin-top: 4px;

    ion-icon {
        font-size: 18px;
    }

    &.filter-active {
        background: rgba(255, 255, 255, 0.3);
        border: 1.5px solid rgba(255, 255, 255, 0.7);
    }
}

.filter-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    background: #ff4757;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
}

.chips-row {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 0 2px;
    scrollbar-width: none;

    &::-webkit-scrollbar {
        display: none;
    }
}

.filter-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 20px;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s;

    ion-icon {
        font-size: 13px;
    }

    &.chip-active {
        background: #fff;
        border-color: #fff;
        color: var(--app-brand);
        font-weight: 700;
    }
}

.result-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 0;
}

.result-count {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.75);
    font-weight: 500;
}

.clear-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.9);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 6px;

    ion-icon {
        font-size: 13px;
    }
}

/* Default theme */
.default {
    --kcs-primary: linear-gradient(135deg, #0055A4 0%, #007bff 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #004080 0%, #0056b3 100%);
    --kcs-primary-hover-text: #fff;
}

/* Green theme */
.green {
    --kcs-primary: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #059669 0%, #10b981 100%);
    --kcs-primary-hover-text: #fff;
}

/* Dark theme */
.dark {
    --kcs-primary: linear-gradient(135deg, #60a5fa 0%, #93c5fd 100%);
    --kcs-primary-text: #1f2937;
    --kcs-primary-hover: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    --kcs-primary-hover-text: #fff;
}

/* Light theme */
.light {
    --kcs-primary: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    --kcs-primary-hover-text: #fff;
}

/* Red-black theme */
.red-black {
    --kcs-primary: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    --kcs-primary-hover-text: #fff;
}

/* Blue-green theme */
.blue-green {
    --kcs-primary: linear-gradient(135deg, #14b8a6 0%, #2dd4bf 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #0d9488 0%, #14b8a6 100%);
    --kcs-primary-hover-text: #fff;
}

/* Blue theme */
.blue {
    --kcs-primary: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
    --kcs-primary-hover-text: #fff;
}

/* Red theme */
.red {
    --kcs-primary: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
    --kcs-primary-hover-text: #fff;
}

/* Purple theme */
.purple {
    --kcs-primary: linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #7c3aed 0%, #8b5cf6 100%);
    --kcs-primary-hover-text: #fff;
}

/* Orange theme */
.orange {
    --kcs-primary: linear-gradient(135deg, #f97316 0%, #fb923c 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #ea580c 0%, #f97316 100%);
    --kcs-primary-hover-text: #fff;
}

/* Green-sustainability theme */
.green-sustainability {
    --kcs-primary: linear-gradient(135deg, #16a34a 0%, #22c55e 100%);
    --kcs-primary-text: #fff;
    --kcs-primary-hover: linear-gradient(135deg, #15803d 0%, #16a34a 100%);
    --kcs-primary-hover-text: #fff;
}

/* Scenergy theme */
.scenergy {
    --kcs-primary: linear-gradient(135deg, #22d3ee 0%, #5eead4 100%);
    --kcs-primary-text: #1f2937;
    --kcs-primary-hover: linear-gradient(135deg, #06b6d4 0%, #22d3ee 100%);
    --kcs-primary-hover-text: #fff;
}

// Empty state
.empty-state {
    padding: 40px 24px;

    p {
        font-size: 15px;
    }
}

// Category accordion
.category-accordion {
    border-bottom: 1px solid var(--ion-color-light-shade);
}

.cat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    background: var(--ion-background-color, #fff);

    &:active {
        background: var(--ion-color-light);
    }
}

.cat-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.cat-icon {
    font-size: 20px;
    flex-shrink: 0;
    color: var(--ion-color-primary);
}

.cat-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--ion-color-dark);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cat-badge {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
    flex-shrink: 0;
}

.cat-chevron {
    font-size: 18px;
    flex-shrink: 0;
    margin-left: 8px;
}

.cat-cards {
    background: var(--ion-color-light, #f4f5f8);
    padding-bottom: 4px;
}

// ─── Macrogruppi: tile (livello 1) + back (livello 2) ─────────
.cat-section-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ion-color-medium);
    padding: 14px 16px 2px;
}

.cat-tiles {
    padding: 6px 8px 140px;
}

/* griglia "I miei servizi" seguita dalla sezione "Tutti": niente padding di fondo extra */
.cat-tiles.cat-tiles-inline {
    padding-bottom: 0;
}

/* tile placeholder durante il caricamento (skeleton) */
.cat-tile.cat-tile-skeleton {
    padding: 0;
    background: var(--ion-color-step-100, #f1f1f4);

    ion-skeleton-text {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        margin: 0;
    }
}

.cat-tile {
    position: relative;
    overflow: hidden;
    border-radius: 22px;
    min-height: 150px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 24px -8px rgba(17, 24, 39, 0.45);
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;

    &:hover {
        transform: translateY(-3px);
        box-shadow: 0 16px 32px -10px rgba(17, 24, 39, 0.55);
    }
    &:active {
        transform: scale(0.97);
    }

    // immagine di sfondo (da DB) sopra il gradiente, sotto lo scrim/contenuto
    .cat-tile-image {
        position: absolute;
        inset: 0;
        border-radius: inherit;
        pointer-events: none;
    }

    // icona watermark sfumata in basso a destra
    .cat-tile-watermark {
        position: absolute;
        right: -12px;
        bottom: -18px;
        font-size: 104px;
        line-height: 1;
        color: #fff;
        opacity: 0.14;
        transform: rotate(-8deg);
        pointer-events: none;
    }

    // velo scuro in basso per la leggibilità del testo
    .cat-tile-scrim {
        position: absolute;
        inset: 0;
        background: linear-gradient(180deg, rgba(0, 0, 0, 0) 35%, rgba(0, 0, 0, 0.28) 100%);
        pointer-events: none;
    }

    // chip vetrato con l'icona
    .cat-tile-chip {
        position: relative;
        z-index: 1;
        width: 46px;
        height: 46px;
        border-radius: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.22);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        border: 1px solid rgba(255, 255, 255, 0.28);
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);

        icon {
            font-size: 24px;
            color: #fff;
        }
    }

    .cat-tile-body {
        position: relative;
        z-index: 1;
        margin-top: auto;
    }

    .cat-tile-name {
        font-size: 18px;
        font-weight: 800;
        line-height: 1.15;
        letter-spacing: -0.01em;
        text-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    }

    .cat-tile-foot {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 8px;
    }

    .cat-tile-count {
        font-size: 11px;
        font-weight: 600;
        padding: 3px 9px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.22);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .cat-tile-go {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.9);

        ion-icon {
            font-size: 15px;
            color: #1f2937;
        }
    }
}

// header livello 2: link "‹ Categorie" + titolo categoria
.cat-head {
    padding: 10px 14px 4px;

    .cat-back-link {
        display: inline-flex;
        align-items: center;
        gap: 1px;
        margin: 0;
        padding: 2px 0;
        border: none;
        background: transparent;
        color: var(--ion-color-primary);
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;

        ion-icon {
            font-size: 18px;
        }

        &:active {
            opacity: 0.6;
        }
    }

    .cat-head-title {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-top: 2px;
        font-size: 20px;
        font-weight: 800;
        letter-spacing: -0.01em;
        color: var(--ion-color-dark);

        icon {
            font-size: 20px;
            color: var(--ion-color-primary);
        }
    }
}

ion-button {
    --background: var(--kcs-primary);
    --color: var(--kcs-primary-text);
    --background-activated: var(--kcs-primary-hover);
    --color-activated: var(--kcs-primary-hover-text);
    --background-hover: var(--kcs-primary-hover);
    --color-hover: var(--kcs-primary-hover-text);
}

// ─── ADVANCED FILTERS MODAL ───────────────────────────────────

.modal-header {
    ion-toolbar {
        --background: #fff;
        --border-width: 0;
        padding-top: 8px;
    }
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--ion-color-dark);
}

.reset-btn {
    font-size: 13px;
    font-weight: 600;
    --color: var(--app-brand);
}

.modal-content {
    --background: #f8f9fa;
}

.filter-section {
    background: #fff;
    border-radius: 14px;
    margin: 12px 16px 0;
    padding: 14px 16px;
}

.filter-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--ion-color-medium);
    margin: 0 0 12px;

    ion-icon {
        font-size: 14px;
    }
}

.sort-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sort-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1.5px solid var(--ion-color-light-shade);
    background: #fff;
    color: var(--ion-color-dark);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    width: 100%;

    ion-icon:first-child {
        font-size: 16px;
        color: var(--ion-color-medium);
        flex-shrink: 0;
    }

    span {
        flex: 1;
    }

    .check-icon {
        font-size: 16px;
        color: var(--app-brand);
        flex-shrink: 0;
    }

    &.selected {
        border-color: var(--app-brand);
        background: rgba(var(--app-brand-rgb), 0.06);
        color: var(--app-brand);
        font-weight: 600;

        ion-icon:first-child {
            color: var(--app-brand);
        }
    }
}

.filter-divider {
    height: 1px;
    margin: 8px 0;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--ion-color-light);
    cursor: pointer;
    gap: 12px;

    &:last-of-type {
        border-bottom: none;
        padding-bottom: 0;
    }

    &:first-of-type {
        padding-top: 0;
    }
}

.toggle-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.toggle-icon {
    font-size: 20px;
    color: var(--ion-color-medium);
    flex-shrink: 0;
}

.toggle-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--ion-color-dark);
    line-height: 1.2;
}

.toggle-sub {
    font-size: 12px;
    color: var(--ion-color-medium);
    margin-top: 2px;
    line-height: 1.2;
}

.modal-footer {
    padding: 16px 16px 8px;

    .apply-btn {
        --border-radius: 12px;
        font-weight: 700;
        font-size: 15px;
        height: 48px;
    }
}

// ─── LOCATION PERMISSION MODAL ────────────────────────────────

.loc-content {
    --background: #0c1a2e;
}

.loc-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 24px 16px;
}

// Pin + animated rings
.loc-pin-wrap {
    position: relative;
    width: 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

@keyframes loc-ring-pulse {
    0%   { transform: scale(1);   opacity: 0.55; }
    70%  { transform: scale(1.9); opacity: 0; }
    100% { transform: scale(1.9); opacity: 0; }
}

.loc-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px solid rgba(245, 158, 11, 0.5);
    animation: loc-ring-pulse 2.4s ease-out infinite;
}

.loc-ring-1 { animation-delay: 0s; }
.loc-ring-2 { animation-delay: 0.7s; }
.loc-ring-3 { animation-delay: 1.4s; }

.loc-glow {
    position: absolute;
    inset: 20px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(245, 158, 11, 0.25) 0%, transparent 70%);
}

.loc-pin {
    position: relative;
    z-index: 2;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(145deg, #f59e0b, #d97706);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2), 0 8px 32px rgba(245, 158, 11, 0.4);

    ion-icon {
        font-size: 26px;
        color: #fff;
    }
}

// Typography
.loc-headline {
    font-size: 22px !important;
    font-weight: 700;
    color: #f1f5f9;
    text-align: center;
    line-height: 1.25;
    margin: 0 0 8px;
    font-family: Georgia, 'Times New Roman', serif;
    letter-spacing: -0.3px;

    em {
        font-style: italic;
        color: #f59e0b;
    }
}

.loc-sub {
    font-size: 13px !important;
    color: rgba(241, 245, 249, 0.6);
    text-align: center;
    line-height: 1.5;
    margin: 0 0 16px;
    max-width: 280px;
}

// Feature rows
.loc-features {
    width: 100%;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 16px;
}

.loc-feature {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);

    &:last-child {
        border-bottom: none;
    }
}

.loc-feat-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: rgba(245, 158, 11, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    ion-icon {
        font-size: 18px;
        color: #f59e0b;
    }
}

.loc-feat-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.loc-feat-title {
    font-size: 13px;
    font-weight: 600;
    color: #f1f5f9;
}

.loc-feat-desc {
    font-size: 11px;
    color: rgba(241, 245, 249, 0.5);
}

// CTA buttons
.loc-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.loc-btn-primary {
    width: 100%;
    height: 46px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, var(--app-brand) 0%, #1a8fd1 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(var(--app-brand-rgb), 0.45);
    transition: opacity 0.15s, transform 0.1s;

    ion-icon {
        font-size: 18px;
    }

    &:active {
        opacity: 0.88;
        transform: scale(0.98);
    }
}

.loc-btn-skip {
    width: 100%;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: rgba(241, 245, 249, 0.45);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    letter-spacing: 0.2px;
    transition: color 0.15s;

    &:active {
        color: rgba(241, 245, 249, 0.7);
    }
}