/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:       #2563eb;
    --primary-dark:  #1d4ed8;
    --primary-light: #eff6ff;
    --danger:        #dc2626;
    --danger-light:  #fef2f2;
    --success:       #16a34a;
    --success-light: #f0fdf4;
    --warning:       #d97706;
    --warning-light: #fffbeb;
    --gray-50:       #f9fafb;
    --gray-100:      #f3f4f6;
    --gray-200:      #e5e7eb;
    --gray-300:      #d1d5db;
    --gray-400:      #9ca3af;
    --gray-500:      #6b7280;
    --gray-600:      #4b5563;
    --gray-700:      #374151;
    --gray-800:      #1f2937;
    --gray-900:      #111827;
    --header-h:      64px;
    --radius:        8px;
    --shadow:        0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg:     0 10px 15px rgba(0,0,0,.10), 0 4px 6px rgba(0,0,0,.05);
    --font:          'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ============================================================
   HEADER
   ============================================================ */
.header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    z-index: 1000;
}
.header-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 100%;
    padding: 0 24px;
}
.header-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
    flex-shrink: 0;
}
.header-logo:hover { color: var(--primary-dark); }

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}
.nav-link {
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: .9rem;
    color: var(--gray-600);
    transition: background .15s, color .15s;
}
.nav-link:hover  { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

/* ============================================================
   PULSANTI
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-dark); }

.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover:not(:disabled){ background: var(--gray-300); }

.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; }

.btn-success   { background: var(--success);  color: #fff; }
.btn-success:hover:not(:disabled)  { background: #15803d; }

.btn-outline {
    background: #fff;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }

.btn-sm { padding: 5px 10px; font-size: .8rem; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    margin-top: var(--header-h);
    padding: 28px 24px;
    min-height: calc(100vh - var(--header-h));
}

/* ============================================================
   CARD
   ============================================================ */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 16px;
}

/* ============================================================
   FILTRI
   ============================================================ */
.filtri-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 20px;
}
.filtro-gruppo {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 160px;
}
.filtro-gruppo label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.filtro-gruppo input,
.filtro-gruppo select {
    padding: 7px 10px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: .875rem;
    color: var(--gray-800);
    background: #fff;
    transition: border-color .15s;
}
.filtro-gruppo input:focus,
.filtro-gruppo select:focus {
    outline: none;
    border-color: var(--primary);
}
.filtri-azioni {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

/* ============================================================
   TABELLA CARICAMENTI (homepage)
   ============================================================ */
.tabella-wrapper {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.tabella {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.tabella thead th {
    background: var(--gray-50);
    padding: 11px 16px;
    text-align: left;
    font-size: .78rem;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}
.tabella tbody tr {
    border-bottom: 1px solid var(--gray-100);
    transition: background .1s;
}
.tabella tbody tr:last-child { border-bottom: none; }
.tabella tbody tr:hover { background: var(--gray-50); }
.tabella tbody td {
    padding: 12px 16px;
    color: var(--gray-700);
    vertical-align: middle;
}
.tabella .azioni {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

/* stato vuoto */
.tabella-vuota {
    text-align: center;
    padding: 48px 16px;
    color: var(--gray-400);
    width: 100%;
    box-sizing: border-box;
}
.tabella-vuota .vuota-icon { font-size: 2.5rem; margin-bottom: 8px; }
.tabella-vuota p { font-size: .9rem; }

/* ============================================================
   PAGINAZIONE
   ============================================================ */
.paginazione {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-top: 1px solid var(--gray-100);
    font-size: .85rem;
    color: var(--gray-500);
}
.paginazione-links { display: flex; gap: 4px; }
.paginazione-links a,
.paginazione-links span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    font-size: .85rem;
    font-weight: 500;
}
.paginazione-links a { color: var(--gray-600); transition: background .15s; }
.paginazione-links a:hover { background: var(--gray-100); }
.paginazione-links span.corrente {
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

/* ============================================================
   POPUP / OVERLAY
   ============================================================ */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1100;
}
.overlay.visible { display: block; }

.popup {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 480px;
    max-width: calc(100vw - 32px);
    z-index: 1200;
}
.popup.visible { display: flex; flex-direction: column; overflow: visible; }

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--gray-200);
}
.popup-header h3 { font-size: 1rem; font-weight: 700; }
.popup-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}
.popup-close:hover { color: var(--gray-700); background: var(--gray-100); }

.popup-body { padding: 20px; flex: 1; overflow: visible; }
.popup-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* ============================================================
   UPLOAD AREA
   ============================================================ */
.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    margin-top: 12px;
}
.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-icon { font-size: 2rem; display: block; margin-bottom: 8px; }
.upload-placeholder p { font-size: .9rem; color: var(--gray-500); }
.upload-placeholder small { color: var(--gray-400); }
.upload-selected p { font-size: .9rem; color: var(--gray-700); font-weight: 500; }

.upload-errore {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--danger-light);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--danger);
    font-size: .85rem;
}

/* ============================================================
   NOTIFICHE TOAST
   ============================================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}
.toast {
    padding: 12px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: .875rem;
    font-weight: 500;
    color: #fff;
    animation: slideIn .25s ease;
    max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }

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

/* ============================================================
   BADGE
   ============================================================ */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-blue  { background: var(--primary-light); color: var(--primary); }
.badge-gray  { background: var(--gray-100);      color: var(--gray-600); }
.badge-green { background: var(--success-light); color: var(--success); }

/* ============================================================
   UTILITIES
   ============================================================ */
.mt-4  { margin-top:  4px; }
.mt-8  { margin-top:  8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-16{ gap: 16px; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-400); font-size: .85rem; }
.fw-bold { font-weight: 700; }

/* ============================================================
   STATUS CARICAMENTO
   ============================================================ */
.status-badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 999px;
    font-size: .75rem; font-weight: 700; letter-spacing: .02em;
    white-space: nowrap;
}
.status-caricato       { background: #e0e7ff; color: #3730a3; }
.status-in-lavorazione { background: #fef9c3; color: #854d0e; }
.status-pronto         { background: #dcfce7; color: #166534; }
.status-chiuso         { background: #f1f5f9; color: #475569; }

/* Wrapper status nel breadcrumb */
.status-caricamento-wrap select {
    border-radius: var(--radius);
    background: #fff;
}

/* Cella HTML nella tabella caricamento */
.td-html {
    min-width: 560px;
    max-width: 760px;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    vertical-align: top !important;
    line-height: 1.55;
    height: auto !important;
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}
.td-html p, .td-html ul, .td-html ol { margin: 0 0 4px; }
.td-html ul, .td-html ol { padding-left: 1.3em; }
