/* Implanet MDM - console in stile "enterprise" (struttura ispirata a Knox Manage, marchio proprio) */
:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1d2939;
  --muted: #667085;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --brand: #1756c2;
  --brand-dark: #0f3f94;
  --brand-soft: #e8f0fe;
  --header: #0b2a5b;
  --danger: #d92d20;
  --danger-soft: #fee4e2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --radius: 6px;
  --sidebar-w: 236px;
  --topbar-h: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 18px 0 8px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- Struttura ---------- */
.topbar { height: var(--topbar-h); background: var(--header); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 16px; position: sticky; top: 0; z-index: 50; }
.topbar-brand { color: #fff; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.topbar-brand:hover { text-decoration: none; }
.logo { width: 13px; height: 22px; border: 3px solid #5b9bff; border-radius: 4px; display: inline-block; }
.topbar-search { flex: 1; max-width: 520px; margin-left: 24px; }
.topbar-search input { width: 100%; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff; border-radius: 4px; padding: 7px 12px; }
.topbar-search input::placeholder { color: rgba(255,255,255,.65); }
.topbar-search input:focus { outline: none; background: rgba(255,255,255,.2); }
.topbar-user { margin-left: auto; position: relative; }
.user-btn { background: none; border: none; color: #fff; display: flex; align-items: center; gap: 8px; cursor: pointer; font: inherit; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #5b9bff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase; }
.user-menu { position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16,24,40,.15); min-width: 190px; padding: 6px 0; }
.user-menu a, .user-menu button { display: block; width: 100%; text-align: left; padding: 8px 16px; color: var(--text); background: none; border: none; font: inherit; cursor: pointer; }
.user-menu a:hover, .user-menu button:hover { background: var(--bg); text-decoration: none; }
.icon-btn { background: none; border: none; color: inherit; font-size: 20px; cursor: pointer; padding: 4px 8px; }
.menu-toggle { display: none; }

.shell-body { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar { width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--border); flex-shrink: 0; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; }
nav { padding: 10px 0 20px; }
.nav-section { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: #98a2b3; padding: 16px 20px 6px; }
nav a { display: flex; align-items: center; gap: 12px; padding: 9px 20px; color: #344054; border-left: 3px solid transparent; font-weight: 500; }
nav a svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: #667085; }
nav a:hover { background: var(--bg); text-decoration: none; }
nav a.active { background: var(--brand-soft); color: var(--brand-dark); border-left-color: var(--brand); }
nav a.active svg { color: var(--brand); }
main { flex: 1; min-width: 0; padding: 20px 28px 48px; }

/* ---------- Testata pagina ---------- */
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs span + span::before { content: "›"; margin: 0 6px; color: #98a2b3; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Componenti ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.card.flush { padding: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.card-body { padding: 16px 20px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.mt { margin-top: 16px; }

.btn { border: 1px solid var(--border-strong); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 4px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: #fda29b; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.link { border: none; background: none; padding: 0; color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 500; margin-bottom: 14px; }
label > input:not([type=checkbox]), label > select, label > textarea { display: block; width: 100%; margin-top: 5px; }
.hint { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 4px; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 4px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b2ccff; border-color: var(--brand); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
label.check input { margin-top: 2px; }
label.check b { display: block; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.error { color: var(--danger); min-height: 18px; }

/* Interruttore (on/off) */
.switch { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border); font-weight: 400; margin: 0; cursor: pointer; }
.switch:last-of-type { border-bottom: none; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: #d0d5dd; position: relative; flex-shrink: 0; transition: background .15s; margin: 0; border: none; padding: 0; }
.switch input::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { left: 18px; }
.switch b { display: block; font-weight: 600; margin-bottom: 2px; }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th { background: #f9fafb; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
tr.click:hover td, tr.selected td { background: #f5f8ff; }
th.cb, td.cb { width: 36px; padding-right: 0; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); gap: 12px; flex-wrap: wrap; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* Barra filtri e barra azioni multiple */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px; background: var(--brand-soft); border-bottom: 1px solid #c7d7fe; }
.bulkbar b { margin-right: 8px; color: var(--brand-dark); }

/* Badge e tag */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: #f2f4f7; color: var(--muted); font-weight: 500; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: #f2f4f7; color: #98a2b3; }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.plain::before { display: none; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 4px; background: #eef4ff; color: #3538cd; white-space: nowrap; }
.tag.gray { background: #f2f4f7; color: #475467; }

/* Schede (tab) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Pagina con menu categorie (profili, impostazioni) */
.split { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.catmenu { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 0; position: sticky; top: calc(var(--topbar-h) + 16px); }
.catmenu a { display: flex; justify-content: space-between; padding: 9px 16px; color: #344054; border-left: 3px solid transparent; }
.catmenu a:hover { background: var(--bg); text-decoration: none; }
.catmenu a.active { background: var(--brand-soft); color: var(--brand-dark); border-left-color: var(--brand); font-weight: 600; }
.catmenu .state { font-size: 11px; color: var(--muted); font-weight: 400; }

/* Testata dispositivo */
.device-hero { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.device-icon { width: 54px; height: 54px; border-radius: 10px; background: var(--brand-soft); display: flex; align-items: center; justify-content: center; }
.device-icon svg { width: 28px; height: 28px; stroke: var(--brand); fill: none; stroke-width: 1.8; }
.device-hero .facts { display: flex; gap: 28px; flex-wrap: wrap; margin-left: auto; }
.facts div span { display: block; font-size: 11.5px; color: var(--muted); }
.facts div b { font-weight: 600; }

/* KPI dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: block; color: var(--text); border-top: 3px solid var(--border-strong); }
.kpi:hover { text-decoration: none; box-shadow: 0 2px 8px rgba(16,24,40,.08); }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1.2; }
.kpi .l { color: var(--muted); font-size: 12.5px; }
.kpi.ok { border-top-color: #17b26a; } .kpi.warn { border-top-color: #f79009; } .kpi.err { border-top-color: var(--danger); } .kpi.brand { border-top-color: var(--brand); }
.bars .bar-row { display: grid; grid-template-columns: 120px 1fr 36px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bars .track { height: 8px; background: #f2f4f7; border-radius: 4px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--brand); border-radius: 4px; }
.stacked { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #f2f4f7; margin: 6px 0 12px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

dl.info { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; word-break: break-word; }

/* Campi da copiare (KME) */
.copyfield { margin-bottom: 14px; }
.copyfield > span { display: block; font-weight: 600; margin-bottom: 4px; }
.copyfield .row input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: #f9fafb; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #f2f4f7; color: #344054; padding: 3px 6px 3px 10px; border-radius: 99px; font-size: 13px; border: 1px solid var(--border); }
.chip.red { background: var(--danger-soft); color: #912018; border-color: #fecdca; }
.chip.green { background: var(--ok-soft); color: #085d3a; border-color: #abefc6; }
.chip button { border: none; background: none; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; padding: 0 4px; }

.notice { background: #eff8ff; border: 1px solid #b2ddff; color: #194185; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.notice.warn { background: #fffaeb; border-color: #fedf89; color: #93370d; }
.notice.err { background: #fef3f2; border-color: #fecdca; color: #912018; }
ol.steps { padding-left: 20px; margin: 0; }
ol.steps li { margin-bottom: 8px; }
pre.code { background: #f2f4f7; padding: 10px 12px; border-radius: 4px; white-space: pre-wrap; word-break: break-all; margin: 6px 0 12px; }

.qr { text-align: center; }
.qr img { width: 340px; max-width: 100%; border: 1px solid var(--border); border-radius: 6px; }

/* Mappe (OpenLayers) */
.map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; position: relative; background: #e5e7eb; }
.map.full { height: calc(100vh - 170px); min-height: 400px; }
.map.small { height: 320px; }
.map-popup { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; box-shadow: 0 4px 14px rgba(0,0,0,.18); font-size: 13px; min-width: 150px; max-width: 260px; position: relative; }
.map-popup::after { content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: #fff; }
.map-tools { top: .5em; right: .5em; display: flex; gap: 4px; }
.map-tools button { width: auto !important; padding: 0 8px; font-size: 12px !important; font-weight: 500; }
.map-tools button.active { background: var(--brand); color: #fff; }
.map-tools-sep { width: 6px; }

/* Accesso */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #0b2a5b 0%, #1756c2 100%); }
.login-card { width: 100%; max-width: 380px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-brand .logo { border-color: var(--brand); width: 16px; height: 28px; }
.login-brand b { display: block; font-size: 19px; }
.login-brand span { color: var(--muted); font-size: 13px; }

/* Avvisi e finestre */
.toast { position: fixed; bottom: 20px; right: 20px; background: #101828; color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 2000; max-width: 440px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: flex; align-items: center; justify-content: center; z-index: 1500; padding: 16px; }
.modal-box { width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal-box .actions { justify-content: flex-end; margin-top: 8px; }

@media (max-width: 900px) {
  .menu-toggle { display: block; }
  .topbar-search { display: none; }
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 16px rgba(0,0,0,.1); }
  .sidebar.open { transform: none; }
  main { padding: 16px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .catmenu { position: static; display: flex; overflow-x: auto; padding: 0; }
  .catmenu a { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .catmenu a.active { border-bottom-color: var(--brand); }
  dl.info { grid-template-columns: 130px 1fr; }
  .device-hero .facts { margin-left: 0; }
  .topbar-user #me { display: none; }
}
