:root {
    /* Palette brand Puntosistemi (estratta dal logo aziendale) */
    --blu: #1860a8;        /* blu primario */
    --blu-scuro: #003060;  /* navy intestazioni */
    --azzurro: #00a8f0;    /* azzurro accento */
    --ciano: #60d8f0;      /* ciano chiaro */
    --grigio: #f4f7fb;
    --bordo: #dde5ef;
    --testo: #1f2a3a;
    --muted: #7b879a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--testo);
    background: var(--grigio);
}

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: var(--blu-scuro);
    color: #fff;
    flex-shrink: 0;
}

.nav { padding: 18px 12px; position: sticky; top: 0; }
.nav-brand { display: flex; justify-content: center; margin-bottom: 8px; }
.logo-box { background: #fff; border-radius: 10px; padding: 10px 12px; width: 100%;
    display: inline-flex; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.nav-logo { width: 100%; max-width: 170px; height: auto; display: block; }
.logo-sub { font-size: 12px; opacity: .7; margin-bottom: 18px; text-transform: uppercase; text-align: center; letter-spacing: .5px; }
.nav-aiact { margin-top: 22px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12);
    font-size: 11px; line-height: 1.45; color: #9fb2cd; }
.nav-aiact a { color: var(--azzurro); font-weight: 600; text-decoration: none; }
.nav-aiact a:hover { text-decoration: underline; }
.nav-item {
    display: block; color: #cdd8ea; text-decoration: none;
    padding: 10px 12px; border-radius: 8px; margin-bottom: 4px; font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--blu); color: #fff; font-weight: 600; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 56px; background: #fff; border-bottom: 1px solid var(--bordo);
    display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
}
.topbar .brand { font-size: 15px; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar .role { color: var(--muted); font-size: 12px; }
.logout-form { margin: 0; }

.content { padding: 22px; }

h1 { font-size: 22px; margin: 0 0 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.btn {
    background: var(--blu); color: #fff; border: none; padding: 9px 16px;
    border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--blu-scuro); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-link { background: none; border: none; color: var(--blu); cursor: pointer; font-size: 14px; text-decoration: none; }

table.grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.grid th, .grid td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--bordo); font-size: 13.5px; }
.grid th { background: #f7f9fc; color: #586273; font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .3px; }
.grid tr:last-child td { border-bottom: none; }
.grid .num { text-align: right; white-space: nowrap; }

.badge { background: #eef2f8; color: #44506a; padding: 2px 8px; border-radius: 20px; font-size: 12px; }
.muted { color: var(--muted); font-size: 13px; }

.form-card { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.field { display: flex; flex-direction: column; }
.field.wide { grid-column: span 2; }
.field label { font-size: 12px; color: #586273; margin-bottom: 4px; font-weight: 600; }
.field input, .field select {
    padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; background: #fff;
}
.field input[readonly] { background: #f4f6f9; color: #586273; }
.form-actions { margin-top: 18px; display: flex; gap: 12px; align-items: center; }

.autocomplete { position: relative; margin-top: 6px; }
.autocomplete input { width: 100%; }
.suggestions { list-style: none; margin: 2px 0 0; padding: 0; border: 1px solid var(--bordo); border-radius: 7px; background: #fff; position: absolute; z-index: 10; width: 100%; max-height: 220px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.suggestions li { padding: 8px 10px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f0f2f6; }
.suggestions li:hover { background: #eef4ff; }
.hint { font-size: 12px; color: var(--muted); padding: 4px 2px; }
.maps-link { margin-left: 8px; color: var(--blu); font-weight: 600; text-decoration: none; white-space: nowrap; }
.maps-link:hover { text-decoration: underline; }

.alert { background: #fdecea; color: #b71c1c; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }

/* Campo con pulsante "Crea nuovo" a fianco */
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row select { flex: 1; min-width: 0; }
.btn-add { white-space: nowrap; background: #eef4ff; color: var(--blu); border: 1px solid #cdddf6;
    border-radius: 7px; padding: 0 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-add:hover { background: #dfeaff; }

/* Modale "Crea nuovo" */
.modal-overlay { position: fixed; inset: 0; background: rgba(8,16,32,.5); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; max-height: 90vh;
    display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(0,0,0,.35); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; background: var(--blu-scuro); color: #fff; font-weight: 700; font-size: 15px; }
.modal-x { background: none; border: none; color: #fff; font-size: 16px; cursor: pointer; line-height: 1; opacity: .85; }
.modal-x:hover { opacity: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body .field input { width: 100%; }
.modal-err { padding: 0 18px 6px; color: #b71c1c; font-size: 13px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--bordo); display: flex; gap: 12px; align-items: center; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { background: #fff; border: 1px solid var(--bordo); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.tab.active { background: var(--blu); color: #fff; border-color: var(--blu); }

.inline-add { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.inline-add input { padding: 8px 10px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; }
.inline-add input.small { width: 70px; }
.wide-input { flex: 1; min-width: 280px; }

.hits { list-style: none; padding: 0; margin: 14px 0 0; }
.hits li { background: #fff; border: 1px solid var(--bordo); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.hit-score { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.hit-text { font-size: 14px; line-height: 1.5; }

/* Login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--blu-scuro), var(--blu)); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-logo { font-size: 24px; font-weight: 700; color: var(--blu); }
.login-tenant { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; }
.login-card label { font-size: 12px; color: #586273; margin: 10px 0 4px; font-weight: 600; }
.login-card input { padding: 9px 11px; border: 1px solid var(--bordo); border-radius: 7px; font-size: 14px; }
.login-btn { margin-top: 18px; width: 100%; padding: 11px; }
.login-hint { margin-top: 16px; text-align: center; }

h2.sub { font-size: 15px; color: #586273; margin: 4px 0 12px; font-weight: 600; }
.small { font-size: 12px; }

/* Azioni CRUD nelle tabelle */
.grid th.actions, .grid td.actions { width: 1%; white-space: nowrap; text-align: right; }
.grid td.actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.grid td.actions form { margin: 0; display: inline; }
.icon-btn { background: #eef2f8; border: 1px solid var(--bordo); border-radius: 6px; padding: 3px 7px; cursor: pointer; font-size: 13px; text-decoration: none; line-height: 1.4; }
.icon-btn:hover { background: #e1e8f4; }
.btn-danger { background: #fff; color: #b71c1c; border: 1px solid #f0c4c0; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn-danger:hover { background: #fdecea; }
.delete-row { margin-top: 12px; }

/* Calendario settimanale */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cal-range { font-weight: 600; color: var(--testo); }
.cal-arrow { background: #fff; border: 1px solid var(--bordo); border-radius: 8px; padding: 8px 14px; text-decoration: none; color: var(--blu); font-size: 14px; }
.cal-arrow:hover { background: #eef4ff; }

.cal-wrap { display: flex; gap: 12px; align-items: flex-start; }
.cal-unassigned { width: 210px; flex-shrink: 0; background: #fff; border: 1px solid var(--bordo); border-radius: 10px; padding: 10px; min-height: 120px; }
.cal-unassigned h3 { margin: 0 0 6px; font-size: 14px; }
.cal-grid { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; min-width: 0; }
.cal-col { background: #fff; border: 1px solid var(--bordo); border-radius: 10px; display: flex; flex-direction: column; min-height: 220px; }
.cal-col.today { border-color: var(--blu); box-shadow: 0 0 0 2px rgba(13,71,161,.12); }
.cal-colhead { padding: 8px 10px; border-bottom: 1px solid var(--bordo); font-size: 12px; font-weight: 600; color: #586273; display: flex; justify-content: space-between; }
.cal-colhead span { color: var(--muted); font-weight: 400; }
.cal-drop { padding: 8px; display: flex; flex-direction: column; gap: 7px; flex: 1; }

.trip-card { position: relative; background: #eef4ff; border: 1px solid #cdddf6; border-left: 3px solid var(--blu); border-radius: 7px; padding: 7px 8px; font-size: 12px; cursor: grab; }
.trip-card:active { cursor: grabbing; }
.trip-card.dragging { opacity: .45; }
.trip-num { font-weight: 700; color: var(--blu-scuro); }
.trip-cli { font-weight: 600; margin-top: 1px; }
.trip-tratta { color: #586273; }

/* Badge esecutore: colore di fondo uniforme per tipologia */
.trip-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.trip-badge { font-weight: 800; font-size: 11px; letter-spacing: .4px; line-height: 1;
    padding: 3px 7px; border-radius: 5px; color: #fff; text-transform: uppercase; white-space: nowrap; }
.trip-badge.mezzo { background: #1860a8; }     /* mezzi propri */
.trip-badge.vettore { background: #e06f00; }   /* vettori esterni */
.trip-badge.nd { background: #8a94a6; }        /* esecutore non assegnato */
.trip-warn { margin-left: auto; color: #d92d20; font-size: 14px; line-height: 1; }
.tip-warn { color: #ffb4b4; font-weight: 600; }

.trip-card.conflict { border-color: #f0a3a3; border-left-color: #d92d20;
    background: #fff5f5; box-shadow: 0 0 0 1px rgba(217,45,32,.15); }

/* Legenda calendario */
.cal-legend { display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
    font-size: 12px; color: var(--muted); margin: 4px 0 12px; }
.cal-legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px;
    vertical-align: middle; margin-right: 5px; }
.cal-legend .lg.mezzo { background: #1860a8; }
.cal-legend .lg.vettore { background: #e06f00; }
.cal-legend .lg.warn { width: auto; height: auto; background: none; color: #d92d20; font-style: normal; }

.trip-tip { display: none; position: absolute; left: 100%; top: 0; margin-left: 8px; width: 240px; background: #1f2430; color: #fff; padding: 9px 11px; border-radius: 8px; font-size: 12px; line-height: 1.55; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.trip-card:hover .trip-tip { display: block; }
.cal-unassigned .trip-tip { left: auto; right: 100%; margin-left: 0; margin-right: 8px; }

.drop-hi { outline: 2px dashed var(--blu); outline-offset: -2px; background: #f3f8ff; }
.cal-arrow.drop-hi { background: #dbe9ff; }

@media (max-width: 1100px) {
    .cal-grid { grid-template-columns: repeat(7, minmax(95px, 1fr)); overflow-x: auto; }
}

@media (max-width: 760px) {
    .sidebar { width: 64px; }
    .logo-sub, .nav-item { font-size: 0; }
    .nav-item { text-align: center; }
    .logo-box { padding: 5px; }
    .nav-logo { max-width: 40px; }
    .nav-aiact { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .field.wide { grid-column: span 1; }
}
