/* JakiWare Master Admin — stile coerente con jakiware.com (blu notte, ciano/blu/viola, Inter + Space Grotesk). */
@font-face { font-family: "Inter"; src: url("/assets/fonts/inter-var.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("/assets/fonts/space-grotesk-var.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }

:root {
  --bg: #05080f; --bg-2: #080e1b; --panel: rgba(15, 25, 45, .66); --panel-2: rgba(19, 31, 55, .86); --panel-solid: #0c1526;
  --line: rgba(148, 178, 230, .14); --line-2: rgba(148, 178, 230, .26);
  --text: #eef3ff; --muted: #a7b5cb; --muted-2: #8a9ab3;
  --cyan: #5ee8f2; --blue: #5b8cff; --violet: #a98bff; --ok: #72f2c2; --warn: #ffcf7a; --bad: #ff7a8a; --info: #93c2ff;
  --accent: var(--cyan); --radius: 18px; --radius-sm: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --side: 248px; --top: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
[data-theme="light"] {
  --bg: #f4f7fc; --bg-2: #eaf0f9; --panel: rgba(255, 255, 255, .86); --panel-2: #ffffff; --panel-solid: #ffffff;
  --line: rgba(20, 40, 80, .12); --line-2: rgba(20, 40, 80, .22); --text: #0b1426; --muted: #4a5a74; --muted-2: #66758d;
  --cyan: #0f9fb0; --blue: #2f5fe0; --violet: #6f4fd8; --ok: #0f9f6e; --warn: #b7791f; --bad: #d23a52; --info: #2f6fce;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.5 var(--font); color: var(--text); background: var(--bg);
  background-image: radial-gradient(1200px 600px at 85% -10%, rgba(91, 140, 255, .13), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(94, 232, 242, .08), transparent 60%);
  background-attachment: fixed; -webkit-font-smoothing: antialiased; overflow-wrap: anywhere;
}
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(22px, 3vw, 28px); }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.logo-mark { width: 34px; height: 34px; border-radius: 10px; display: inline-block; background: url("/favicon.svg") center/contain no-repeat; }

/* ---- Struttura */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line); background: linear-gradient(180deg, rgba(8, 14, 27, .92), rgba(5, 8, 15, .92)); padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; }
[data-theme="light"] .side { background: #fff; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-family: var(--display); font-weight: 600; }
.brand small { display: block; color: var(--muted-2); font: 500 11px/1.2 var(--font); letter-spacing: .08em; text-transform: uppercase; }
.nav-group { margin: 12px 8px 4px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: linear-gradient(90deg, rgba(94, 232, 242, .16), rgba(91, 140, 255, .08)); color: var(--text); box-shadow: inset 2px 0 0 var(--cyan); }
.nav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: none; }
.dot.ok { background: var(--ok); } .dot.stale, .dot.never { background: var(--warn); } .dot.down { background: var(--bad); } .dot.planned { background: var(--violet); }
.side-foot { margin-top: auto; padding: 12px 8px 0; color: var(--muted-2); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; height: var(--top); display: flex; align-items: center; gap: 12px; padding: 0 clamp(14px, 3vw, 28px); border-bottom: 1px solid var(--line); background: rgba(5, 8, 15, .78); backdrop-filter: blur(14px); }
[data-theme="light"] .top { background: rgba(244, 247, 252, .85); }
.top .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: clamp(16px, 3vw, 30px); display: flex; flex-direction: column; gap: 18px; max-width: 1500px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head p { color: var(--muted); margin-top: 4px; }

/* ---- Componenti */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; backdrop-filter: blur(10px); min-width: 0; }
.card > h2, .card > header { margin-bottom: 12px; }
.card header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; }
.kpi .value { font: 600 22px/1.25 var(--display); margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value .cur { display: block; }
.kpi .hint { color: var(--muted-2); font-size: 12px; margin-top: 6px; }
.kpi::after { content: ""; position: absolute; inset: auto -30% -60% auto; width: 140px; height: 140px; border-radius: 50%; background: radial-gradient(circle, rgba(94, 232, 242, .1), transparent 70%); pointer-events: none; }
.nature { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); }
.nature.contracted { color: var(--blue); border-color: rgba(91, 140, 255, .4); }
.nature.collected, .nature.real { color: var(--ok); border-color: rgba(114, 242, 194, .4); }
.nature.estimated { color: var(--warn); border-color: rgba(255, 207, 122, .4); }
.nature.to_reconcile { color: var(--violet); border-color: rgba(169, 139, 255, .45); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: rgba(148, 178, 230, .1); color: var(--muted); white-space: nowrap; }
.badge.ok, .badge.active, .badge.paid, .badge.approved { background: rgba(114, 242, 194, .12); color: var(--ok); }
.badge.warn, .badge.stale, .badge.past_due, .badge.open, .badge.trial, .badge.onboarding, .badge.pending, .badge.in_progress, .badge.submitted, .badge.never { background: rgba(255, 207, 122, .12); color: var(--warn); }
.badge.bad, .badge.down, .badge.suspended, .badge.overdue, .badge.failed, .badge.critical, .badge.rejected { background: rgba(255, 122, 138, .13); color: var(--bad); }
.badge.cancelled, .badge.ended, .badge.disabled { background: rgba(148, 178, 230, .08); color: var(--muted-2); }
.badge.planned, .badge.info { background: rgba(169, 139, 255, .14); color: var(--violet); }
.badge.env { background: rgba(255, 207, 122, .15); color: var(--warn); text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }

