/* components.css — Sidebar, card, table, form, btn, modal, toast */

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

.app__sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--dark2);
    border-right: var(--border-subtle);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.app__main {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    position: relative;
}

.app__main iframe {
    width: 100%;
    height: 100vh;
    border: none;
    display: none;
}

.app__welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    flex-direction: column;
    gap: var(--sp-lg);
}

.app__welcome img {
    max-width: 200px;
    opacity: 0.6;
}

/* ==============================
   SIDEBAR
   ============================== */
.sidebar__header {
    padding: var(--sp-lg) var(--sp-md);
    border-bottom: var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
}

.sidebar__header img {
    height: 32px;
    width: auto;
}

.sidebar__header strong {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--gold);
    font-weight: 400;
}

.sidebar__nav {
    flex: 1;
    padding: var(--sp-md) 0;
    overflow-y: auto;
}

.sidebar__item {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: 12px var(--sp-md) 12px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    user-select: none;
}

.sidebar__item:hover {
    color: var(--light);
    background: rgba(201, 169, 110, 0.05);
}

.sidebar__item--active {
    color: var(--gold);
    background: rgba(201, 169, 110, 0.08);
    border-left-color: var(--gold);
}

.sidebar__item .ico {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.sidebar__divider {
    border: none;
    border-top: var(--border-subtle);
    margin: var(--sp-sm) var(--sp-md);
}

.sidebar__footer {
    padding: var(--sp-md);
    border-top: var(--border-subtle);
}

/* ==============================
   PAGE CONTENT (inside iframe)
   ============================== */
.page {
    padding: var(--sp-lg);
    max-width: 1200px;
}

/* Variante per pagine con tabelle a molte colonne (es. Attività Richieste/Effettuate):
   rimuove il max-width di .page in modo che il contenuto si estenda a tutta la larghezza
   dell'iframe (100vw - sidebar). La leggibilità del testo è gestita dai max-width
   per colonna (.col-descrizione / .col-note). */
.page--wide {
    max-width: none;
}

.page__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-lg);
}

.page__title {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--gold);
    font-weight: 400;
}

/* ==============================
   CARD
   ============================== */
.card {
    background: var(--dark2);
    border: var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: background var(--transition-normal);
}

.card:hover {
    background: var(--dark3);
}

.card__header {
    padding: var(--sp-md) var(--sp-lg);
    border-bottom: var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card__title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    color: var(--gold-light);
}

.card__body {
    padding: var(--sp-lg);
}

/* ==============================
   TABLE
   ============================== */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: var(--border-subtle);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table thead {
    background: var(--dark3);
}

.table th {
    padding: 12px 16px;
    text-align: left;
    color: var(--gold);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--light);
    vertical-align: middle;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

.table tbody tr:hover {
    background: rgba(201, 169, 110, 0.04);
}

.table--striped tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* ==============================
   NOTA CLIENTE → ADMIN
   Blocco read-only mostrato sotto la descrizione dell'intervento, sia nella lista
   cliente sia in Attività Richieste. Non è una colonna: il campo è facoltativo e
   sarebbe vuoto nella maggior parte delle righe.
   ============================== */
.nota-va {
    margin-top: 6px;
    padding: 4px 0 4px 8px;
    border-left: 2px solid var(--gold);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.nota-va__label {
    color: var(--gold);
    font-weight: 500;
}

/* ==============================
   BUTTONS
   ============================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-xs);
    padding: 10px 24px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-normal);
    text-decoration: none;
    white-space: nowrap;
}

.btn--primary {
    background: var(--gold);
    color: var(--dark);
}
.btn--primary:hover {
    background: var(--gold-light);
    box-shadow: 0 0 20px rgba(201, 169, 110, 0.2);
}

.btn--secondary {
    background: transparent;
    color: var(--gold);
    border: var(--border-gold);
}
.btn--secondary:hover {
    background: rgba(201, 169, 110, 0.1);
}

.btn--danger {
    background: transparent;
    color: var(--color-error);
    border: 1px solid rgba(231, 76, 60, 0.3);
}
.btn--danger:hover {
    background: rgba(231, 76, 60, 0.1);
}

.btn--sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.btn--lg {
    padding: 14px 36px;
    font-size: 0.95rem;
}

.btn--block {
    display: flex;
    width: 100%;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ==============================
   FORMS
   ============================== */
.form__group {
    margin-bottom: var(--sp-md);
}

.form__label {
    display: block;
    margin-bottom: var(--sp-xs);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.form__input,
.form__select,
.form__textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--dark3);
    border: 1px solid rgba(201, 169, 110, 0.15);
    border-radius: var(--radius-sm);
    color: var(--light);
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: border-color var(--transition-fast);
    outline: none;
}

