/* ================================================================
   CRM ESTETICA – Custom CSS
   Bootstrap 5.3 override + componenti custom
   ================================================================ */

/* ── Variabili ─────────────────────────────────────────────────── */
:root {
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --brand-dark:  #1e3a5f;
    --brand-mid:   #2c5282;
    --brand-light: #ebf4ff;
    --surface:     #f8fafc;
    --surface-2:   #f1f5f9;
    --border:      #e2e8f0;
    --text-muted:  #64748b;
    --radius-card: 0.75rem;
    --shadow-card: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-hover: 0 4px 12px rgba(0,0,0,.12);
    --transition:  .18s ease;
}

/* ── Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: .9375rem;
    background: var(--surface);
    color: #1a202c;
    -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--brand-dark);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform var(--transition);
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem 1rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: .25rem;
}

.nav-section-label {
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.4);
    padding: .75rem 1.25rem .25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .55rem 1.25rem;
    color: rgba(255,255,255,.75);
    border-radius: 0;
    font-size: .875rem;
    font-weight: 400;
    transition: all var(--transition);
    margin: 0 .5rem;
    border-radius: .5rem;
}

.nav-link:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.nav-link.active {
    background: rgba(255,255,255,.15);
    color: #fff;
    font-weight: 600;
}

.nav-link .bi {
    font-size: 1rem;
    opacity: .85;
    width: 1.25rem;
    flex-shrink: 0;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.1);
    padding: .5rem 0;
    flex-shrink: 0;
}

.sidebar-footer .avatar-sm {
    width: 32px; height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-footer .fw-semibold,
.sidebar-footer .small {
    color: rgba(255,255,255,.8);
}

.btn-sidebar-logout {
    color: rgba(255,255,255,.5);
    padding: .25rem .4rem;
}
.btn-sidebar-logout:hover { color: #fff; }

/* ── Topbar mobile ─────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: var(--brand-dark);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 1039;
    color: #fff;
    gap: .5rem;
}
.topbar .btn-link { color: #fff; text-decoration: none; }
.topbar .fw-semibold { font-size: 1rem; }

/* ── Main content ──────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 1.75rem 2rem 3rem;
}

@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0;
        padding-top: calc(var(--topbar-height) + 1rem);
    }
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 1039;
    }
    .sidebar-overlay.show { display: block; }
}

/* ── Page header ───────────────────────────────────────────────── */
.page-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--brand-dark);
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    background: #fff;
}
.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
}

/* ── KPI Cards ─────────────────────────────────────────────────── */
.kpi-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 1.25rem 1.5rem;
    transition: box-shadow var(--transition), transform var(--transition);
}
.kpi-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}
.kpi-card .kpi-icon {
    width: 48px; height: 48px;
    border-radius: .625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.375rem;
    margin-bottom: .875rem;
}
.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: .25rem;
}
.kpi-card .kpi-label {
    font-size: .8125rem;
    color: var(--text-muted);
    font-weight: 500;
}

