/* Toscana Diagnostica · Portale SGI
   Stile allineato alla Cash Management (repo td-cash-management, web/src/styles.css).
   Palette: Dark Teal #1C505E · Pacific Blue #71B1BD · Jet Black #01212C · Cornsilk #FFFAE3 · Mauve #DEC0F1 */
:root {
  --teal: #1C505E; --teal-600: #16434f; --teal-050: #e8f0f2;
  --blue: #71B1BD; --blue-100: #dcedf0;
  --jet: #01212C; --silk: #FFFAE3; --mauve: #DEC0F1; --mauve-100: #f3e8fa;
  --ink: #0f2a33; --muted: #5b6f75; --line: #dbe5e7; --bg: #f3f6f6; --card: #ffffff;
  --red: #b3372f; --red-100: #fbe9e7; --green: #2f7d5b; --green-100: #e3f3ea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(1, 33, 44, .06), 0 4px 16px rgba(1, 33, 44, .05);
  --font: 'Manrope', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 750; color: var(--jet); }
h2 { font-size: 16px; font-weight: 700; color: var(--jet); }
h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--teal); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.side { background: var(--jet); color: #cfe3e7; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin; }
.side .brand { padding: 22px 20px 14px; border-bottom: 1px solid rgba(113, 177, 189, .18); }
.side .brand img { width: 170px; display: block; }
.side .brand .app { margin-top: 8px; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--blue); font-weight: 700; }
.side nav { padding: 10px 10px 20px; flex: 1; }
.side .group { margin: 14px 10px 6px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #6f98a1; font-weight: 700; }
.side a, .side button.navlink { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 1px 0; border-radius: 8px; color: #d6e8eb; font-weight: 550; width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.side a:hover, .side button.navlink:hover { background: rgba(113, 177, 189, .12); text-decoration: none; }
.side a.active, .side button.navlink.active { background: var(--teal); color: #fff; }
.side .count { margin-left: auto; background: var(--mauve); color: var(--jet); font-size: 11px; font-weight: 800; border-radius: 10px; padding: 0 7px; }
.side svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.side select.areasel { width: calc(100% - 20px); margin: 4px 10px 8px; background: rgba(255,255,255,.06); color: #d6e8eb; border: 1px solid rgba(113,177,189,.3); border-radius: 8px; min-height: 36px; font-size: 13px; padding: 6px 10px; }
.side select.areasel option { color: var(--ink); background: #fff; }
.side .hint { margin: 0 20px 6px; font-size: 11.5px; color: #6f98a1; line-height: 1.4; }
.kpi.clickable { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.kpi.clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(1,33,44,.12); }
.kpi.clickable.on { outline: 2px solid var(--blue); outline-offset: 1px; }
.kpi .act { font-size: 11.5px; color: var(--blue); font-weight: 700; margin-top: 8px; text-transform: uppercase; letter-spacing: .06em; }
.kpi.accent .act { color: var(--mauve); }
.side .me { padding: 14px 18px; border-top: 1px solid rgba(113, 177, 189, .18); font-size: 12.5px; color: #9cc4cc; }
.side .me .name { color: #fff; font-weight: 700; }
.main { min-width: 0; }
.topbar { display: none; }
.page { padding: 28px 40px 60px; max-width: 1240px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; max-width: 820px; font-size: 14.5px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mt { margin-top: 16px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card > .bd { padding: 16px 18px; }
.card > .bd.flush { padding: 0; }
.kpi { padding: 16px 18px; }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 28px; font-weight: 780; color: var(--jet); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { background: var(--jet); border-color: var(--jet); }
.kpi.accent .lbl, .kpi.accent .foot { color: #9cc4cc; }
.kpi.accent .val { color: var(--silk); }
.kpi .bar { height: 4px; border-radius: 4px; margin-top: 10px; background: var(--teal-050); overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: var(--teal); }

/* Tables */
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafcfc; position: sticky; top: 0; }
.t td { padding: 10px 14px; border-bottom: 1px solid #edf2f3; vertical-align: middle; }
.t tr:last-child td { border-bottom: none; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover td { background: #f6fafb; }
.table-wrap { overflow-x: auto; }

/* Badges / chips */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.b-grey { background: #eef1f2; color: #57686d; }
.b-blue { background: var(--blue-100); color: #1f6573; }
.b-teal { background: var(--teal); color: #fff; }
.b-mauve { background: var(--mauve-100); color: #6d3f8a; }
.b-green { background: var(--green-100); color: var(--green); }
.b-red { background: var(--red-100); color: var(--red); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--teal-050); color: var(--teal); font-size: 12px; font-weight: 700; margin: 2px 4px 2px 0; font-family: var(--mono); }
.mark { background: var(--silk); border-radius: 3px; padding: 0 2px; }

/* Forms */
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 650; color: var(--muted); }
input, select { font: inherit; color: var(--ink); background: #fff; border: 1px solid #c9d7da; border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(113, 177, 189, .28); }
.searchbox { position: relative; }
.searchbox input { padding-left: 36px; padding-right: 48px; min-height: 44px; font-size: 15px; }
.searchbox > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.searchbox .clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: none; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: var(--teal-050); color: var(--teal); align-items: center; justify-content: center; z-index: 2; }
.searchbox .clear svg { width: 14px; height: 14px; display: block; }
.searchbox .clear.on { display: flex; }
.searchbox .clear:hover { background: var(--teal); color: #fff; }
.seg { display: inline-flex; border: 1px solid #c9d7da; border-radius: 8px; overflow: hidden; flex-wrap: wrap; background: #fff; }
.seg button { display: flex; align-items: center; gap: 6px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; border: 0; border-right: 1px solid #c9d7da; background: none; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--teal); color: #fff; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters label.f { min-width: 150px; }
.help { font-size: 11.5px; color: var(--muted); font-weight: 500; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 700; font-size: 13.5px; border-radius: 9px; padding: 8px 14px; min-height: 38px; border: 1px solid transparent; cursor: pointer; background: var(--teal); color: #fff; white-space: nowrap; }
.btn:hover { background: var(--teal-600); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--teal); border-color: #c5d6da; }
.btn.ghost:hover { background: var(--teal-050); }
.btn.dark { background: var(--jet); }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.btn.lg { min-height: 46px; padding: 10px 20px; font-size: 15px; }
.iconbtn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; font: inherit; }
.iconbtn:hover { color: var(--teal); background: var(--teal-050); }

/* Alerts */
.alert { border-radius: 10px; padding: 11px 14px; font-weight: 550; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; }
.alert.info { background: var(--blue-100); color: #174f5a; }
.alert.warn { background: var(--silk); color: #6a5510; border: 1px solid #efe2a8; }

/* Chip grid (documenti cardine, aree, informative) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fcfdfd; cursor: pointer; display: block; color: inherit; }
.tile:hover { border-color: var(--blue); background: #f6fafb; text-decoration: none; }
.tile .code { font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: var(--teal); }
.tile .name { margin-top: 3px; font-size: 13px; font-weight: 600; color: var(--jet); line-height: 1.35; }
.tile .sub { margin-top: 2px; font-size: 12px; color: var(--muted); }
.tile.area { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile.area .name { margin: 0; }
.tile.area .count { background: var(--mauve); color: var(--jet); font-size: 11px; font-weight: 800; border-radius: 10px; padding: 0 7px; }

.doc-code { font-family: var(--mono); font-weight: 700; color: var(--teal); white-space: nowrap; }
.doc-title { font-weight: 650; color: var(--jet); }
.doc-sintesi { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.doc-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.url { font-family: var(--mono); font-size: 12px; color: var(--muted); background: #f3f6f6; padding: 2px 8px; border-radius: 6px; cursor: pointer; display: inline-block; margin-top: 4px; word-break: break-all; }
.url:hover { background: var(--teal-050); color: var(--teal); }

/* Toast */
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--jet); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; max-width: 420px; z-index: 60; opacity: 0; transform: translateY(10px); transition: all .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--red); }

footer.foot { margin-top: 30px; color: var(--muted); font-size: 12px; line-height: 1.6; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (min-width: 1700px) { .page { max-width: 1320px; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--jet); position: sticky; top: 0; z-index: 30; }
  .topbar img { height: 26px; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .page { padding: 18px 16px 50px; }
  .g2, .g4 { grid-template-columns: 1fr; }
  .t thead { display: none; }
  .t td { display: block; padding: 4px 14px; border: none; }
  .t tr { display: block; padding: 8px 0; border-bottom: 1px solid #edf2f3; }
  .doc-actions { justify-content: flex-start; }
}
@media print { .side, .topbar { display: none !important; } .shell { display: block; } }

/* Colonna azioni: su una riga, allineata a destra */
.t td:last-child .doc-actions { flex-wrap: nowrap; }
.t td:last-child { white-space: nowrap; }
