/* ===== Manudesk – tema ===== */
:root {
  --md-bg: #f4f6fb;
  --md-surface: #ffffff;
  --md-border: #e4e8f0;
  --md-text: #1e293b;
  --md-muted: #64748b;
  --md-primary: #2563eb;
  --md-primary-soft: #eaf1ff;
  --md-radius: 12px;
  --md-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --md-shadow-lg: 0 10px 25px -8px rgba(15, 23, 42, .18);
  /* stati */
  --st-nuova: #0ea5e9;
  --st-presa_in_carico: #8b5cf6;
  --st-in_lavorazione: #f59e0b;
  --st-in_attesa: #f97316;
  --st-risolta: #10b981;
  --st-chiusa: #94a3b8;
}
body {
  background: var(--md-bg);
  color: var(--md-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: .925rem;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--md-primary); }
.text-muted { color: var(--md-muted) !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8em; letter-spacing: .01em; }

/* ===== Barra superiore ===== */
.md-topbar {
  position: sticky; top: 0; z-index: 1020;
  background: rgba(255, 255, 255, .9); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--md-border);
}
.md-topbar .inner { display: flex; align-items: center; gap: 1rem; height: 60px; padding: 0 1.5rem; }
.md-brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; color: var(--md-text); text-decoration: none; }
.md-brand .logo {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed); box-shadow: 0 4px 10px -3px rgba(37, 99, 235, .6);
}
.md-brand small { display: block; font-weight: 500; font-size: .7rem; color: var(--md-muted); margin-top: -3px; }
.md-seg { display: inline-flex; background: #eef1f6; border-radius: 10px; padding: 3px; }
.md-seg a { display: flex; align-items: center; gap: .4rem; padding: .35rem .9rem; border-radius: 8px; color: var(--md-muted); text-decoration: none; font-weight: 500; font-size: .875rem; }
.md-seg a.active { background: #fff; color: var(--md-text); box-shadow: var(--md-shadow); }
.md-seg a:hover:not(.active) { color: var(--md-text); }
.md-user { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.md-user .who { line-height: 1.15; text-align: right; }
.md-user .who strong { display: block; font-size: .85rem; }
.md-user .who span { font-size: .72rem; color: var(--md-muted); }
.md-iconbtn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--md-border); background: #fff; color: var(--md-muted); }
.md-iconbtn:hover { color: var(--md-text); background: #f8fafc; }
@media (max-width: 640px) { .md-user .who, .md-brand small { display: none; } .md-topbar .inner { padding: 0 .75rem; gap: .5rem; } }

.md-main { padding: 1.5rem; }
@media (max-width: 640px) { .md-main { padding: 1rem .75rem; } }
.md-pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.md-pagehead h1 { font-size: 1.4rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.md-pagehead p { margin: .15rem 0 0; color: var(--md-muted); }

/* ===== Elementi comuni ===== */
.md-card { background: var(--md-surface); border: 1px solid var(--md-border); border-radius: var(--md-radius); box-shadow: var(--md-shadow); }
.md-card > .hd { padding: .8rem 1rem; border-bottom: 1px solid var(--md-border); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.md-card > .bd { padding: 1rem; }
.avatar {
  display: inline-grid; place-items: center; flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  color: #fff; font-size: .7rem; font-weight: 700; letter-spacing: .02em; background: var(--c, #64748b);
}
.avatar.sm { width: 22px; height: 22px; font-size: .6rem; }
.avatar.lg { width: 38px; height: 38px; font-size: .8rem; }
.avatar.empty { background: #fff; color: var(--md-muted); border: 1.5px dashed #cbd5e1; }
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; line-height: 1.4; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st { color: var(--s); background: color-mix(in srgb, var(--s) 13%, white); }
.st-nuova { --s: var(--st-nuova); } .st-presa_in_carico { --s: var(--st-presa_in_carico); }
.st-in_lavorazione { --s: #d97706; } .st-in_attesa { --s: #ea580c; }
.st-risolta { --s: #059669; } .st-chiusa { --s: #64748b; }
.pr-bassa { color: #475569; background: #f1f5f9; }
.pr-normale { color: #1d4ed8; background: #e8effe; }
.pr-alta { color: #c2410c; background: #ffedd5; }
.pr-urgente { color: #fff; background: #dc2626; }
.btn { border-radius: 9px; font-weight: 500; font-size: .875rem; }
.btn-primary { background: var(--md-primary); border-color: var(--md-primary); }
.form-control, .form-select { border-radius: 9px; border-color: #d8dee9; font-size: .9rem; }
.form-control:focus, .form-select:focus { border-color: #93b4f7; box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .15); }
.form-label { font-weight: 500; font-size: .8rem; color: var(--md-muted); margin-bottom: .25rem; }
.alert { border-radius: 10px; border: 0; box-shadow: var(--md-shadow); }

/* ===== Riepilogo dirigente ===== */
.md-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.md-kpi { background: #fff; border: 1px solid var(--md-border); border-radius: var(--md-radius); padding: .8rem 1rem; box-shadow: var(--md-shadow); position: relative; overflow: hidden; }
.md-kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--s, var(--md-primary)); }
.md-kpi .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.md-kpi .l { font-size: .78rem; color: var(--md-muted); font-weight: 500; }
.md-summary table { margin: 0; }
.md-summary th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--md-muted); font-weight: 600; border-bottom-color: var(--md-border); white-space: nowrap; }
.md-summary td { border-color: #f0f2f7; }
.md-summary .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.md-summary .zero { color: #cbd5e1; font-weight: 400; }
.md-summary a { color: var(--md-text); text-decoration: none; font-weight: 500; }
.md-summary a:hover { color: var(--md-primary); }
details.md-card > summary { list-style: none; cursor: pointer; }
details.md-card > summary::-webkit-details-marker { display: none; }
details.md-card > summary .chev { transition: transform .15s; }
details.md-card[open] > summary .chev { transform: rotate(180deg); }
details.md-card:not([open]) > summary { border-bottom: 0; }

/* ===== Da smistare ===== */
.md-inbox {
  border-radius: var(--md-radius); padding: 1rem; margin-bottom: 1.25rem;
  background: linear-gradient(180deg, #fff8eb, #fffdf7); border: 1px solid #fde4b4;
}
.md-inbox .title { display: flex; align-items: center; gap: .5rem; font-weight: 700; margin-bottom: .75rem; color: #92400e; }
.md-inbox .title .count { background: #f59e0b; color: #fff; border-radius: 999px; padding: 0 .55rem; font-size: .75rem; }
.unassigned-list { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .25rem; min-height: 40px; }
.unassigned-list .tcard { flex: 0 0 280px; margin: 0; }
.md-inbox .hint { font-size: .78rem; color: #a16207; margin: .9rem 0 .5rem; display: flex; align-items: center; gap: .4rem; }
.assign-targets { display: flex; flex-wrap: wrap; gap: .5rem; }
.assign-target {
  display: flex; align-items: center; gap: .5rem; padding: .4rem .8rem .4rem .4rem; min-width: 160px; border-radius: 999px;
  border: 1.5px dashed #e8c37a; background: #fff; font-size: .85rem; font-weight: 500; transition: all .15s;
}
.assign-target:has(.tcard), .assign-target:hover { border-style: solid; border-color: var(--md-primary); background: var(--md-primary-soft); transform: translateY(-1px); }
.assign-target .tcard { display: none; }

/* ===== Kanban ===== */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(225px, 1fr); gap: .85rem; overflow-x: auto; padding-bottom: 1rem; align-items: start; }
.kanban-col { background: #eceff5; border-radius: var(--md-radius); padding: .6rem; border-top: 3px solid var(--s); }
.kanban-col .col-hd { display: flex; align-items: center; gap: .5rem; padding: .25rem .35rem .65rem; }
.kanban-col .col-hd .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--s); }
.kanban-col .col-hd h2 { font-size: .82rem; font-weight: 700; margin: 0; letter-spacing: .01em; }
.kanban-col .col-hd .count { margin-left: auto; background: #fff; color: var(--md-muted); font-size: .72rem; font-weight: 700; padding: .05rem .5rem; border-radius: 999px; }
.kanban-col .col-hd small { font-size: .7rem; color: var(--md-muted); }
.kanban-list { min-height: 120px; display: flex; flex-direction: column; gap: .6rem; border-radius: 9px; }
.kanban-list:empty::after { content: "Trascina qui"; display: grid; place-items: center; height: 100px; border: 1.5px dashed #cfd6e2; border-radius: 9px; color: #a0aec0; font-size: .8rem; }
.kanban-col[data-s="nuova"] { --s: var(--st-nuova); } .kanban-col[data-s="presa_in_carico"] { --s: var(--st-presa_in_carico); }
.kanban-col[data-s="in_lavorazione"] { --s: var(--st-in_lavorazione); } .kanban-col[data-s="in_attesa"] { --s: var(--st-in_attesa); }
.kanban-col[data-s="risolta"] { --s: var(--st-risolta); } .kanban-col[data-s="chiusa"] { --s: var(--st-chiusa); }

/* scheda */
.tcard {
  position: relative; background: #fff; border: 1px solid var(--md-border); border-radius: 10px; padding: .7rem .8rem;
  box-shadow: var(--md-shadow); cursor: grab; transition: box-shadow .15s, transform .15s, border-color .15s;
}
.tcard:hover { box-shadow: var(--md-shadow-lg); transform: translateY(-1px); border-color: #d3dae6; }
.tcard:active { cursor: grabbing; }
.tcard.p-alta { box-shadow: inset 3px 0 0 #f97316, var(--md-shadow); }
.tcard.p-urgente { box-shadow: inset 3px 0 0 #dc2626, var(--md-shadow); background: #fffafa; }
.tcard .top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .35rem; }
.tcard .code { color: var(--md-muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.tcard .code::after { content: ""; position: absolute; inset: 0; } /* tutta la scheda è cliccabile */
.tcard .subj { font-weight: 600; font-size: .9rem; line-height: 1.3; color: var(--md-text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: .55rem; }
.tcard .meta { display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .76rem; color: var(--md-muted); }
.tcard .meta .from { display: flex; align-items: center; gap: .3rem; min-width: 0; }
.tcard .meta .from span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard .meta .age { display: flex; align-items: center; gap: .25rem; white-space: nowrap; }
.tcard .foot { display: flex; align-items: center; justify-content: space-between; margin-top: .55rem; padding-top: .5rem; border-top: 1px solid #f1f4f8; font-size: .76rem; color: var(--md-muted); }
.tcard svg, .md-ico { width: 14px; height: 14px; flex: 0 0 auto; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: var(--md-shadow-lg); }
.sortable-drag { transform: rotate(2deg); }

/* ===== Lista ===== */
.md-filters { padding: 1rem; margin-bottom: 1rem; }
.md-table { margin: 0; }
.md-table thead th { background: #f8fafc; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--md-muted); font-weight: 600; border-bottom: 1px solid var(--md-border); padding: .7rem .9rem; white-space: nowrap; position: sticky; top: 0; }
.md-table thead th a { color: inherit; text-decoration: none; }
.md-table thead th a:hover { color: var(--md-text); }
.md-table td { padding: .7rem .9rem; border-color: #f0f2f7; vertical-align: middle; }
.md-table tbody tr { cursor: pointer; transition: background .1s; }
.md-table tbody tr:hover { background: #f8faff; }
.md-table .subj { font-weight: 600; color: var(--md-text); text-decoration: none; }
.md-table .who { display: flex; align-items: center; gap: .45rem; white-space: nowrap; }
.md-pager { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-top: 1px solid var(--md-border); font-size: .85rem; color: var(--md-muted); }

/* ===== Dettaglio ===== */
.md-ticket-head { padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; }
.md-ticket-head .crumbs { font-size: .8rem; margin-bottom: .5rem; }
.md-ticket-head .crumbs a { color: var(--md-muted); text-decoration: none; }
.md-ticket-head h1 { font-size: 1.35rem; font-weight: 700; margin: 0 0 .5rem; letter-spacing: -.01em; }
.md-ticket-head .facts { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; color: var(--md-muted); font-size: .85rem; }
.md-ticket-head .facts > span { display: flex; align-items: center; gap: .35rem; }
.thread { display: flex; flex-direction: column; gap: 1rem; }
.msg { display: flex; gap: .75rem; }
.msg .bubble { flex: 1; min-width: 0; background: #fff; border: 1px solid var(--md-border); border-radius: 4px var(--md-radius) var(--md-radius) var(--md-radius); box-shadow: var(--md-shadow); }
.msg .bubble .mh { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem .75rem; padding: .6rem .9rem; border-bottom: 1px solid #f0f2f7; font-size: .8rem; color: var(--md-muted); }
.msg .bubble .mh strong { color: var(--md-text); }
.msg .bubble .mb { padding: .8rem .9rem; }
.msg pre { white-space: pre-wrap; font-family: inherit; font-size: .9rem; margin: 0; word-break: break-word; line-height: 1.55; }
.msg.out { flex-direction: row-reverse; }
.msg.out .bubble { background: #f3f7ff; border-color: #d6e3fd; border-radius: var(--md-radius) 4px var(--md-radius) var(--md-radius); }
.msg.nota .bubble { background: #fffbeb; border: 1px dashed #f5d27a; }
.msg .tag { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .05rem .45rem; border-radius: 5px; }
.msg.in .tag { background: #e0f2fe; color: #0369a1; }
.msg.out .tag { background: #dbeafe; color: #1d4ed8; }
.msg.nota .tag { background: #fef3c7; color: #92400e; }
.att { display: inline-flex; align-items: center; gap: .4rem; margin: .6rem .4rem 0 0; padding: .35rem .65rem; border: 1px solid var(--md-border); border-radius: 8px; background: #fff; font-size: .8rem; text-decoration: none; color: var(--md-text); }
.att:hover { border-color: var(--md-primary); color: var(--md-primary); }
.composer { margin-top: 1.5rem; overflow: hidden; }
.composer .tabs { display: flex; border-bottom: 1px solid var(--md-border); background: #f8fafc; }
.composer .tabs button { border: 0; background: none; padding: .75rem 1.1rem; font-weight: 600; font-size: .85rem; color: var(--md-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.composer .tabs button.active { color: var(--md-primary); border-bottom-color: var(--md-primary); background: #fff; }
.composer .tabs button[data-bs-target="#tab-note"].active { color: #b45309; border-bottom-color: #f59e0b; }
.composer textarea { border-radius: 9px; resize: vertical; }
.side .md-card { margin-bottom: 1rem; }
.side dl { display: grid; grid-template-columns: auto 1fr; gap: .55rem .75rem; margin: 0; font-size: .85rem; align-items: center; }
.side dt { color: var(--md-muted); font-weight: 500; }
.side dd { margin: 0; text-align: right; justify-self: end; }
.events { list-style: none; margin: 0; padding: 0; position: relative; }
.events::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: #e8ecf3; }
.events li { position: relative; padding: 0 0 .9rem 1.5rem; font-size: .82rem; }
.events li:last-child { padding-bottom: 0; }
.events li::before { content: ""; position: absolute; left: 1px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2.5px solid var(--md-primary); }
.events .when { color: var(--md-muted); font-size: .74rem; }
.events .note { margin-top: .2rem; padding: .35rem .55rem; background: #f8fafc; border-radius: 6px; color: var(--md-muted); }

/* ===== Accesso ===== */
.md-auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 10% -10%, #dbe7ff, transparent), radial-gradient(900px 500px at 110% 110%, #ece3ff, transparent), var(--md-bg); }
.md-auth .box { width: 100%; max-width: 400px; }
.md-auth .md-card { padding: 2rem; box-shadow: 0 20px 45px -20px rgba(15, 23, 42, .3); }
.md-auth .md-brand { justify-content: center; margin-bottom: 1.5rem; font-size: 1.25rem; }
.md-auth .md-brand .logo { width: 42px; height: 42px; border-radius: 12px; }
.md-auth h1 { font-size: 1.1rem; font-weight: 700; text-align: center; margin-bottom: .25rem; }
.md-auth .sub { text-align: center; color: var(--md-muted); font-size: .85rem; margin-bottom: 1.5rem; }
.md-auth .form-control { padding: .6rem .8rem; }
.md-auth .btn { padding: .6rem; }