.form__input:focus,
.form__select:focus,
.form__textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(201, 169, 110, 0.1);
}

.form__input::placeholder,
.form__textarea::placeholder {
    color: var(--mid);
}

.form__textarea {
    resize: vertical;
    min-height: 100px;
}

.form__select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23c9a96e' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.form__select option {
    background: var(--dark2);
    color: var(--light);
}

.form__row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-md);
}

.form__actions {
    display: flex;
    gap: var(--sp-sm);
    margin-top: var(--sp-lg);
}

.form__error {
    color: var(--color-error);
    font-size: 0.8rem;
    margin-top: var(--sp-xs);
}

/* File input */
.form__file {
    position: relative;
}

.form__file input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    top: 0;
    left: 0;
}

.form__file-label {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: 10px 14px;
    background: var(--dark3);
    border: 1px dashed rgba(201, 169, 110, 0.25);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.form__file-label:hover {
    border-color: var(--gold);
}

/* ==============================
   MODAL
   ============================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal--open {
    display: flex;
}

.modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal__content {
    position: relative;
    background: var(--dark2);
    border: var(--border-subtle);
    border-radius: var(--radius-md);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-modal);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-md) var(--sp-lg);
    border-bottom: var(--border-subtle);
}

.modal__title {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--gold);
}

.modal__close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition-fast);
}
.modal__close:hover {
    color: var(--light);
}

.modal__body {
    padding: var(--sp-lg);
}

.modal__footer {
    padding: var(--sp-md) var(--sp-lg);
    border-top: var(--border-subtle);
    display: flex;
    gap: var(--sp-sm);
    justify-content: flex-end;
}

/* ==============================
   TOAST
   ============================== */
.toast-container {
    position: fixed;
    bottom: var(--sp-lg);
    right: var(--sp-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--white);
    backdrop-filter: blur(12px);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards;
    max-width: 380px;
    box-shadow: var(--shadow-card);
}

.toast--success {
    background: rgba(46, 204, 113, 0.9);
}

.toast--error {
    background: rgba(231, 76, 60, 0.9);
}

.toast--info {
    background: rgba(52, 152, 219, 0.9);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(10px); }
}

/* ==============================
   BADGE
   ============================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
}

.badge--pending {
    background: rgba(201, 169, 110, 0.15);
    color: var(--gold);
}

.badge--active {
    background: rgba(52, 152, 219, 0.15);
    color: var(--color-info);
}

.badge--done {
    background: rgba(46, 204, 113, 0.15);
    color: var(--color-success);
}

.badge--danger {
    background: rgba(231, 76, 60, 0.15);
    color: var(--color-error);
}

/* ==============================
   LOADER
   ============================== */
.loader-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(14, 14, 14, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
}

.loader-overlay--active {
    display: flex;
}

.loader {
    width: 40px;
    height: 40px;
    border: 3px solid var(--dark3);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ====== UPLOAD PROGRESS OVERLAY ====== */
.upload-progress-overlay {
    position: fixed;
    inset: 0;
    z-index: 3001;
    background: rgba(14, 14, 14, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
}

.upload-progress-overlay--active {
    display: flex;
}

.upload-progress-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.upload-progress-label {
    color: var(--gold);
    font-size: 1.1rem;
    font-weight: 600;
}

.upload-progress-bar {
    width: 260px;
    height: 8px;
    background: var(--dark3);
    border-radius: 4px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    width: 0;
    background: var(--gold);
    border-radius: 4px;
    transition: width 0.15s ease;
}

.upload-progress-text {
    color: #fff;
    font-size: 0.9rem;
}

/* ==============================
   LOGIN PAGE
   ============================== */
.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--dark);
}

