/* =============================================================
   admin.css — Stile area amministrativa
   Stesso sistema di variabili del sito pubblico,
   layout a sidebar per desktop, stack verticale su mobile.
   ============================================================= */

/* Importa le variabili globali (già definite in style.css,
   ma qui le ridichariamo per rendere admin.css autonomo) */
:root {
    --cream:      #FAF7F2;
    --beige:      #F0EAE0;
    --beige-dark: #DDD5C8;
    --white:      #FFFFFF;
    --sage:       #8FAE8B;
    --sage-light: #C8D9C5;
    --sage-dark:  #6A8E66;
    --text:       #3A3530;
    --text-muted: #7A746C;
    --text-light: #A09890;
    --error:      #C0625A;
    --success:    #6A8E66;
    --radius:     6px;
    --shadow:     0 1px 4px rgba(0,0,0,0.07);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
    --font:       'Georgia', 'Times New Roman', serif;
    --font-ui:    system-ui, -apple-system, 'Segoe UI', sans-serif;
    --sidebar-w:  230px;
}

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

body {
    font-family: var(--font-ui);
    background: var(--cream);
    color: var(--text);
    line-height: 1.6;
    font-size: 15px;
}

a { color: var(--sage-dark); text-decoration: none; }
a:hover { color: var(--sage); }

h1, h2, h3 { font-family: var(--font); font-weight: normal; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

/* --- Layout admin: sidebar + main --- */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.admin-sidebar {
    width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--beige-dark);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 50;
    overflow-y: auto;
}
.sidebar-logo {
    padding: 1.5rem 1.25rem 1rem;
    border-bottom: 1px solid var(--beige);
}
.sidebar-logo a {
    font-family: var(--font);
    font-size: 1.1rem;
    color: var(--text);
    display: block;
    line-height: 1.3;
}
.sidebar-logo span {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    display: block;
    margin-top: 0.15rem;
}
.sidebar-nav {
    padding: 1rem 0;
    flex: 1;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 1.25rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    border-left: 2px solid transparent;
    transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.sidebar-nav a:hover {
    color: var(--text);
    background: var(--cream);
}
.sidebar-nav a.active {
    color: var(--sage-dark);
    border-left-color: var(--sage);
    background: var(--cream);
    font-weight: 500;
}
.sidebar-nav .nav-icon { font-size: 1rem; width: 1.2rem; text-align: center; }
.sidebar-section-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-light);
    padding: 1rem 1.25rem 0.3rem;
}
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--beige);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.sidebar-footer a { color: var(--error); font-size: 0.8rem; }
.sidebar-footer a:hover { color: #a8504a; }

/* --- Contenuto principale --- */
.admin-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.admin-topbar {
    background: var(--white);
    border-bottom: 1px solid var(--beige-dark);
    padding: 0 2rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}
.admin-topbar h1 { font-size: 1.1rem; font-family: var(--font-ui); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.admin-content { padding: 2rem; flex: 1; }

/* --- Bottoni --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-family: var(--font-ui);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}
.btn-primary { background: var(--sage); color: #fff; border-color: var(--sage); }
.btn-primary:hover { background: var(--sage-dark); border-color: var(--sage-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--beige-dark); }
.btn-outline:hover { background: var(--beige); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; border-color: var(--error); }
.btn-danger:hover { background: #a8504a; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--beige); color: var(--text); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Stat cards (dashboard) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--beige-dark);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.stat-card__label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}
.stat-card__value {
    font-size: 2rem;
    font-family: var(--font);
    color: var(--text);
    line-height: 1;
}
.stat-card__sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}
.stat-card--accent { border-left: 3px solid var(--sage); }

/* --- Tabelle admin --- */
.admin-table-wrap {
    background: var(--white);
    border: 1px solid var(--beige-dark);
    border-radius: var(--radius);
    overflow: hidden;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
}
.admin-table thead { background: var(--beige); }
.admin-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}
.admin-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--beige);
    font-size: 0.875rem;
    vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--cream); }
.admin-table .actions { display: flex; gap: 0.4rem; align-items: center; }
.table-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* --- Badge stato prenotazione --- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-pending   { background: #FEF3CD; color: #856404; }
.badge-confirmed { background: #D1EDD4; color: #2D6A31; }
.badge-cancelled { background: #F5E0DF; color: #8B3530; }

/* --- Pallino colore staff --- */
.staff-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
    flex-shrink: 0;
}

/* --- Card / sezione contenuto --- */
.card {
    background: var(--white);
    border: 1px solid var(--beige-dark);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
}
.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--beige);
}