.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-2); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: rgba(148, 178, 230, .04); }
.empty { color: var(--muted-2); padding: 18px 4px; text-align: center; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted-2); } .kv dd { margin: 0; }
.note { border-left: 3px solid var(--info); background: rgba(147, 194, 255, .07); padding: 10px 12px; border-radius: 0 10px 10px 0; font-size: 13.5px; color: var(--muted); }
.note.warn { border-color: var(--warn); background: rgba(255, 207, 122, .07); }
.note.bad { border-color: var(--bad); background: rgba(255, 122, 138, .08); }
.note.ok { border-color: var(--ok); background: rgba(114, 242, 194, .07); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; min-height: 38px; padding: 8px 14px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text); text-decoration: none; }
.btn:hover { border-color: var(--cyan); text-decoration: none; }
.btn.primary { background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #031019; border: 0; }
.btn.danger { border-color: rgba(255, 122, 138, .5); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: transparent; cursor: pointer; color: var(--text); }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line-2); background: rgba(5, 8, 15, .5); color: var(--text); font-size: 15px; }
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { background: #fff; }
textarea { min-height: 80px; resize: vertical; }
select { -webkit-appearance: none; appearance: none; padding-right: 32px; background-repeat: no-repeat; background-position: right 10px center; background-size: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a7b5cb' stroke-width='1.6'/%3E%3C/svg%3E"); }
select option { background: var(--panel-solid); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(94, 232, 242, .15); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.err { color: var(--bad); font-size: 13px; min-height: 1em; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 12px; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--text); border-color: var(--cyan); text-decoration: none; }

.chart { width: 100%; height: 180px; }
.chart .bar { fill: url(#gbar); }
.chart .bar2 { fill: var(--violet); opacity: .8; }
.chart text { fill: var(--muted-2); font-size: 10px; font-family: var(--font); }
.chart .axis { stroke: var(--line-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--cyan); }
.legend i.v { background: var(--violet); }

.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(2, 4, 9, .72); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(4px); }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 22px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.modal h2 { margin-bottom: 8px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast .t { background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, .4); font-size: 14px; max-width: min(92vw, 520px); }
#toast .t.bad { border-color: var(--bad); } #toast .t.ok { border-color: var(--ok); }

/* ---- Utilità (nessuno stile in linea: CSP style-src 'self') */
.text-bad { color: var(--bad); } .spread { justify-content: space-between; } .loose { line-height: 1.8; }
.subcard { margin-bottom: 10px; background: var(--panel-2); } .mt-6 { margin-top: 6px; } .mt-8 { margin-top: 8px; } .mt-10 { margin-top: 10px; } .mt-12 { margin-top: 12px; } .mt-14 { margin-top: 14px; }
.list { margin: 0; padding-left: 18px; } .plain { text-decoration: none; color: inherit; } .plain:hover { text-decoration: none; border-color: var(--line-2); } .break { word-break: break-all; }

/* ---- Accesso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 22px; padding: clamp(22px, 5vw, 34px); backdrop-filter: blur(14px); box-shadow: 0 30px 90px rgba(0, 0, 0, .35); }
.auth-card .brand { padding: 0 0 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .lang { margin-top: 18px; display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.otp { letter-spacing: .4em; text-align: center; font: 600 24px/1 var(--display); }
.qr { background: #fff; padding: 12px; border-radius: 14px; width: 220px; max-width: 100%; margin: 4px auto; }
.qr svg { display: block; width: 100%; height: auto; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: ui-monospace, Consolas, monospace; font-size: 15px; background: rgba(5, 8, 15, .5); padding: 12px; border-radius: 12px; border: 1px dashed var(--line-2); }
.lang-select { width: auto; min-height: 34px; padding: 4px 8px; font-size: 13px; }

/* ---- Telefono e tablet */
@media (max-width: 1023px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(84vw, 300px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: 20px 0 60px rgba(0, 0, 0, .5); }
  .shell.nav-open .side { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; z-index: 40; background: rgba(2, 4, 9, .55); }
  .menu-btn { display: inline-grid; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .content { padding: 14px 12px calc(24px + var(--safe-b)); gap: 14px; }
  .card { padding: 14px; border-radius: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 18px; }
  .top .who { display: none; }
  .top { gap: 8px; padding: 0 10px; }
  .top .lang-select { max-width: 118px; }
  .badge.env { display: none; }
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 2px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted-2); font-size: 12px; text-align: left; flex: none; max-width: 45%; }
  table.responsive td.num { white-space: normal; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}
@media (max-width: 380px) { .kpis { grid-template-columns: 1fr; } }

/* ---- Stampa (report PDF dal browser) */
@media print {
  :root { --text: #000; --muted: #333; --muted-2: #555; --line: #ccc; --line-2: #999; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .side, .top, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: 1px solid #bbb; background: #fff; break-inside: avoid; backdrop-filter: none; }
  a { color: #000; }
  .badge, .nature { border: 1px solid #999; background: none !important; color: #000 !important; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
