:root {
  --bg: #f6f6f8; --card: #ffffff; --fg: #1c1c1e; --muted: #6b6b72; --line: #e4e4ea;
  --accent: #c2185b; --accent-soft: #fce4ef; --ok: #1b7f4b; --ok-soft: #e3f5ea;
  --warn: #9a5b00; --warn-soft: #fff3dc; --err: #b42318; --err-soft: #fde8e7;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --card: #1b1b1f; --fg: #f1f1f4; --muted: #9b9ba3; --line: #2c2c33;
    --accent: #ff5c9d; --accent-soft: #3a1828; --ok: #4cc38a; --ok-soft: #13301f;
    --warn: #f0b44c; --warn-soft: #34270f; --err: #ff6b5f; --err-soft: #3a1714;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.side { width: 306px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px;
        position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-weight: 700; padding: 4px 10px 16px; }
.brand span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.logo { font-size: 43px; line-height: 1.1; font-weight: 800; letter-spacing: -.02em; color: var(--fg);
        display: flex; align-items: center; gap: .22em; white-space: nowrap; }
.logo-mark, .brand .logo .logo-mark { color: var(--accent); display: inline-flex; flex-shrink: 0; font-size: inherit; margin: 0; }
.brand .logo .logo-text { display: inline; font-size: inherit; font-weight: 800; color: var(--fg); margin: 0; }
.logo-mark svg { width: 1.03em; height: 1.2em; display: block; }
.logo b { color: var(--accent); font-weight: 800; }
.tagline { font-size: 13.5px; font-weight: 600; line-height: 1.35; color: var(--fg); margin: 6px 0 8px; white-space: nowrap; }
.brand span { margin-top: 2px; }
.account, .brand .account { display: block; margin-top: 30px; padding: 9px 12px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  font-size: 13px; font-weight: 600; }
h1.logo { font-size: 42px; margin: 0 0 8px; }
.brand .account .small { display: block; color: var(--accent); opacity: .8; margin: 0; }
.switch { padding: 0 10px 12px; } .switch select { width: 100%; margin-top: 4px; }
.side > .banner { display: block; margin: 0 10px 12px; text-decoration: none; }
.creds { font-family: ui-monospace, Consolas, monospace; user-select: all; }
.login .tagline { font-size: 15px; margin: 0 0 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--fg); margin-bottom: 2px; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .bottom { margin-top: auto; font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; max-width: 1200px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* componenti */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 700; } .kpi .l { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); } .flash.errore { background: var(--err-soft); color: var(--err); }
.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }

/* barre */
.bar-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 13px; }
.bar-row .lab { width: 190px; flex-shrink: 0; }
.bar { flex: 1; height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row .val { width: 80px; text-align: right; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.spark div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }

/* tabelle e liste */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table-wrap { overflow-x: auto; }
.feed li, .list li { list-style: none; padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.feed, .list { padding: 0; margin: 0; }
.feed .t { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* form */
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); font: inherit; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; margin: 10px 0; }
.check input { width: 18px; height: 18px; }
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--fg); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline { display: inline; }
details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.days { display: flex; gap: 6px; flex-wrap: wrap; } .days label { display: flex; gap: 4px; align-items: center; margin: 0; color: var(--fg); }

/* automazioni */
.auto { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.auto:last-child { border-bottom: 0; }
.auto .info { flex: 1; min-width: 220px; }
.auto .stats { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.auto .stats b { color: var(--fg); font-size: 16px; display: block; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--line); flex-shrink: 0; }
.posts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; max-height: 360px; overflow-y: auto; }
.post { position: relative; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; font-size: 11px; margin: 0; color: var(--fg); background: var(--card); }
.post img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--line); }
.post span { display: block; padding: 4px 6px; height: 34px; overflow: hidden; }
.post input { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; }
.post:has(input:checked) { border-color: var(--accent); }
.tpl { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tpl a { display: block; border: 1px dashed var(--line); border-radius: 10px; padding: 14px; color: var(--fg); }
.tpl a:hover { border-color: var(--accent); text-decoration: none; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 520px; overflow-y: auto; padding: 4px; }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; }
.msg.out { background: var(--accent-soft); align-self: flex-end; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* calendario */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.day { background: var(--bg); border-radius: 10px; padding: 8px; min-height: 90px; font-size: 12px; }
.day .d { font-weight: 600; margin-bottom: 6px; }
.day .p { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; margin-bottom: 4px; }
pre.out { white-space: pre-wrap; background: var(--bg); padding: 14px; border-radius: 10px; font: 14px/1.5 system-ui, sans-serif; }

/* guida */
.guida-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.toc { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.toc a { padding: 4px 6px; border-radius: 6px; color: var(--fg); } .toc a:hover { background: var(--bg); text-decoration: none; }
.guida { line-height: 1.6; } .guida section { margin-bottom: 26px; scroll-margin-top: 16px; }
.guida h2 { font-size: 19px; margin: 6px 0 10px; } .guida h3 { margin-top: 16px; }
.guida .steps > li { margin-bottom: 10px; } .guida ul ul { margin-top: 4px; }
.guida .code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--bg); padding: 1px 6px; border-radius: 6px; word-break: break-all; }
.guida .nota { display: block; background: var(--accent-soft); color: var(--fg); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 8px; margin: 8px 0; }
.guida dl.faq dt { font-weight: 700; margin-top: 12px; } .guida dl.faq dd { margin: 4px 0 0; }
.guida table { margin: 8px 0 12px; } .guida hr { border: 0; border-top: 2px solid var(--line); margin: 30px 0; }
.guida-sez { font-size: 24px; }
@media (max-width: 860px) { .guida-layout { grid-template-columns: 1fr; } .toc { position: static; } }
@media print { .side, .toc, .banner, .flash { display: none !important; } .guida-layout { display: block; } .main { padding: 0; } .card { border: 0; box-shadow: none; } }

/* login */
.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; }

/* mobile */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; gap: 4px; }
  .brand { padding: 0 8px; white-space: nowrap; } .brand span, .brand .tagline { display: none; }
  .brand .logo { font-size: 20px; } .brand .account { display: none; }
  .nav { display: flex; gap: 2px; } .nav a { white-space: nowrap; padding: 8px; }
  .side .bottom, .side .switch, .side > .banner { display: none; }
  .main { padding: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .week { grid-template-columns: repeat(2, 1fr); }
  .bar-row .lab { width: 120px; }
  .msg { max-width: 90%; }
}