.login__box {
    width: 100%;
    max-width: 400px;
    padding: var(--sp-xl);
}

.login__logo {
    text-align: center;
    margin-bottom: var(--sp-xl);
}

.login__logo img {
    height: 48px;
    opacity: 0.8;
}

.login__title {
    text-align: center;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--gold);
    margin-bottom: var(--sp-lg);
}

.login__error {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: var(--color-error);
    padding: var(--sp-sm) var(--sp-md);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: var(--sp-md);
    display: none;
}

/* ==============================
   SUMMARY CARDS
   ============================== */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-md);
    margin-bottom: var(--sp-lg);
}

.summary-card {
    background: var(--dark2);
    border: var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--sp-lg);
}

.summary-card__label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: var(--sp-xs);
}

.summary-card__value {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    color: var(--gold);
}

/* ==============================
   EMPTY STATE
   ============================== */
.empty-state {
    text-align: center;
    padding: var(--sp-xl);
    color: var(--text-muted);
}

.empty-state__icon {
    font-size: 3rem;
    margin-bottom: var(--sp-md);
    opacity: 0.5;
}

/* ==============================
   RESPONSIVE
   ============================== */
@media (max-width: 768px) {
    .app__sidebar {
        width: 100%;
        height: auto;
        position: relative;
        min-height: auto;
    }

    .app__main {
        margin-left: 0;
    }

    .app {
        flex-direction: column;
    }

    .page {
        padding: var(--sp-md);
    }

    .form__row {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .modal__content {
        width: 95%;
        max-height: 90vh;
    }
}

/* ==============================
   MEDIA GALLERY
   ============================== */
.media-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0;
    align-items: center;
    max-width: 100%;
    min-width: 0;
}
.media-gallery::-webkit-scrollbar { height: 4px; }
.media-gallery::-webkit-scrollbar-thumb { background: rgba(201,169,110,.4); border-radius: 2px; }
.media-gallery__item {
    position: relative;
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,.15);
    transition: border-color .2s;
}
@media (max-width: 600px) {
    .media-gallery__item { width: 64px; height: 64px; }
}
.media-gallery__item:hover { border-color: var(--gold); }
.media-gallery__item--video { border-color: rgba(201,169,110,.7) !important; }
.media-gallery__item img,
.media-gallery__item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.media-gallery__video-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2a1f0a 0%, #3d2e10 100%);
    border: 2px solid rgba(201,169,110,.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-sizing: border-box;
}
.media-gallery__play {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.4rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(201,169,110,.9);
    box-shadow: 0 0 8px rgba(201,169,110,.5);
    padding-left: 3px;
}
.media-gallery__video-label {
    font-size: 0.55rem;
    color: #e8c97e;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
}
.media-gallery__count {
    flex-shrink: 0;
    background: rgba(201,169,110,.2);
    color: var(--gold);
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* Lightbox */
.media-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0,0,0,.92);
    align-items: center;
    justify-content: center;
}
.media-lightbox__content {
    display: flex;
    align-items: center;
    justify-content: center;
}
.media-lightbox__close {
    position: absolute;
    top: 16px;
    right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    z-index: 10;
}
.media-lightbox__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(201,169,110,.35);
    border: 1px solid rgba(201,169,110,.6);
    color: #fff;
    font-size: 1.6rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background .2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.media-lightbox__arrow:hover { background: rgba(201,169,110,.6); }
.media-lightbox__arrow--left { left: 12px; }
.media-lightbox__arrow--right { right: 12px; }
.media-lightbox__counter {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    background: rgba(0,0,0,.65);
    padding: 5px 16px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.15);
    white-space: nowrap;
    z-index: 10;
}
