/* LucaOS — tema e componenti di base. Nessuno stile inline: la CSP lo vieta. */
@font-face { font-family: "KaTeX_Main"; src: url("../vendor/katex/fonts/KaTeX_Main-Regular.woff2") format("woff2"); font-display: swap; }
:root {
  --bg: #11161a; --surface: #181f24; --surface2: #1f282e; --raise: #26323a; --line: #2b363d;
  --text: #e4ebe9; --muted: #8d9da3; --accent: #43b5a0; --accent-ink: #06201b; --accent-soft: rgba(67,181,160,.16);
  --brass: #c8a45a; --danger: #e5766a; --ok: #6bbf8a; --warn: #d9a441;
  --shadow: 0 18px 50px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.3);
  --r: 10px; --rs: 6px; --rail: 64px; --bar: 42px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --serif: "KaTeX_Main", "Latin Modern Roman", Georgia, serif;
  --fs: 1; color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e6ecea; --surface: #f6f8f7; --surface2: #edf1f0; --raise: #ffffff; --line: #ccd6d3;
  --text: #162024; --muted: #53656b; --accent: #1b7767; --accent-ink: #ffffff; --accent-soft: rgba(27,119,103,.12);
  --brass: #8a6a1d; --danger: #b43a2d; --ok: #2c7a48; --warn: #8a6410;
  --shadow: 0 14px 40px rgba(20,40,40,.22), 0 2px 6px rgba(20,40,40,.12); color-scheme: light;
}
:root[data-accent="ottone"] { --accent: #c8a45a; --accent-ink: #231a05; --accent-soft: rgba(200,164,90,.16); }
:root[data-accent="indaco"] { --accent: #8794f2; --accent-ink: #0c1237; --accent-soft: rgba(135,148,242,.16); }
:root[data-accent="rosa"] { --accent: #e583a8; --accent-ink: #3a0c20; --accent-soft: rgba(229,131,168,.16); }
:root[data-theme="light"][data-accent="ottone"] { --accent: #8a6a1d; --accent-ink: #fff; --accent-soft: rgba(138,106,29,.13); }
:root[data-theme="light"][data-accent="indaco"] { --accent: #4452c4; --accent-ink: #fff; --accent-soft: rgba(68,82,196,.12); }
:root[data-theme="light"][data-accent="rosa"] { --accent: #b23d6b; --accent-ink: #fff; --accent-soft: rgba(178,61,107,.12); }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: calc(14px * var(--fs))/1.45 var(--ui); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--raise) transparent; }

/* ---------- guscio ---------- */
#os { position: fixed; inset: 0; display: grid; grid-template-columns: var(--rail) 1fr; grid-template-rows: var(--bar) 1fr; grid-template-areas: "rail top" "rail desk"; }
#rail { grid-area: rail; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px; z-index: 5000; }
#top { grid-area: top; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 12px; z-index: 5000; }
#desk { grid-area: desk; position: relative; overflow: hidden; }
#wall { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#wins { position: absolute; inset: 0; }
.rail-btn { position: relative; width: 46px; height: 46px; border-radius: 12px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.rail-btn:hover { background: var(--raise); color: var(--text); }
.rail-btn.run::after { content: ""; position: absolute; left: -9px; top: 19px; width: 4px; height: 8px; border-radius: 0 3px 3px 0; background: var(--muted); }
.rail-btn.act { color: var(--accent); background: var(--accent-soft); }
.rail-btn.act::after { background: var(--accent); height: 20px; top: 13px; }
.rail-btn[data-tip]:hover::before { content: attr(data-tip); position: absolute; left: 54px; top: 50%; transform: translateY(-50%); background: var(--raise); border: 1px solid var(--line); padding: 3px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap; z-index: 9999; pointer-events: none; color: var(--text); }
.rail-sp { flex: 1; }
.rail-launch { color: var(--accent-ink); background: var(--accent); }
.rail-launch:hover { background: var(--accent); color: var(--accent-ink); filter: brightness(1.1); }
.brand { font-family: var(--serif); font-size: 18px; letter-spacing: .2px; display: flex; align-items: baseline; gap: 0; } .brand small { margin-left: 8px; }
.brand b { color: var(--accent); font-weight: 600; }
.brand small { color: var(--muted); font: 12px var(--ui); }
.top-sp { flex: 1; }
.pill { height: 30px; border-radius: 15px; border: 1px solid var(--line); background: var(--surface2); display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--muted); cursor: pointer; min-width: 220px; }
.pill:hover { border-color: var(--accent); color: var(--text); }
.pill kbd { margin-left: auto; font: 11px var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.tray { display: flex; align-items: center; gap: 4px; }
.tray-btn { height: 30px; min-width: 30px; padding: 0 8px; border: 0; background: transparent; border-radius: 8px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tray-btn:hover { background: var(--raise); color: var(--text); }
.clock { font-variant-numeric: tabular-nums; color: var(--text); cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--danger); } .dot.warn { background: var(--warn); }

/* ---------- finestre ---------- */
.win { position: absolute; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; outline: none; }
.win:not(.on) { box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.win:not(.on) .win-bar { opacity: .72; }
.win.min { display: none; }
.win.max { left: 0 !important; top: 0 !important; width: 100% !important; height: 100% !important; border-radius: 0; border: 0; }
.win.moving { user-select: none; } .win.moving .win-body { pointer-events: none; }
.win-bar { height: 36px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 6px 0 12px; background: var(--surface2); border-bottom: 1px solid var(--line); cursor: grab; user-select: none; touch-action: none; }
.win-ico { color: var(--accent); display: grid; }
.win-title { flex: 1; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-btns { display: flex; gap: 2px; }
.wbtn { width: 30px; height: 26px; border: 0; background: transparent; border-radius: 6px; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.wbtn:hover { background: var(--raise); color: var(--text); } .wbtn.close:hover { background: var(--danger); color: #fff; }
.win-body { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.rz { position: absolute; z-index: 3; } .win.max .rz { display: none; }
.rz-n { top: -3px; left: 8px; right: 8px; height: 7px; cursor: n-resize; } .rz-s { bottom: -3px; left: 8px; right: 8px; height: 7px; cursor: s-resize; }
.rz-e { right: -3px; top: 8px; bottom: 8px; width: 7px; cursor: e-resize; } .rz-w { left: -3px; top: 8px; bottom: 8px; width: 7px; cursor: w-resize; }
.rz-ne { top: -3px; right: -3px; width: 12px; height: 12px; cursor: ne-resize; } .rz-nw { top: -3px; left: -3px; width: 12px; height: 12px; cursor: nw-resize; }
.rz-se { bottom: -3px; right: -3px; width: 12px; height: 12px; cursor: se-resize; } .rz-sw { bottom: -3px; left: -3px; width: 12px; height: 12px; cursor: sw-resize; }

/* ---------- componenti ---------- */
.btn { height: 30px; padding: 0 12px; border-radius: var(--rs); border: 1px solid var(--line); background: var(--raise); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); } .btn:disabled { opacity: .45; cursor: not-allowed; border-color: var(--line); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; } .btn.pri:hover { filter: brightness(1.08); }
.btn.dng { color: var(--danger); } .btn.dng:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; } .btn.ghost:hover { background: var(--raise); border-color: transparent; }
.btn.ico { width: 30px; padding: 0; justify-content: center; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.inp, .sel, .ta { height: 30px; border-radius: var(--rs); border: 1px solid var(--line); background: var(--bg); padding: 0 10px; min-width: 0; }
.ta { height: auto; padding: 8px 10px; resize: vertical; font-family: var(--mono); }
.inp:focus, .sel:focus, .ta:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tools { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--surface); flex: none; flex-wrap: wrap; }
.tools .sp { flex: 1; } .sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }
.status { flex: none; padding: 3px 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; display: flex; gap: 14px; background: var(--surface2); }
.scroll { overflow: auto; min-height: 0; flex: 1; }
.empty { display: grid; place-items: center; text-align: center; color: var(--muted); padding: 40px 20px; gap: 6px; }
.empty b { color: var(--text); font-size: 15px; }
.card { background: var(--surface2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.muted { color: var(--muted); } .mono { font-family: var(--mono); } .grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; } .col { display: flex; flex-direction: column; gap: 8px; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 9px; padding: 0 7px; color: var(--muted); }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; }
.kbd { font: 11px var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; background: var(--surface2); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 8px; }
.sel { padding-right: 6px; }

/* ---------- menu contestuale, dialoghi, toast ---------- */
.ctx { position: fixed; z-index: 99990; min-width: 190px; background: var(--raise); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.ctx button { display: flex; width: 100%; align-items: center; gap: 9px; text-align: left; border: 0; background: transparent; height: 30px; padding: 0 10px; border-radius: 5px; cursor: pointer; }
.ctx button:hover, .ctx button:focus-visible { background: var(--accent-soft); outline: none; } .ctx button.dng { color: var(--danger); }
.ctx hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.scrim { position: fixed; inset: 0; z-index: 99980; background: rgba(5,10,12,.55); display: grid; place-items: center; padding: 16px; }
.dlg { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 12px; max-height: 90vh; overflow: auto; }
.dlg h3 { margin: 0; font-size: 18px; } .dlg p { margin: 0; color: var(--muted); } .dlg .acts { display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 99999; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { pointer-events: auto; background: var(--raise); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 9px 12px; box-shadow: var(--shadow); max-width: 360px; display: flex; gap: 10px; align-items: center; }
.toast.err { border-left-color: var(--danger); } .toast button { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-weight: 600; }

/* ---------- ricerca rapida e lanciatore ---------- */
.spot { position: fixed; inset: 0; z-index: 99000; background: rgba(5,10,12,.5); display: flex; justify-content: center; align-items: flex-start; padding-top: 11vh; }
.spot-box { width: min(640px, calc(100% - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.spot-in { width: 100%; height: 52px; border: 0; background: transparent; padding: 0 18px; font-size: 17px; outline: none; border-bottom: 1px solid var(--line); }
.spot-list { max-height: 52vh; overflow: auto; padding: 6px; }
.spot-it { display: flex; align-items: center; gap: 12px; padding: 7px 10px; border-radius: 8px; cursor: pointer; min-height: 40px; }
.spot-it.sel { background: var(--accent-soft); } .spot-it .ic { color: var(--accent); display: grid; } .spot-it .t { flex: 1; min-width: 0; } .spot-it .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .spot-it .t small { color: var(--muted); }
.spot-hint { padding: 6px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; display: flex; gap: 14px; }
.launcher { position: fixed; inset: var(--bar) 0 0 var(--rail); z-index: 4900; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); padding: 28px; overflow: auto; }
.launcher h2 { font-size: 15px; color: var(--muted); font-family: var(--ui); font-weight: 600; margin: 18px 0 10px; }
.l-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.l-app { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px 10px; border-radius: 12px; border: 0; background: transparent; cursor: pointer; text-align: center; }
.l-app:hover, .l-app:focus-visible { background: var(--raise); outline: none; }
.l-app .tile { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; background: var(--surface2); border: 1px solid var(--line); color: var(--accent); }
.l-app span { font-size: 12.5px; line-height: 1.2; }

@media (max-width: 720px) {
  #os { grid-template-columns: 1fr; grid-template-rows: var(--bar) 1fr 58px; grid-template-areas: "top" "desk" "rail"; }
  #rail { flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 0 6px; overflow-x: auto; justify-content: flex-start; }
  .rail-btn.run::after { left: 18px; top: auto; bottom: -5px; width: 8px; height: 4px; border-radius: 3px 3px 0 0; } .rail-btn.act::after { width: 20px; left: 13px; top: auto; height: 4px; }
  .rail-btn[data-tip]:hover::before { display: none; }
  .pill { min-width: 0; flex: 1; } .pill kbd, .brand small, .hide-m { display: none; }
  .launcher { inset: var(--bar) 0 58px 0; padding: 14px; }
  .rail-sp { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  :root:not([data-motion="no"]) .win { animation: pop .14s ease-out; }
  @keyframes pop { from { opacity: 0; transform: scale(.975); } to { opacity: 1; transform: none; } }
}
:root[data-motion="no"] * { animation: none !important; transition: none !important; }
[hidden] { display: none !important; }