.kpi-primary   .kpi-icon { background: var(--brand-light); color: var(--brand-dark); }
.kpi-success   .kpi-icon { background: #d1fae5; color: #065f46; }
.kpi-warning   .kpi-icon { background: #fef3c7; color: #92400e; }
.kpi-danger    .kpi-icon { background: #fee2e2; color: #991b1b; }
.kpi-info      .kpi-icon { background: #dbeafe; color: #1e40af; }
.kpi-muted     .kpi-icon { background: #f1f5f9; color: #64748b; }

/* ── Tabelle ───────────────────────────────────────────────────── */
.table-crm {
    font-size: .875rem;
}
.table-crm thead th {
    background: var(--surface-2);
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding: .75rem 1rem;
}
.table-crm tbody td {
    padding: .75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}
.table-crm tbody tr:hover td {
    background: var(--surface);
}
.table-crm .actions {
    opacity: 0;
    transition: opacity var(--transition);
}
.table-crm tbody tr:hover .actions {
    opacity: 1;
}

/* ── Badge stati ───────────────────────────────────────────────── */
.badge-status {
    font-size: .7rem;
    font-weight: 600;
    padding: .3em .6em;
    border-radius: .375rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Clienti */
.badge-prospect    { background: #e0e7ff; color: #3730a3; }
.badge-active      { background: #d1fae5; color: #065f46; }
.badge-suspended   { background: #fef3c7; color: #92400e; }
.badge-terminated  { background: #fee2e2; color: #991b1b; }
.badge-to_recover  { background: #fce7f3; color: #9d174d; }

/* Noleggi */
.badge-draft       { background: #f1f5f9; color: #64748b; }
.badge-scheduled   { background: #dbeafe; color: #1e40af; }
.badge-delivering  { background: #fef3c7; color: #92400e; }
.badge-delivered   { background: #d1fae5; color: #065f46; }
.badge-concluded   { background: #f1f5f9; color: #475569; }
.badge-cancelled   { background: #fee2e2; color: #991b1b; }

/* Ticket */
.badge-new         { background: #ede9fe; color: #5b21b6; }
.badge-assigned    { background: #dbeafe; color: #1e40af; }
.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-completed   { background: #d1fae5; color: #065f46; }
.badge-partial     { background: #ffedd5; color: #9a3412; }
.badge-postponed   { background: #f1f5f9; color: #475569; }

/* Ordini */
.badge-to_verify   { background: #ede9fe; color: #5b21b6; }
.badge-confirmed   { background: #dbeafe; color: #1e40af; }
.badge-preparing   { background: #fef3c7; color: #92400e; }
.badge-fulfilled   { background: #d1fae5; color: #065f46; }

/* ── Priorità ticket ───────────────────────────────────────────── */
.priority-1::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; margin-right: .35rem; }
.priority-2::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; margin-right: .35rem; }
.priority-3::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #10b981; margin-right: .35rem; }

/* ── Filter bar ────────────────────────────────────────────────── */
.filter-bar {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-end;
}
.filter-bar .form-control,
.filter-bar .form-select {
    font-size: .875rem;
    min-width: 160px;
    border-color: var(--border);
}
.filter-bar .form-control:focus,
.filter-bar .form-select:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

/* ── Form ──────────────────────────────────────────────────────── */
.form-label {
    font-size: .8125rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: .35rem;
}
.form-control, .form-select {
    border-color: var(--border);
    border-radius: .5rem;
    font-size: .9rem;
}
.form-control:focus, .form-select:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
    font-size: .875rem;
    font-weight: 500;
    border-radius: .5rem;
    padding: .45rem 1rem;
}
.btn-primary {
    background: #0d6efd;
    border-color: #0d6efd;
}
.btn-sm {
    padding: .3rem .7rem;
    font-size: .8rem;
}

/* ── Auth / Login ──────────────────────────────────────────────── */
.auth-body {
    background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand-mid) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-wrapper {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}
.auth-card {
    background: #fff;
    border-radius: 1rem;
    padding: 2.5rem 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.auth-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--brand-dark);
    margin-top: .75rem;
    margin-bottom: .25rem;
}
.auth-logo p { color: var(--text-muted); font-size: .875rem; }

/* ── Timeline storico cliente ──────────────────────────────────── */
.timeline {
    position: relative;
    padding-left: 1.75rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: .5rem;
    top: 0; bottom: 0;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    margin-bottom: 1.25rem;
}
.timeline-dot {
    position: absolute;
    left: -1.25rem;
    top: .35rem;
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #0d6efd;
}
.timeline-dot.rental   { background: #3b82f6; }
.timeline-dot.training { background: #8b5cf6; }
.timeline-dot.order    { background: #10b981; }
.timeline-dot.ticket   { background: #f59e0b; }
.timeline-dot.note     { background: #6b7280; }

.timeline-content {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .625rem;
    padding: .75rem 1rem;
    font-size: .875rem;
}

/* ── Calendario ────────────────────────────────────────────────── */
.calendar-wrapper {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow: hidden;
}
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}
.calendar-day-header {
    padding: .5rem;
    text-align: center;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.calendar-cell {
    min-height: 90px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: .375rem;
    position: relative;
    background: #fff;
    transition: background var(--transition);
}
.calendar-cell:hover { background: var(--surface); }
.calendar-cell.other-month { background: var(--surface); opacity: .6; }
.calendar-cell.today .cell-date {
    background: #0d6efd;
    color: #fff;
    border-radius: 50%;
    width: 24px; height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cell-date {
    font-size: .75rem;
    font-weight: 600;
    margin-bottom: .25rem;
    width: 24px; height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.calendar-event {
    font-size: .7rem;
    padding: .15rem .4rem;
    border-radius: .3rem;
    margin-bottom: .15rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #fff;
    font-weight: 500;
}

/* ── Badge notifiche ───────────────────────────────────────────── */
.badge-notification {
    position: absolute;
    top: -4px; right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: .65rem;
    font-weight: 700;
    width: 18px; height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ── Alerts flash ──────────────────────────────────────────────── */
.alert {
    border-radius: .625rem;
    border: none;
    font-size: .875rem;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger  { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info    { background: #dbeafe; color: #1e40af; }

/* ── Disponibilità calendario ──────────────────────────────────── */
.avail-cell {
    cursor: pointer;
    user-select: none;
}
.avail-cell:hover:not(.avail-past):not(.other-month) {
    background: var(--brand-light);
}
.avail-cell.selected {
    background: #dbeafe !important;
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}
.avail-cell.saved-available {
    background: #f0fdf4;
}
.avail-cell.saved-available .avail-time-indicator { color: #065f46; }
.avail-cell.saved-blocked {
    background: #fff1f2;
}
.avail-cell.saved-blocked .avail-time-indicator { color: #991b1b; }
.avail-cell.avail-weekend { opacity: .5; }
.avail-cell.avail-past    { opacity: .4; cursor: default; }
.avail-time-indicator {
    font-size: .65rem;
    line-height: 1.3;
    margin-top: .2rem;
    overflow: hidden;
}
.avail-legend-dot {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: .3rem;
    background: var(--surface-2);
    border: 1px solid rgba(0,0,0,.1);
}

/* ── Utility ───────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted) !important; }
.section-divider { border-top: 1px solid var(--border); margin: 1.5rem 0; }
