/* ============================================================
   CarKPI — app.css  |  UI moderna, chiara, leggibile
   Sidebar: nera  |  Contenuto: bianco/grigio chiaro
   ============================================================ */

:root {
    --ck-primary:        #1E3A5F;
    --ck-primary-light:  #2E75B6;
    --ck-accent:         #16A34A;
    --ck-purple:         #7C3AED;
    --ck-orange:         #EA580C;
    --ck-danger:         #DC2626;
    --ck-warning:        #D97706;
    --ck-info:           #0284C7;

    --ck-bg:             #F8FAFC;
    --ck-sidebar-bg:     #000000;
    --ck-sidebar-width:  260px;
    --ck-topbar-height:  60px;
    --ck-card-radius:    10px;
    --ck-shadow:         0 1px 8px rgba(0,0,0,.06);
    --ck-shadow-md:      0 4px 16px rgba(0,0,0,.08);
    --ck-transition:     .18s ease;

    --ck-font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --ck-font-size:      14px;
    --ck-line-height:    1.6;

    /* Testo */
    --ck-text:           #111827;
    --ck-text-secondary: #6B7280;
    --ck-border:         #E5E7EB;
}

/* ── RESET ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--ck-font-size); scroll-behavior: smooth; }
body {
    font-family: var(--ck-font);
    background: var(--ck-bg);
    color: var(--ck-text);
    line-height: var(--ck-line-height);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--ck-primary-light); text-decoration: none; }
a:hover { color: var(--ck-primary); }

/* ── LAYOUT ─────────────────────────────────────────────────── */
#wrapper { min-height: 100vh; }

#page-content-wrapper {
    margin-left: var(--ck-sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--ck-transition);
}

/* ── SIDEBAR — nera come richiesto ───────────────────────────── */
.sidebar {
    width: var(--ck-sidebar-width);
    min-height: 100vh;
    background: var(--ck-sidebar-bg);
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width var(--ck-transition);
    overflow: hidden;
}

.sidebar-header {
    height: var(--ck-topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
    background: #000; /* sempre nero — il logo lo richiede */
}

/* Logo nella sidebar */
.sidebar-brand { display: flex; align-items: center; text-decoration: none; }

.brand-logo-full {
    display: block;
    height: 36px;
    width: auto;
    /* nessun background extra — la sidebar-header è già nera */
}
.brand-logo-mini {
    display: none !important;
    height: 32px;
    width: 32px;
    object-fit: contain;
    border-radius: 6px;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.4);
    font-size: 1rem;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: color var(--ck-transition);
}
.sidebar-toggle:hover { color: white; }

