:root {
  --bg: #eef1f4; --panel: #fff; --panel2: #f8fafb; --head: #f3f6f8; --hover: #f5f9fc; --input: #fff; --inbrd: #c3ccd5; --inhover: #d8dee4; --ro: #f3f5f7;
  --line: #d5dbe1; --line2: #e7ebef; --text: #1d2733; --muted: #66737f; --tagbg: #e9edf1; --tagfg: #44515e; --curRow: #fbfcdf; --acbrd: #9fb0c0; --acline: #f0f2f4;
  --brand: #1f5f8b; --brand2: #174a6d; --brand-soft: #e3eef6; --brand-l: #9fd0f3; --ok: #1e7d46; --ok-soft: #e2f3e9; --warn: #a36100; --warn-soft: #fff2db;
  --err: #b3261e; --err-soft: #fde7e5; --err-brd: #e5b4b0; --sel: #fff7cf; --focus: #2f80c0; --shadow: rgba(0,0,0,.18); --fs: 13px;
}
/* Colore principale */
[data-colore="verde"] { --brand: #2e7d4f; --brand2: #215c3a; --brand-soft: #e3f2e9; --brand-l: #a8e0bf; --focus: #3a9a62; }
[data-colore="mattone"] { --brand: #b4532a; --brand2: #8a3d1d; --brand-soft: #f8e9e2; --brand-l: #f5c2a8; --focus: #c9693e; }
[data-colore="grigio"] { --brand: #4a5662; --brand2: #313a43; --brand-soft: #e8ecef; --brand-l: #c4ced8; --focus: #66788a; }
[data-colore="viola"] { --brand: #5b4b9a; --brand2: #41356f; --brand-soft: #ece9f7; --brand-l: #cbc2f0; --focus: #7464b8; }
/* Tema scuro */
[data-tema="scuro"] {
  --bg: #15191e; --panel: #1e242b; --panel2: #191e24; --head: #252c34; --hover: #262e37; --input: #161b21; --inbrd: #3a4450; --inhover: #4a5562; --ro: #222930;
  --line: #333c46; --line2: #2a323b; --text: #e3e8ee; --muted: #93a0ad; --tagbg: #2c343d; --tagfg: #c3ccd5; --curRow: #2d2f22; --acbrd: #4a5562; --acline: #2a323b;
  --brand-soft: #1f3445; --ok: #4cc283; --ok-soft: #173326; --warn: #e7a83c; --warn-soft: #3a2d14; --err: #ff7b72; --err-soft: #3d1f1d; --err-brd: #6b302b; --sel: #3a3520; --shadow: rgba(0,0,0,.55);
  color-scheme: dark;
}
[data-tema="scuro"] .btn.pri, [data-tema="scuro"] .tile .v { filter: none; }
[data-tema="scuro"][data-colore="verde"] { --brand-soft: #1b3326; } [data-tema="scuro"][data-colore="mattone"] { --brand-soft: #3a2419; } [data-tema="scuro"][data-colore="grigio"] { --brand-soft: #2a323b; } [data-tema="scuro"][data-colore="viola"] { --brand-soft: #2b2645; }
[data-tema="scuro"] .tile .v, [data-tema="scuro"] .banco .totale { color: var(--text); }
/* Dimensione testo e densità */
[data-testo="grande"] { --fs: 14.5px; } [data-testo="molto"] { --fs: 16px; }
[data-densita="comoda"] .tbl td { padding: 8px 10px; } [data-densita="comoda"] .righe td { padding: 3px 2px; } [data-densita="comoda"] #menu a { padding: 7px 14px 7px 22px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", Tahoma, Arial, sans-serif; font-size: var(--fs); color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

/* Struttura */
#app { display: grid; grid-template-columns: var(--menu-w, 205px) minmax(0, 1fr); grid-template-rows: 44px 1fr; height: 100vh; }
#top { grid-column: 1 / 3; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--brand2); color: #fff; }
#top .logo { font-weight: 700; font-size: 16px; letter-spacing: .3px; } #top .logo span { color: var(--brand-l); }
#top .az { opacity: .85; } #top .sp { flex: 1; }
#top .pill { background: rgba(255,255,255,.12); padding: 4px 10px; border-radius: 12px; cursor: pointer; white-space: nowrap; font-size: 12px; }
#top .pill.red { background: #c0392b; } #top .pill.yellow { background: #d68910; } #top .pill.green { background: #1e8449; }
#menu { background: var(--panel2); border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; padding: 6px 0 20px; position: relative; }
#menu-drag { position: fixed; top: 44px; bottom: 0; width: 7px; cursor: col-resize; z-index: 20; }
#menu-drag:hover, #menu-drag.on { background: var(--brand); opacity: .35; }
[data-menu="nascosto"] #app { grid-template-columns: 0 minmax(0, 1fr); } [data-menu="nascosto"] #menu, [data-menu="nascosto"] #menu-drag { display: none; }
#menu a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .burger { font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 4px; user-select: none; } #top .burger:hover { background: rgba(255,255,255,.15); }
#menu .grp { padding: 10px 14px 4px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#menu .grp:hover { color: var(--text); } #menu .grp .fr { width: 10px; display: inline-block; transition: transform .15s; } #menu .grp.chiuso .fr { transform: rotate(-90deg); } #menu .grp.chiuso.dentro { color: var(--brand); }
#menu .grp-items.chiuso { display: none; }
#menu a { display: block; padding: 5px 14px 5px 22px; color: var(--text); text-decoration: none; border-left: 3px solid transparent; }
#menu a:hover { background: var(--brand-soft); } #menu a.on { background: var(--brand-soft); border-left-color: var(--brand); font-weight: 600; }
#menu a .k { float: right; color: var(--muted); font-size: 11px; }
#main { grid-column: 2; grid-row: 2; overflow: auto; padding: 14px 18px 40px; position: relative; }
#offline { position: fixed; left: 0; right: 0; top: 44px; z-index: 50; background: var(--err); color: #fff; text-align: center; padding: 6px; font-weight: 600; }

/* Testate */
.hdr { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.hdr h1 { font-size: 19px; margin: 0; font-weight: 600; } .hdr .sp { flex: 1; } .hdr .sub { color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 4px; } .tile .l { color: var(--muted); font-size: 12px; } .tile.warn .v { color: var(--warn); } .tile.err .v { color: var(--err); }

/* Bottoni */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 6px 12px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--head); } .btn:disabled { opacity: .5; cursor: default; }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.pri:hover { background: var(--brand2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; } .btn.danger { color: var(--err); border-color: var(--err-brd); }
.btn.sm { padding: 3px 8px; font-size: 12px; } .btn.big { padding: 10px 18px; font-size: 15px; font-weight: 600; }
.btn .kb { opacity: .65; font-size: 11px; margin-left: 4px; }
.iconbtn { border: none; background: none; cursor: pointer; color: var(--muted); padding: 2px 6px; font-size: 14px; } .iconbtn:hover { color: var(--err); }

/* Form */
.form { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px 12px; }
.f { display: flex; flex-direction: column; gap: 3px; min-width: 0; } .f > label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.f input, .f select, .f textarea, .inp { border: 1px solid var(--inbrd); border-radius: 4px; padding: 5px 7px; background: var(--input); width: 100%; min-width: 0; }
.f textarea { min-height: 56px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
input[readonly] { background: var(--ro); } .f.chk { flex-direction: row; align-items: center; gap: 6px; padding-top: 18px; } .f.chk input { width: auto; } .f.chk label { font-size: 13px; color: var(--text); font-weight: 400; }
.f.req > label::after { content: ' *'; color: var(--err); }
.c1 { grid-column: span 1; } .c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }
.sep { grid-column: span 12; font-weight: 700; color: var(--brand); border-bottom: 1px solid var(--line2); padding: 6px 0 3px; margin-top: 4px; font-size: 12px; text-transform: uppercase; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .inp { width: auto; }
.search { min-width: 260px; }

/* Tabelle */
.tbl-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; } .tbl th { position: sticky; top: 0; background: var(--head); text-align: left; padding: 6px 8px; font-size: 12px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: default; z-index: 1; }
.tbl td { padding: 5px 8px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
.tbl tbody tr { cursor: pointer; } .tbl tbody tr:hover { background: var(--hover); } .tbl tbody tr.sel { background: var(--sel); }
.tbl .n, .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; } .tbl .c { text-align: center; }
.tbl tfoot td { font-weight: 700; background: var(--panel2); border-top: 1px solid var(--line); }
.muted { color: var(--muted); } .small { font-size: 11.5px; } .b { font-weight: 700; } .err-t { color: var(--err); } .ok-t { color: var(--ok); } .warn-t { color: var(--warn); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--tagbg); color: var(--tagfg); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); } .tag.warn { background: var(--warn-soft); color: var(--warn); } .tag.err { background: var(--err-soft); color: var(--err); } .tag.blue { background: var(--brand-soft); color: var(--brand); }
.pager { display: flex; gap: 8px; align-items: center; padding: 8px; color: var(--muted); }

/* Schede (tab) */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 1px solid transparent; border-bottom: none; background: none; padding: 7px 14px; cursor: pointer; border-radius: 5px 5px 0 0; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--panel); border-color: var(--line); color: var(--text); margin-bottom: -1px; }

/* Editor documento */
.doc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "top side" "rows side"; gap: 0 12px; align-items: start; }
.doc-top { grid-area: top; } .doc-rows { grid-area: rows; } .doc-side { grid-area: side; }
@media (max-width: 1500px) { .doc-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "side" "rows"; } .doc-side { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; } .doc-side .card { margin-bottom: 12px; } }
.righe { width: 100%; border-collapse: collapse; background: var(--panel); }
.righe th { background: var(--head); font-size: 11.5px; padding: 5px 4px; text-align: left; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.righe td { padding: 1px 2px; border-bottom: 1px solid var(--line2); }
.righe input, .righe select { border: 1px solid transparent; padding: 4px 4px; width: 100%; background: transparent; border-radius: 3px; }
.righe input:hover, .righe select:hover { border-color: var(--inhover); } .righe input:focus, .righe select:focus { background: var(--input); }
.righe tr.descr input.descr { font-style: italic; font-weight: 600; } .righe .num input { text-align: right; }
.righe tr.cur { background: var(--curRow); } .righe .hint { font-size: 10.5px; color: var(--muted); padding: 0 5px; white-space: nowrap; }
.righe .hint.neg { color: var(--err); font-weight: 700; }
.totbox { font-size: 13px; } .totbox .r { display: flex; justify-content: space-between; padding: 3px 0; } .totbox .big { font-size: 20px; font-weight: 700; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 6px; }
.alert { padding: 8px 10px; border-radius: 5px; margin-bottom: 8px; } .alert.err { background: var(--err-soft); color: var(--err); } .alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.ok { background: var(--ok-soft); color: var(--ok); } .alert.info { background: var(--brand-soft); color: var(--brand2); }

/* Ricerca a tendina */
.ac { position: relative; } .ac-list { position: absolute; z-index: 1000; background: var(--panel); border: 1px solid var(--acbrd); box-shadow: 0 6px 18px var(--shadow); max-height: 330px; overflow-y: auto; min-width: 100%; border-radius: 4px; }
.ac-list div { padding: 5px 8px; cursor: pointer; white-space: nowrap; border-bottom: 1px solid var(--acline); } .ac-list div.on { background: var(--brand-soft); }
.ac-list .s { color: var(--muted); font-size: 11.5px; margin-left: 8px; } .ac-list .r { float: right; margin-left: 16px; color: var(--muted); font-size: 11.5px; }

/* Finestre */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,40,.45); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding-top: 6vh; }
.modal { background: var(--panel); border-radius: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.3); width: 560px; max-width: 94vw; max-height: 86vh; display: flex; flex-direction: column; }
.modal.wide { width: 900px; } .modal .mh { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 15px; display: flex; }
.modal .mh .x { margin-left: auto; cursor: pointer; color: var(--muted); } .modal .mb { padding: 14px 16px; overflow: auto; } .modal .mf { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #23313f; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 420px; white-space: pre-wrap; }
.toast.err { background: var(--err); } .toast.ok { background: var(--ok); }

/* Login */
.login { max-width: 360px; margin: 12vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 26px; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.login h2 { margin: 0 0 4px; color: var(--brand2); } .login .f { margin-top: 12px; } .login .btn { width: 100%; margin-top: 18px; padding: 9px; }

/* Banco */
.banco { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; height: calc(100vh - 110px); }
.banco .left { display: flex; flex-direction: column; min-height: 0; } .banco .scan { font-size: 18px; padding: 10px; }
.banco .totale { font-size: 40px; font-weight: 800; text-align: right; color: var(--brand2); }
.banco .pay { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; } .banco .pay .btn { padding: 14px 6px; font-size: 14px; font-weight: 700; white-space: normal; }
.banco > div { min-width: 0; }
.kbd { display: inline-block; border: 1px solid var(--inbrd); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; font-size: 11px; background: var(--panel2); }
@media print { #menu, #top, .noprint { display: none !important; } #app { display: block; } }
[data-tema="scuro"] .btn.ok { background: #1e7d46; border-color: #1e7d46; } [data-tema="scuro"] #offline, [data-tema="scuro"] .toast.err { background: #b3261e; }
[data-tema="scuro"] .modal-bg { background: rgba(0,0,0,.6); } [data-tema="scuro"] .toast { background: #303a45; }
/* Anteprime aspetto */
.aspetto-op { display: flex; gap: 8px; flex-wrap: wrap; } .aspetto-op button { border: 2px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; min-width: 110px; }
.aspetto-op button.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); font-weight: 700; }
.aspetto-op .sw { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 6px; vertical-align: -2px; }
[data-tema="scuro"] .alert.info { color: var(--brand-l); } [data-tema="scuro"] .alert.info a, [data-tema="scuro"] a { color: var(--brand-l); }

#menu a.fisso { padding: 8px 14px; font-weight: 600; border-bottom: 1px solid var(--line2); margin-bottom: 4px; }

/* Icone */
.ico { display: inline-flex; width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; } .ico svg { width: 100%; height: 100%; }
.btn .ico { margin-right: 4px; } .btn .ico:last-child:not(:first-child) { margin: 0 0 0 4px; }
#menu a.fisso .ico { margin-right: 8px; } #menu .grp .fr .ico { width: 12px; height: 12px; vertical-align: -1px; }
#top .burger .ico { width: 20px; height: 20px; vertical-align: -4px; } #top .pill .ico { width: 14px; height: 14px; vertical-align: -2px; }
.iconbtn .ico { width: 14px; height: 14px; } .modal .mh .x .ico { width: 16px; height: 16px; }
#menu .grp .fr { width: 12px; }