/* --- Form admin --- */
.form-group { margin-bottom: 1.1rem; }
.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}
.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--cream);
    border: 1px solid var(--beige-dark);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font-ui);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px var(--sage-light);
}
.form-control::placeholder { color: var(--text-light); }
select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237A746C' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.85rem center;
    padding-right: 2.25rem;
    cursor: pointer;
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 0.775rem; color: var(--text-muted); margin-top: 0.3rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* Toggle attivo/inattivo */
.toggle-switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--beige-dark);
    border-radius: 20px;
    cursor: pointer;
    transition: background var(--transition);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    background: #fff;
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: transform var(--transition);
    box-shadow: var(--shadow);
}
input:checked + .toggle-slider { background: var(--sage); }
input:checked + .toggle-slider::before { transform: translateX(16px); }

/* --- Alert --- */
.alert {
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
}
.alert-success { background: #EDF4EC; border-color: #C5DCC3; color: #3A6B37; }
.alert-error   { background: #FAECEA; border-color: #E8B9B5; color: #8B3530; }
.alert-info    { background: #EDF1FA; border-color: #BCC8E8; color: #334A8B; }

/* --- Filtri / toolbar sopra le tabelle --- */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.table-toolbar h2 { font-size: 1rem; font-family: var(--font-ui); font-weight: 600; }
.filter-row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.filter-row select,
.filter-row input[type="date"] {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--beige-dark);
    border-radius: var(--radius);
    font-size: 0.825rem;
    background: var(--white);
    color: var(--text);
    font-family: var(--font-ui);
    cursor: pointer;
}

/* Orari lavoro (form staff) */
.hours-list { display: flex; flex-direction: column; gap: 0.5rem; }
.hour-row {
    display: grid;
    grid-template-columns: 90px 1fr 1fr auto;
    gap: 0.5rem;
    align-items: center;
    background: var(--cream);
    border: 1px solid var(--beige-dark);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}
.hour-row .day-label { font-weight: 500; color: var(--text-muted); font-size: 0.8rem; }

/* --- Hamburger mobile (admin) --- */
.admin-menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-direction: column;
    gap: 5px;
}
.admin-menu-toggle span { display: block; width: 22px; height: 2px; background: var(--text); border-radius: 2px; }

/* --- Responsive admin --- */
@media (max-width: 900px) {
    .admin-sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition);
    }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-main { margin-left: 0; }
    .admin-menu-toggle { display: flex; }
    .admin-content { padding: 1.25rem; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .hour-row { grid-template-columns: 80px 1fr 1fr auto; }
}

@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .admin-table th:nth-child(n+4),
    .admin-table td:nth-child(n+4) { display: none; }
    .filter-row { flex-direction: column; align-items: stretch; }
}

/* Utility */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.d-flex { display: flex; }
.gap-1  { gap: 0.5rem; }
.gap-2  { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.fw-500 { font-weight: 500; }
.fs-sm  { font-size: 0.8rem; }

/* --- Fix area staff: toolbar e navigazione allineate come nell'admin ---
   Senza questo, le pagine senza stat-cards mostrano uno spazio vuoto
   tra la topbar e il primo elemento di contenuto. */
.table-toolbar {
    padding-top: 0;
    margin-top: 0;
}

/* La toolbar filtri occupa subito lo spazio in cima al contenuto */
.table-toolbar + .admin-table-wrap,
.table-toolbar + form + .admin-table-wrap {
    margin-top: 0;
}

/* Badge status in inglese → etichette italiane già gestite in PHP,
   ma forziamo il testo in minuscolo per uniformità visiva */
.badge { text-transform: uppercase; }
/* =============================================================
   MOBILE RESPONSIVE — Tabelle come card verticali
   ============================================================= */

@media (max-width: 768px) {

    /* Nascondi le colonne extra invece di tagliarle */
    .admin-table th:nth-child(n+4),
    .admin-table td:nth-child(n+4) { display: none; }

    /* Trasforma le righe tabella in card verticali */
    .mobile-cards .admin-table,
    .mobile-cards .admin-table thead,
    .mobile-cards .admin-table tbody,
    .mobile-cards .admin-table tr,
    .mobile-cards .admin-table th,
    .mobile-cards .admin-table td {
        display: block;
        width: 100%;
    }
    .mobile-cards .admin-table thead { display: none; }
    .mobile-cards .admin-table-wrap { overflow-x: visible; }

    .mobile-cards .admin-table tr {
        background: var(--white);
        border: 1px solid var(--beige-dark);
        border-radius: 10px;
        padding: 1rem;
        margin-bottom: 0.75rem;
        position: relative;
    }
    .mobile-cards .admin-table td {
        padding: 0.2rem 0;
        font-size: 0.875rem;
        border: none;
    }
    .mobile-cards .admin-table td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-light);
        margin-bottom: 0.1rem;
    }
    /* Prima cella — titolo della card */
    .mobile-cards .admin-table td:first-child {
        font-weight: 700;
        font-size: 1rem;
        color: var(--navy);
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
        border-bottom: 1px solid var(--beige-dark);
    }
    /* Ultima cella — azioni in fondo */
    .mobile-cards .admin-table td:last-child {
        padding-top: 0.75rem;
        margin-top: 0.5rem;
        border-top: 1px solid var(--beige-dark);
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    /* Dashboard stats — 2 colonne */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
    .stat-card  { padding: 1rem; }
    .stat-value { font-size: 1.8rem; }

    /* Topbar */
    .admin-topbar { padding: 0 1rem; }
    .admin-topbar h1 { font-size: 0.95rem; }

    /* Content padding ridotto */
    .admin-content { padding: 1rem; }

    /* Form */
    .form-row, .form-row-3 { grid-template-columns: 1fr; }

    /* Sidebar overlay migliorata */
    .admin-sidebar {
        z-index: 500;
        box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    }

    /* Filtri in colonna */
    .filter-row { flex-direction: column; gap: 0.5rem; }
    .filter-row select,
    .filter-row input { width: 100%; }

    /* Bottoni azioni più grandi su mobile */
    .btn-sm { padding: 0.5rem 0.85rem; font-size: 0.8rem; }

    /* Tabella prenotazioni standard — scroll orizzontale con indicatore */
    .admin-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }
    .admin-table { min-width: 500px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .admin-content { padding: 0.75rem; }
}