/* Tenant info */
.sidebar-tenant {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.tenant-name {
    color: white;
    font-weight: 600;
    font-size: .84rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tenant-location {
    color: rgba(255,255,255,.45);
    font-size: .74rem;
    margin-bottom: 4px;
}

/* Nav items */
.sidebar-nav {
    list-style: none;
    padding: 8px 10px;
    margin: 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }

.nav-item .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: rgba(255,255,255,.6);
    font-size: .875rem;
    font-weight: 450;
    border-radius: 8px;
    transition: all var(--ck-transition);
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    margin-bottom: 2px;
}
.nav-item .nav-link:hover {
    color: white;
    background: rgba(255,255,255,.08);
}
.nav-item.active .nav-link,
.nav-item .nav-link.active {
    color: white;
    background: var(--ck-primary-light);
    font-weight: 600;
}
.nav-icon {
    width: 18px;
    text-align: center;
    font-size: .875rem;
    flex-shrink: 0;
    opacity: .85;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-item.coming-soon .nav-link { opacity: .35; cursor: not-allowed; }
.nav-item.locked .nav-link { opacity: .45; }
.nav-lock { font-size: .68rem; opacity: .6; }
.nav-badge { font-size: .65rem; }

/* Sidebar bottom */
.sidebar-bottom {
    border-top: 1px solid rgba(255,255,255,.06);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.lang-switcher { font-size: .78rem; color: rgba(255,255,255,.35); }
.lang-switcher a { color: rgba(255,255,255,.35); }
.lang-switcher a.active,
.lang-switcher a:hover { color: white; }
.btn-logout {
    color: rgba(255,255,255,.4);
    font-size: .8rem;
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: color var(--ck-transition);
}
.btn-logout:hover { color: #F87171; }

/* Collapsed */
.sidebar-collapsed .sidebar             { width: 60px; }
.sidebar-collapsed #page-content-wrapper { margin-left: 60px; }
.sidebar-collapsed .nav-label,
.sidebar-collapsed .tenant-name,
.sidebar-collapsed .tenant-location,
.sidebar-collapsed .sidebar-bottom .nav-label { display: none; }
.sidebar-collapsed .sidebar-brand       { justify-content: center; }
.sidebar-collapsed .sidebar-bottom      { justify-content: center; }
.sidebar-collapsed .sidebar-toggle      { margin: 0 auto; }
.sidebar-collapsed .sidebar-nav         { padding: 8px 6px; }
.sidebar-collapsed .nav-item .nav-link  { justify-content: center; padding: 10px; }
.sidebar-collapsed .sidebar-tenant      { display: none; }
/* Logo */
.sidebar-collapsed .brand-logo-full { display: none !important; }
.sidebar-collapsed .brand-logo-mini { display: block !important; }

/* ── TOPBAR ─────────────────────────────────────────────────── */
.topbar {
    height: var(--ck-topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--ck-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.topbar-breadcrumb .breadcrumb { font-size: .82rem; margin-bottom: 0; }
.topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before { color: #D1D5DB; }
.topbar-breadcrumb .breadcrumb-item a { color: var(--ck-primary-light); }
.topbar-breadcrumb .breadcrumb-item.active { color: var(--ck-text-secondary); }

.btn-user {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1.5px solid var(--ck-border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: .875rem;
    color: var(--ck-text);
    transition: all var(--ck-transition);
    cursor: pointer;
}
.btn-user:hover { border-color: #9CA3AF; background: #F9FAFB; }

.user-avatar {
    width: 28px;
    height: 28px;
    background: var(--ck-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .78rem;
    flex-shrink: 0;
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1.5px solid var(--ck-border);
    border-radius: 8px;
    color: #6B7280;
    transition: all var(--ck-transition);
    cursor: pointer;
    padding: 0;
}
.btn-icon:hover { background: #F9FAFB; color: var(--ck-primary); border-color: #9CA3AF; }

.notification-badge {
    position: absolute;
    top: -3px; right: -3px;
    background: var(--ck-danger);
    color: white;
    border-radius: 50%;
    width: 16px; height: 16px;
    font-size: .62rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}
.notification-dropdown { width: 300px; padding: 0; }
.notification-dropdown .dropdown-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: .82rem;
    border-bottom: 1px solid var(--ck-border);
}

/* ── MAIN ───────────────────────────────────────────────────── */
main { flex: 1; padding: 24px !important; background: var(--ck-bg); }

/* ── FOOTER ─────────────────────────────────────────────────── */
.app-footer {
    padding: 12px 24px;
    font-size: .75rem;
    color: #9CA3AF;
    border-top: 1px solid var(--ck-border);
    background: #fff;
    flex-shrink: 0;
}

/* ── CARDS ───────────────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid var(--ck-border);
    border-radius: var(--ck-card-radius);
    box-shadow: var(--ck-shadow);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid var(--ck-border);
    padding: 14px 20px;
    font-weight: 600;
    font-size: .9rem;
    color: var(--ck-text);
    border-radius: var(--ck-card-radius) var(--ck-card-radius) 0 0 !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.card-body { padding: 20px; }

/* ── KPI CARDS ──────────────────────────────────────────────── */
.kpi-card {
    background: #fff;
    border: 1px solid var(--ck-border);
    border-radius: var(--ck-card-radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--ck-transition), transform var(--ck-transition);
}
.kpi-card:hover { box-shadow: var(--ck-shadow-md); transform: translateY(-1px); }
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--ck-primary-light);
    border-radius: var(--ck-card-radius) var(--ck-card-radius) 0 0;
}
.kpi-card.accent-green::before  { background: var(--ck-accent); }
.kpi-card.accent-orange::before { background: var(--ck-orange); }
.kpi-card.accent-purple::before { background: var(--ck-purple); }

.kpi-label {
    font-size: .74rem;
    font-weight: 700;
    color: var(--ck-text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 8px;
}
.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--ck-text);
    line-height: 1.2;
    margin-bottom: 6px;
}
.kpi-delta {
    font-size: .78rem;
    display: flex;
    align-items: center;
    gap: 4px;
}
.kpi-delta.up   { color: var(--ck-accent); }
.kpi-delta.down { color: var(--ck-danger); }
.kpi-icon {
    position: absolute;
    top: 16px; right: 16px;
    width: 40px; height: 40px;
    border-radius: 10px;
    background: #F1F5F9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--ck-primary-light);
}

/* ── FORM — chiari e leggibili ──────────────────────────────── */
.form-label {
    font-size: .84rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
}
.form-control, .form-select {
    background: #fff;
    border: 1.5px solid #D1D5DB;
    border-radius: 8px;
    color: #111827;
    font-size: .9rem;
    padding: 9px 12px;
    transition: border-color var(--ck-transition), box-shadow var(--ck-transition);
}
.form-control:focus, .form-select:focus {
    background: #fff;
    border-color: var(--ck-primary-light);
    box-shadow: 0 0 0 3px rgba(46,117,182,.12);
    color: #111827;
    outline: none;
}
.form-control::placeholder { color: #9CA3AF; }
.form-control.is-invalid   { border-color: var(--ck-danger); }
.invalid-feedback          { font-size: .78rem; color: var(--ck-danger); }

.input-group-text {
    background: #F9FAFB;
    border: 1.5px solid #D1D5DB;
    color: #6B7280;
    font-size: .875rem;
}
.input-group .form-control:not(:first-child)  { border-left: none; }
.input-group .form-control:not(:last-child)   { border-right: none; }
.input-group .input-group-text:first-child    { border-right: none; }
.input-group .input-group-text:last-child     { border-left: none; }

.required-star::after { content: ' *'; color: var(--ck-danger); }

/* Form switch */
.form-check-input:checked { background-color: var(--ck-primary-light); border-color: var(--ck-primary-light); }
.form-check-label { color: #374151; font-size: .875rem; }

/* Select2 */
.select2-container--bootstrap-5 .select2-selection {
    border: 1.5px solid #D1D5DB !important;
    border-radius: 8px !important;
    background: #fff !important;
    color: #111827 !important;
    font-size: .9rem !important;
    min-height: 40px !important;
}
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    color: #111827 !important;
    padding: 4px 8px !important;
}

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
    font-size: .875rem;
    font-weight: 500;
    border-radius: 8px;
    padding: 8px 16px;
    transition: all var(--ck-transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-primary {
    background: var(--ck-primary-light);
    border-color: var(--ck-primary-light);
    color: #fff;
}
.btn-primary:hover { background: var(--ck-primary); border-color: var(--ck-primary); color: #fff; }
.btn-success { background: var(--ck-accent); border-color: var(--ck-accent); color: #fff; }
.btn-sm   { padding: 5px 10px; font-size: .8rem; }
.btn-lg   { padding: 10px 22px; font-size: .95rem; }
.btn-outline-secondary { border-color: #D1D5DB; color: #374151; }
.btn-outline-secondary:hover { background: #F9FAFB; color: #111827; border-color: #9CA3AF; }

/* ── DATATABLE ──────────────────────────────────────────────── */
.dt-wrapper .card-header { flex-wrap: wrap; gap: 8px; }
.dt-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

table.dataTable { border-collapse: collapse !important; }
table.dataTable thead th {
    background: var(--ck-primary);
    color: white;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .3px;
    border: none !important;
    padding: 11px 14px;
    white-space: nowrap;
}
table.dataTable tbody tr:hover { background: #F8FAFC !important; }
table.dataTable tbody td {
    padding: 10px 14px;
    font-size: .875rem;
    vertical-align: middle;
    color: var(--ck-text);
    border-bottom: 1px solid #F3F4F6 !important;
}

.dt-action-btn {
    width: 30px; height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1.5px solid #E5E7EB;
    background: #fff;
    color: #6B7280;
    font-size: .8rem;
    transition: all var(--ck-transition);
    cursor: pointer;
    text-decoration: none;
}
.dt-action-btn:hover { border-color: var(--ck-primary-light); color: var(--ck-primary-light); background: #EFF6FF; }
.dt-action-btn.delete:hover { border-color: var(--ck-danger); color: var(--ck-danger); background: #FEF2F2; }

/* DataTables UI */
.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label,
.dataTables_wrapper .dataTables_info { color: #6B7280; font-size: .82rem; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1.5px solid #D1D5DB !important;
    border-radius: 6px !important;
    color: #111827 !important;
    background: #fff !important;
    padding: 4px 10px !important;
    font-size: .85rem !important;
}

/* ── WIZARD ─────────────────────────────────────────────────── */
.wizard-steps {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 0 28px;
}
.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
}
.wizard-step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 15px;
    left: 50%;
    width: 100%;
    height: 2px;
    background: #E5E7EB;
    z-index: 0;
    transition: background var(--ck-transition);
}
.wizard-step.completed::after { background: var(--ck-accent); }
.step-circle {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 2px solid #E5E7EB;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 700;
    color: #9CA3AF;
    position: relative;
    z-index: 1;
    transition: all var(--ck-transition);
}
.wizard-step.active .step-circle {
    border-color: var(--ck-primary-light);
    background: var(--ck-primary-light);
    color: white;
    box-shadow: 0 0 0 4px rgba(46,117,182,.15);
}
.wizard-step.completed .step-circle {
    border-color: var(--ck-accent);
    background: var(--ck-accent);
    color: white;
}
.step-label {
    font-size: .72rem;
    color: #9CA3AF;
    margin-top: 6px;
    text-align: center;
    font-weight: 500;
}
.wizard-step.active .step-label    { color: var(--ck-primary-light); font-weight: 600; }
.wizard-step.completed .step-label { color: var(--ck-accent); }
.wizard-pane    { display: none; }
.wizard-pane.active { display: block; }
.wizard-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 0;
    border-top: 1px solid #F3F4F6;
    margin-top: 20px;
}

/* ── BADGES ─────────────────────────────────────────────────── */
.badge { font-size: .72rem; font-weight: 600; padding: 4px 8px; border-radius: 5px; }
.bg-purple { background-color: var(--ck-purple) !important; }

/* ── ALERTS ─────────────────────────────────────────────────── */
.alert {
    border: none;
    border-radius: 8px;
    font-size: .875rem;
    padding: 12px 16px;
    border-left: 4px solid transparent;
}
.alert-success { background: #F0FDF4; color: #166534; border-left-color: var(--ck-accent); }
.alert-danger  { background: #FEF2F2; color: #991B1B; border-left-color: var(--ck-danger); }
.alert-warning { background: #FFFBEB; color: #92400E; border-left-color: var(--ck-warning); }
.alert-info    { background: #EFF6FF; color: #1E40AF; border-left-color: var(--ck-info); }

/* ── MODAL ──────────────────────────────────────────────────── */
.modal-content { border: none; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.15); background: #fff; }
.modal-header  { border-bottom: 1px solid #F3F4F6; padding: 16px 20px; }
.modal-footer  { border-top: 1px solid #F3F4F6; }
.modal-title   { font-weight: 600; color: var(--ck-text); }
.bg-gradient-primary { background: linear-gradient(135deg, var(--ck-primary) 0%, var(--ck-primary-light) 100%); }

/* ── PAGE HEADER ────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title    { font-size: 1.3rem; font-weight: 700; color: var(--ck-text); margin: 0; }
.page-subtitle { font-size: .82rem; color: var(--ck-text-secondary); margin: 2px 0 0; }

/* ── DRAG & DROP ────────────────────────────────────────────── */
.sortable-ghost { opacity: .4; }
.drag-handle    { cursor: grab; color: #D1D5DB; }
.drag-handle:hover { color: #6B7280; }

/* ── MODULE LOCKED ──────────────────────────────────────────── */
.module-locked { position: relative; overflow: hidden; }
.module-locked::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.75);
    backdrop-filter: blur(3px);
    z-index: 10;
}
.lock-overlay {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 11; gap: 12px;
}

/* ── UTILITIES ──────────────────────────────────────────────── */
.text-primary-ck { color: var(--ck-primary) !important; }
.text-accent     { color: var(--ck-accent)  !important; }
.bg-ck-light     { background: var(--ck-bg) !important; }
.border-start-primary { border-left: 4px solid var(--ck-primary-light) !important; }
.border-start-success { border-left: 4px solid var(--ck-accent)        !important; }
.border-start-danger  { border-left: 4px solid var(--ck-danger)        !important; }
.shadow-sm-ck         { box-shadow: var(--ck-shadow); }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
.sidebar-toggle-mobile { display: none; }

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1050;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.3);
    }
    #page-content-wrapper { margin-left: 0 !important; }
    .sidebar-toggle-mobile { display: flex; }
    .sidebar-toggle        { display: none; }
    main { padding: 16px !important; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .topbar { padding: 0 16px; }
    .kpi-value { font-size: 1.4rem; }
    .step-label { display: none; }
}
