/* ============================================================
   ALUMAT — Fogli di stile condivisi (HTMX edition)
   Estratti dal blocco <style> di app.html, riorganizzati.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #eae8e3;
    color: #1a1a18;
    font-size: 13px;
}

/* ─── LAYOUT PRINCIPALE ─────────────────────────────────────── */

.app {
    display: flex;
    height: 100vh;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #eae8e3;
}

/* ─── SIDEBAR ───────────────────────────────────────────────── */

.sb {
    flex-shrink: 0;
    background: #2c4a6e;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 222px;
    transition: width .22s;
}
.app.sidebar-collapsed .sb { width: 54px; }

.sb-header {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    display: flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
}
.sb-brand-icon {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sb-brand-icon img {
    display: block;
    width: 32px;
    height: 32px;
    object-fit: contain;
}
.sb-brand-text       { flex: 1; min-width: 0; }
.sb-brand-title      { color: #d8eaf7; font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.sb-brand-subtitle   { font-size: 9.5px; color: #4e7a9e; }
.sb-toggle {
    width: 24px;
    height: 24px;
    border: .5px solid rgba(255,255,255,.18);
    border-radius: 7px;
    background: rgba(255,255,255,.06);
    color: #d8eaf7;
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sb-toggle:hover { background: rgba(255,255,255,.12); }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 0; }

.sb-link {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 7px 14px;
    background: none; border: none;
    border-left: 3px solid transparent;
    color: #8ab4d4;
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
}
.sb-link:hover { background: rgba(255, 255, 255, .05); }
.sb-link.is-active {
    background: rgba(192, 57, 43, .2);
    border-left-color: #c0392b;
    color: #fff;
}

.sb-group-header {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 7px 14px;
    background: none; border: none;
    border-left: 3px solid transparent;
    color: #8ab4d4;
    font-size: 12px;
    cursor: pointer;
    text-align: left;
}
.sb-group-header:hover { background: rgba(255, 255, 255, .05); }
.sb-group-header.is-active { color: #fff; font-weight: 500; }
.sb-group-children {
    background: rgba(0, 0, 0, .12);
}
.sb-sublink {
    display: flex; align-items: center; gap: 7px;
    width: 100%; padding: 6px 14px 6px 33px;
    background: none; border: none;
    border-left: 3px solid transparent;
    color: #5e8bb0;
    font-size: 11.5px;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
}
.sb-sublink:hover { background: rgba(0, 0, 0, .18); }
.sb-sublink.is-active {
    background: rgba(192, 57, 43, .12);
    border-left-color: #c0392b;
    color: #fff;
}
.app.sidebar-collapsed .sb-header {
    padding: 11px;
    justify-content: center;
    flex-wrap: wrap;
}
.app.sidebar-collapsed .sb-brand-text,
.app.sidebar-collapsed .sb-nav {
    display: none;
}
.app.sidebar-collapsed .sb-toggle {
    transform: rotate(180deg);
}

/* ─── TOPBAR ────────────────────────────────────────────────── */

.tb {
    background: #fff;
    border-bottom: .5px solid rgba(0, 0, 0, .1);
    padding: 0 16px;
    height: 46px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.tb .title { font-size: 13px; font-weight: 500; flex: 1; }
.tb .muted { font-size: 11px; color: #888; }

/* ─── BOTTONI ───────────────────────────────────────────────── */

.btn {
    padding: 5px 11px; font-size: 12px;
    border-radius: 7px;
    border: .5px solid rgba(0, 0, 0, .2);
    background: transparent;
    color: #555;
    cursor: pointer;
    white-space: nowrap;
    transition: background .1s;
    display: inline-flex; align-items: center; gap: 4px;
    font-family: inherit;
    text-decoration: none;
}
.btn:hover { background: #f0eff0; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn-icon {
    width: 26px;
    height: 26px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
}
.btn[aria-label="Modifica"],
.btn[aria-label="Modifica tipo"],
.btn[aria-label="Elimina"],
.btn[aria-label="Elimina tipo"] {
    width: 26px;
    height: 26px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
}
.btn-p  { background: #c0392b !important; color: #fff !important; border-color: #c0392b !important; }
.btn-p:hover { background: #a93226 !important; }
.btn-g  { background: #2e7d52 !important; color: #fff !important; border-color: #2e7d52 !important; }
.btn-g:hover { background: #256041 !important; }
.btn-d  { color: #791f1f; border-color: rgba(163, 45, 45, .3); }
.btn-d:hover { background: #fcebeb; }

/* ─── INPUT / SELECT / TEXTAREA ─────────────────────────────── */

.fi {
    padding: 6px 9px; font-size: 12.5px;
    border: .5px solid rgba(0, 0, 0, .2);
    border-radius: 7px;
    background: #f5f5f3;
    color: #1a1a18;
    width: 100%;
    font-family: inherit;
}
.fi:focus { outline: none; border-color: rgba(0, 0, 0, .38); background: #fff; }
select.fi { appearance: auto; }
textarea.fi { resize: vertical; min-height: 60px; }

.color-field {
    display: grid;
    grid-template-columns: max-content minmax(170px, 1fr);
    gap: 12px;
    align-items: start;
}
.color-lookup {
    display: grid;
    grid-template-columns: repeat(8, 22px);
    gap: 5px;
    max-width: 220px;
}
.color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: .5px solid rgba(0,0,0,.22);
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}
.color-swatch.is-selected {
    outline: 2px solid #2c4a6e;
    outline-offset: 2px;
}
.color-usage {
    min-height: 86px;
    max-height: 190px;
    overflow: auto;
    border: .5px solid rgba(0,0,0,.12);
    border-radius: 7px;
    background: #fafafa;
    padding: 8px;
}
.color-usage-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #555;
    margin-bottom: 6px;
}
.color-usage-dot {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    border: .5px solid rgba(0,0,0,.25);
    flex-shrink: 0;
}
.color-usage-empty {
    font-size: 11.5px;
    color: #999;
}
.color-usage-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.color-usage-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 11.5px;
    color: #333;
    padding: 4px 6px;
    border-radius: 5px;
    background: #fff;
}
.color-usage-item.is-current {
    background: #e6f1fb;
}
.color-usage-item span {
    font-size: 10px;
    color: #2c4a6e;
}

/* ─── BADGE ─────────────────────────────────────────────────── */

.bdg {
    display: inline-flex; align-items: center;
    padding: 2px 7px; border-radius: 3px;
    font-size: 10.5px; font-weight: 500;
}
.bok { background: #eaf3de; color: #27500a; }
.bko { background: #fcebeb; color: #791f1f; }
.bwa { background: #faeeda; color: #633806; }
.bin { background: #e6f1fb; color: #0c447c; }
.bgy { background: #f0eff0; color: #555; }

/* ─── TABELLE ───────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }
thead th {
    padding: 7px 12px; font-size: 10.5px; font-weight: 500;
    color: #666; text-align: left;
    border-bottom: .5px solid rgba(0, 0, 0, .1);
    background: #f5f5f3;
    white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
tbody td {
    padding: 7px 12px; font-size: 12px; color: #1a1a18;
    border-bottom: .5px solid rgba(0, 0, 0, .07);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 200px;
}
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #f8f8f7; }
tbody tr.is-active td { background: #e6f1fb; }

.project-lav-preview-row td {
    background: #fafafa;
    padding-top: 4px;
    padding-bottom: 8px;
    white-space: normal;
}
.project-lav-preview {
    display: grid;
    gap: 5px;
}
.project-lav-item {
    display: block;
    padding: 5px 8px;
    border: .5px solid rgba(0, 0, 0, .08);
    border-radius: 7px;
    background: #fff;
}
.project-lav-line {
    display: grid;
    grid-template-columns: 28px minmax(160px, 1fr) minmax(180px, 1.3fr) 76px;
    align-items: center;
    gap: 8px;
}
.project-lav-drag {
    cursor: grab;
}
.project-lav-check-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    cursor: pointer;
}
.project-lav-title {
    font-size: 11.5px;
    color: #1a1a18;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.project-lav-meta {
    font-size: 10.5px;
    color: #777;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.project-lav-details {
    margin: 7px 0 2px 26px;
    display: grid;
    gap: 8px;
}
.project-lav-detail-block {
    display: grid;
    gap: 5px;
}
.project-lav-detail-title {
    font-size: 10px;
    text-transform: uppercase;
    color: #888;
    font-weight: 500;
}
.project-lav-warning {
    font-size: 11px;
    color: #8a5a04;
    background: #fff7e6;
    border: .5px solid rgba(138, 90, 4, .18);
    border-radius: 6px;
    padding: 5px 7px;
}
.project-lav-param-row {
    display: grid;
    grid-template-columns: minmax(130px, .8fr) 120px minmax(170px, 1fr);
    gap: 6px;
    align-items: center;
}
.project-lav-param-row span {
    font-size: 11px;
    color: #555;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.project-lav-coord-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(90px, 1fr)) 28px;
    gap: 6px;
}
.project-custom-lav-controls {
    margin: 7px 0 0 26px;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 90px 80px 28px;
    gap: 6px;
    align-items: center;
}

/* ─── FILTRI (filter bar) ───────────────────────────────────── */

.fbar {
    padding: 8px 16px;
    border-bottom: .5px solid rgba(0, 0, 0, .1);
    background: #f5f5f3;
    display: flex; flex-wrap: wrap;
    gap: 10px; align-items: flex-end;
}
.fitem { display: flex; flex-direction: column; }
.fbar label {
    font-size: 9.5px; text-transform: uppercase;
    color: #888; margin-bottom: 2px;
}

/* ─── CARD / DETAIL PANEL ───────────────────────────────────── */

.card {
    background: #fff;
    border: .5px solid rgba(0, 0, 0, .1);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 10px;
}
.card-h {
    font-size: 10px; font-weight: 500; text-transform: uppercase;
    color: #888; margin-bottom: 10px;
}

.detail-pane {
    width: 380px; min-width: 380px;
    border-left: .5px solid rgba(0, 0, 0, .1);
    overflow-y: auto; background: #fff; padding: 14px;
}
.detail-title {
    font-size: 14px; font-weight: 500; color: #2c4a6e;
    margin-bottom: 14px;
    display: flex; align-items: center; justify-content: space-between;
}

.fld { display: flex; flex-direction: column; gap: 3px; }
.fld label, .fld > .fld-label {
    font-size: 10.5px; text-transform: uppercase;
    color: #888; font-weight: 500;
}
.fld .req { color: #c0392b; }
.fld-value { font-size: 12.5px; padding: 6px 0; }

/* Pannello dettaglio: i label dei campi devono spiccare sopra al valore */
.detail-pane .fld-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    font-weight: 700;
    color: #2c4a6e;
    border-bottom: .5px solid #d9d6cf;
    padding-bottom: 3px;
    margin-bottom: 2px;
}
.detail-pane .fld-value { font-size: 13px; color: #1a1a18; padding: 2px 0 0; }

/* ─── KPI (dashboard) ──────────────────────────────────────── */

.kpi {
    background: #fff;
    border: .5px solid rgba(0, 0, 0, .1);
    border-left: 3px solid;
    border-radius: 10px;
    padding: 14px;
}
.kpi .kl { font-size: 11px; color: #888; margin-bottom: 5px; }
.kpi .kv { font-size: 26px; font-weight: 500; color: #1a1a18; }

/* ─── DIALOG (modale edit/new) ──────────────────────────────── */

dialog.modal {
    padding: 0;
    border: none;
    border-radius: 12px;
    max-width: 95vw;
    width: 640px;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
    margin: auto;
}
dialog.modal[open] {
    position: fixed;
    inset: 0;
}
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); }

.modal-h {
    padding: 14px 18px;
    border-bottom: .5px solid rgba(0, 0, 0, .1);
    display: flex; align-items: center; gap: 10px;
}
.modal-h .mt  { font-size: 14px; font-weight: 500; flex: 1; }
.modal-h .mc  { width: 4px; height: 22px; border-radius: 2px; background: #2c4a6e; }
.modal-b {
    padding: 18px;
    overflow-y: auto;
    max-height: calc(90vh - 110px);
    display: flex; flex-direction: column; gap: 12px;
}
.modal-f {
    padding: 12px 18px;
    border-top: .5px solid rgba(0, 0, 0, .1);
    display: flex; justify-content: flex-end; gap: 8px;
}
.frow {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.frow-single {
    grid-template-columns: 1fr;
}

/* ─── TOAST / NOTIFICHE ─────────────────────────────────────── */

#toast {
    position: fixed;
    bottom: 12px; right: 14px;
    background: #1e5c36; color: #9fe8b4;
    font-size: 11.5px;
    padding: 8px 14px;
    border-radius: 8px;
    opacity: 0;
    transition: opacity .25s;
    pointer-events: none;
    z-index: 99;
    border: .5px solid rgba(46, 204, 113, .3);
}
#toast.show       { opacity: 1; }
#toast.toast-err  { background: #5c1e1e; color: #e8b4b4; border-color: rgba(204, 46, 46, .3); }

/* ─── STATI / VARIE ─────────────────────────────────────────── */

.loading, .empty {
    padding: 40px;
    text-align: center;
    color: #aaa;
    font-size: 13px;
}

.prog-bar {
    height: 6px; background: #e8e8e6;
    border-radius: 3px; overflow: hidden;
    margin-top: 4px;
}
.prog-fill {
    height: 100%; border-radius: 3px;
    background: #2e7d52;
}

/* Scrollbar sottile (solo WebKit) */
.sc { overflow-y: auto; }
.sc::-webkit-scrollbar { width: 4px; }
.sc::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .15); border-radius: 2px; }

/* Indicatore visivo mentre HTMX sta caricando un pezzo */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }
.htmx-swapping { opacity: .5; transition: opacity .12s; }

/* Utility di spacing/layout */
.flex     { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-1   { flex: 1; }
.gap-1    { gap: 4px; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }
.ml-auto  { margin-left: auto; }

/* Login */
.login-body {
    min-height: 100vh;
    margin: 0;
    background: #e4e2dc;
    display: grid;
    place-items: center;
    font-family: system-ui, -apple-system, Segoe UI, sans-serif;
    color: #1f2329;
}
.login-shell {
    width: min(92vw, 380px);
}
.login-panel {
    background: #f7f6f2;
    border: .5px solid rgba(0, 0, 0, .12);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(0, 0, 0, .18);
    padding: 24px;
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}
.login-brand img {
    width: 44px;
    height: 44px;
}
.login-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0;
}
.login-subtitle {
    color: #6d7178;
    font-size: 12px;
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: #555b62;
}
.login-form input,
.login-form select {
    height: 38px;
    border: .5px solid rgba(0, 0, 0, .2);
    border-radius: 6px;
    padding: 0 10px;
    background: #fff;
    font: inherit;
}
.login-form select {
    cursor: pointer;
}
.login-form button {
    height: 40px;
    border: 0;
    border-radius: 6px;
    background: #f4c20d;
    color: #1f2329;
    font-weight: 700;
    cursor: pointer;
}
.login-error {
    margin-bottom: 14px;
    padding: 9px 10px;
    border-radius: 6px;
    background: #ffe7e7;
    color: #9f1d1d;
    font-size: 12px;
}

.sb-user {
    margin-top: auto;
    padding: 12px;
    border-top: .5px solid rgba(255, 255, 255, .12);
}
.sb-user-name {
    font-size: 12px;
    font-weight: 700;
    color: #f6f3e9;
}
.sb-user-company {
    font-size: 11px;
    color: rgba(246, 243, 233, .62);
    margin-top: 2px;
}
.sb-logout {
    display: inline-block;
    margin-top: 8px;
    font-size: 11px;
    color: #f4c20d;
    text-decoration: none;
}

/* ─── Upload preview (form-field type image/file) ─────────────── */
.upload-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0 6px;
    padding: 6px 8px;
    border: .5px solid #d9d6cf;
    border-radius: 6px;
    background: #f7f5ef;
    font-size: 11.5px;
}
.upload-preview img {
    max-width: 90px;
    max-height: 60px;
    object-fit: contain;
    border: .5px solid #ddd;
    background: #fff;
    border-radius: 3px;
}
.upload-preview a { color: #2c4a6e; word-break: break-all; }
.upload-clear { display: flex; align-items: center; gap: 4px; color: #888; margin-left: auto; cursor: pointer; }

/* ─── Anteprima immagini nel pannello dettaglio ───────────────── */
.detail-img {
    display: inline-block;
    border: .5px solid #d9d6cf;
    border-radius: 5px;
    padding: 3px;
    background: #fff;
}
.detail-img img {
    display: block;
    max-width: 100%;
    max-height: 180px;
    object-fit: contain;
}
.detail-img-name {
    margin-top: 4px;
    font-size: 10.5px;
    color: #888;
    word-break: break-all;
}

/* ─── Render HTML nel pannello dettaglio (type='html') ───────── */
.detail-html {
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.detail-html p     { margin: 0 0 6px; }
.detail-html ul,
.detail-html ol    { margin: 0 0 6px 18px; }
.detail-html img   { max-width: 100%; height: auto; }
.detail-html a     { color: #2c4a6e; }
.detail-html table { border-collapse: collapse; max-width: 100%; }
.detail-html table td, .detail-html table th { border: .5px solid #d9d6cf; padding: 3px 6px; font-size: 11.5px; }