/* =============================================================
   FILTRI BARRA COMPATTA
   ============================================================= */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.filter-input {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--beige-dark);
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--white);
    flex: 1;
    min-width: 130px;
    max-width: 200px;
}
.filter-input:focus { outline: none; border-color: var(--green); }

.bookings-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* =============================================================
   CARD PRENOTAZIONI MOBILE
   ============================================================= */
.desktop-only { display: block; }
.mobile-only  { display: none; }

.booking-cards { display: flex; flex-direction: column; gap: 0.75rem; }

.booking-card {
    background: var(--white);
    border: 1px solid var(--beige-dark);
    border-radius: 10px;
    padding: 0.875rem 1rem;
    transition: box-shadow 0.15s ease;
}
.booking-card:active { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.booking-card.cancelled { opacity: 0.55; }

.booking-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--beige);
}
.booking-card-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--navy);
}
.booking-card-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}
.booking-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.booking-card-meta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only  { display: block !important; }

    /* Filtri in griglia compatta */
    .filter-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .filter-input { max-width: 100%; min-width: 0; }
    .filter-bar .btn { height: 38px; }
    .filter-bar .btn:first-of-type { grid-column: 1; }
    .filter-bar .btn:last-of-type  { grid-column: 2; }
}

/* =============================================================
   MOBILE — Pagine Piano, Impostazioni, Codice Amico
   ============================================================= */
@media (max-width: 768px) {

    /* Piano — 1 colonna invece di 3 */
    div[style*="grid-template-columns:repeat(3,1fr)"],
    div[style*="grid-template-columns: repeat(3,1fr)"],
    div[style*="grid-template-columns:repeat(3, 1fr)"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    /* Impostazioni — 1 colonna invece di 2 */
    div[style*="grid-template-columns:1fr 320px"],
    div[style*="grid-template-columns: 1fr 320px"],
    div[style*="grid-template-columns:1fr 300px"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    /* Stats grid codice amico — 1 colonna */
    .stats-grid[style],
    div[style*="grid-template-columns:repeat(3,1fr)"] .stat-card {
        min-width: 0 !important;
    }

    /* Forza larghezza massima su mobile */
    .card { overflow: hidden; }

    /* Select nei form piano */
    select.form-control { width: 100% !important; }

    /* Bottoni piano full width */
    div[style*="grid-template-columns:repeat(3,1fr)"] .btn { width: 100% !important; }
}

/* Griglia piani abbonamento */
.piani-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.piano-attuale-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}
/* Griglia impostazioni */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 768px) {
    .piani-grid    { grid-template-columns: 1fr !important; }
    .settings-grid { grid-template-columns: 1fr !important; }
    .piani-grid .btn { width: 100%; }
    .piani-grid select { width: 100%; }
    .piano-attuale-inner { flex-direction: column; align-items: flex-start; }
}
