/* style.css - LAB Sicurezza Industriale (prototipo, non online) */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --accent: #4f9dff;
  --accent-2: #7c5cff;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  padding-bottom: 4rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: rgba(15,17,21,0.85);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 10;
}
.site-header .container { display: flex; align-items: center; gap: 1.5rem; padding-top: 0.75rem; padding-bottom: 0.75rem; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.02em; }
.brand .tag { color: var(--accent); }
.brand .lab { font-size: 0.65rem; background: var(--accent-2); color: #fff; border-radius: 4px; padding: 2px 6px; margin-left: 6px; vertical-align: middle; text-transform: uppercase; letter-spacing: 0.08em; }
.site-nav { display: flex; gap: 1rem; margin-left: auto; flex-wrap: wrap; }
.site-nav a { color: var(--text-dim); font-size: 0.9rem; padding: 4px 8px; border-radius: 6px; }
.site-nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.site-nav a.active { color: var(--accent); background: rgba(79,157,255,0.12); }

/* Banner LAB */
.lab-banner {
  background: linear-gradient(90deg, rgba(124,92,255,0.15), rgba(79,157,255,0.08));
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.lab-banner b { color: var(--accent-2); }

/* Hero */
.hero { padding: 3rem 0 2rem; }
.hero h1 { font-size: 2rem; line-height: 1.2; margin-bottom: 0.75rem; }
.hero p { color: var(--text-dim); max-width: 720px; font-size: 1.05rem; }

/* Cards / grid */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}
.card h3 { margin-bottom: 0.5rem; font-size: 1.05rem; }
.card p { color: var(--text-dim); font-size: 0.92rem; }
.card .meta { color: var(--text-dim); font-size: 0.82rem; margin-top: 0.5rem; }

/* Sezioni pagine */
.page-head { padding: 2rem 0 1rem; }
.page-head h1 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.page-head p { color: var(--text-dim); }

/* Badge licenza */
.badge { display: inline-block; font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; letter-spacing: 0.03em; }
.badge-open { background: rgba(63,185,80,0.15); color: var(--ok); border: 1px solid rgba(63,185,80,0.3); }
.badge-link { background: rgba(210,153,34,0.15); color: var(--warn); border: 1px solid rgba(210,153,34,0.3); }
.badge-pay { background: rgba(248,81,73,0.15); color: var(--danger); border: 1px solid rgba(248,81,73,0.3); }

/* Tabelle */
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.num { font-family: var(--mono); font-size: 0.85rem; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* Disclaimer */
.disclaimer {
  background: rgba(210,153,34,0.08);
  border: 1px solid rgba(210,153,34,0.25);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  font-size: 0.85rem;
  color: var(--warn);
  margin: 1.5rem 0;
}

/* Buttons */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 0.35rem 0.8rem; font-size: 0.82rem; }

/* Form */
label { display: block; font-size: 0.82rem; color: var(--text-dim); margin: 0.75rem 0 0.3rem; }
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.92rem;
  font-family: var(--font);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* FTA editor */
.fta-layout { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .fta-layout { grid-template-columns: 1fr; } }

.fta-tree { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; min-height: 300px; overflow-x: auto; }
.tree-node { margin-left: 1.4rem; border-left: 1px solid var(--border); padding-left: 1rem; position: relative; }
.tree-node::before { content: ""; position: absolute; left: -1px; top: 0.9em; width: 1rem; height: 1px; background: var(--border); }
.tree-root { margin-left: 0; border-left: none; padding-left: 0; }
.tree-root::before { display: none; }
.tree-box {
  display: inline-block;
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(79,157,255,0.08);
  margin: 0.2rem 0;
}
.tree-box.gate-and { border-color: var(--accent-2); background: rgba(124,92,255,0.1); }
.tree-box.gate-or { border-color: var(--accent); background: rgba(79,157,255,0.08); }
.tree-box.base { border-color: var(--text-dim); background: var(--surface-2); font-weight: 400; }
.tree-box .p { font-family: var(--mono); font-size: 0.75rem; color: var(--text-dim); display: block; font-weight: 400; }

/* Risultati FTA */
.results { margin-top: 1rem; }
.result-line { padding: 0.4rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; display: flex; justify-content: space-between; gap: 1rem; }
.result-line .lbl { color: var(--text-dim); }
.result-line .val { font-family: var(--mono); font-weight: 600; }

.mcs-item { padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; margin: 0.4rem 0; font-size: 0.85rem; }
.mcs-item .p { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.mcs-item .src { color: var(--text-dim); font-size: 0.78rem; }

/* Editor add base */
.add-base-row { display: grid; grid-template-columns: 1fr 1fr 90px auto; gap: 0.5rem; align-items: end; }
.add-base-row select { width: 100%; }
@media (max-width: 720px) { .add-base-row { grid-template-columns: 1fr; } }

.bases-list { max-height: 260px; overflow-y: auto; }
.base-item { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.85rem; gap: 0.5rem; }
.base-item .name { flex: 1; }
.base-item .p { font-family: var(--mono); color: var(--text-dim); font-size: 0.8rem; }
.base-item .del { cursor: pointer; color: var(--danger); background: none; border: none; font-size: 1rem; padding: 0 0.25rem; }

/* Utility */
.mono { font-family: var(--mono); }
.dim { color: var(--text-dim); }
.small { font-size: 0.85rem; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }
.mb-1 { margin-bottom: 1rem; }
.hidden { display: none; }

/* ============ LAVAGNA FTA/ETA ============ */
.lavagna-main { max-width: 1400px; }
.lavagna-layout {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 1rem;
  align-items: stretch;
  margin-top: 1rem;
}
@media (max-width: 1100px) {
  .lavagna-layout { grid-template-columns: 1fr; }
  .lavagna-canvas-wrap { order: -1; }
}

.lavagna-side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.lavagna-side .card { padding: 1rem; }

.palette { display: flex; flex-direction: column; gap: 0.4rem; }
.pal-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  cursor: grab;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.pal-item:hover { border-color: var(--accent); background: rgba(79,157,255,0.08); }
.pal-item:active { cursor: grabbing; }

.lavagna-canvas-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0c0e12;
  display: flex;
  flex-direction: column;
  min-height: 620px;
}
.lavagna-canvas { flex: 1; cursor: grab; position: relative; min-height: 560px; }
.lavagna-canvas:active { cursor: grabbing; }
.lavagna-canvas svg { display: block; width: 100%; height: 100%; min-height: 560px; }

.node-group { cursor: grab; }
.node-group:active { cursor: grabbing; }
.node-group.sel rect { filter: drop-shadow(0 0 6px rgba(255,255,255,0.35)); }
.handle { cursor: crosshair; }
.handle:hover { fill: var(--accent); }

.link-path { cursor: pointer; }
.link-path:hover { stroke: var(--accent); stroke-width: 3; }
.link-label { cursor: pointer; pointer-events: all; }

.lavagna-status {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.4rem 0.8rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
#st-hint { margin-left: auto; }

#help-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
#help-overlay.hidden { display: none; }
.help-box { max-width: 560px; width: 90%; max-height: 80vh; overflow-y: auto; }

#db-list { max-height: 380px; overflow-y: auto; }
.db-apply, .db-new { font-size: 0.72rem; padding: 0.25rem 0.55rem; }
