:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1a2230;
  --ink-soft: #5b6675;
  --line: #e6e9ee;
  --accent: #0f766e;
  --accent-soft: #e6f3f1;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ─── Brand ─────────────────────────────── */
.brand-mark { font-weight: 700; letter-spacing: .04em; color: var(--accent); }
.brand-sub { font-weight: 500; color: var(--ink-soft); }
.login-brand { display: flex; align-items: baseline; gap: .4rem; font-size: 1.7rem; }
.brand-mark.sm { font-size: 1.05rem; }
.brand-sub.sm { font-size: 1.05rem; }

/* ─── Login ─────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  padding: 2rem 1.8rem; display: flex; flex-direction: column; gap: 1rem;
}
.login-tag { margin: 0 0 .4rem; color: var(--ink-soft); font-size: .92rem; }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--ink-soft); font-weight: 500; }
.login-card input {
  padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px;
  font-size: .95rem; color: var(--ink); background: #fbfcfd;
}
.login-card input:focus { outline: none; border-color: var(--accent); background: #fff; }
.login-card button { margin-top: .4rem; }
.login-err { color: var(--danger); font-size: .85rem; margin: 0; }

/* ─── Buttons ───────────────────────────── */
button { cursor: pointer; font-family: inherit; border-radius: 10px; font-weight: 600; transition: .15s; }
.primary-btn, #loginBtn { background: var(--accent); color: #fff; border: none; padding: .65rem 1rem; font-size: .95rem; }
.primary-btn:hover, #loginBtn:hover { filter: brightness(1.06); }
.ghost-btn { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); padding: .5rem .85rem; font-size: .9rem; }
.ghost-btn:hover { background: #fff; color: var(--ink); }
.sm { font-size: .85rem !important; padding: .45rem .8rem !important; }

/* ─── Topbar ────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.2rem;
  padding: .8rem 1.4rem; background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-brand { display: flex; align-items: baseline; gap: .35rem; white-space: nowrap; }
.search-shell {
  flex: 1; max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: .55rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .55rem .9rem;
}
.search-shell:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-ic { width: 18px; height: 18px; color: var(--ink-soft); flex: none; }
#searchInput { flex: 1; border: none; outline: none; font-size: .95rem; background: transparent; color: var(--ink); }
.search-spin { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Pannello risultati "Cerca o chiedi" */
.search-panel {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  width: min(720px, calc(100vw - 2.8rem)); max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(16,24,40,.16); padding: 1rem; z-index: 40;
}
.sp-answer { font-size: .95rem; line-height: 1.5; color: var(--ink); background: var(--accent-soft); border-radius: 10px; padding: .8rem .9rem; margin-bottom: .8rem; white-space: pre-wrap; }
.sp-note, .sp-empty { font-size: .85rem; color: var(--ink-soft); padding: .3rem .1rem .6rem; }
.sp-excerpt { margin: 0 0 .8rem; padding: .6rem .8rem; border-left: 3px solid var(--accent); background: #fbfffe; color: var(--ink); font-size: .88rem; font-style: italic; border-radius: 0 8px 8px 0; }
.sp-deep-btn { width: 100%; margin: 0 0 .8rem; background: var(--surface); border: 1px solid var(--accent); color: var(--accent); padding: .55rem; font-size: .88rem; font-weight: 600; }
.sp-deep-btn:hover { background: var(--accent-soft); }
.sp-deep-load { display: flex; align-items: center; gap: .55rem; font-size: .9rem; color: var(--ink-soft); padding: .6rem .2rem; }
.sp-list { display: flex; flex-direction: column; gap: .4rem; }
.sp-item { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; cursor: pointer; }
.sp-item:hover { border-color: #d3d8e0; }
.sp-item.sp-rel { border-color: var(--accent); background: #fbfffe; }
.sp-item-head { display: flex; align-items: center; gap: .5rem; }
.sp-title { font-weight: 600; font-size: .92rem; flex: 1; }
.sp-snip { font-size: .82rem; color: var(--ink-soft); margin-top: .25rem; }

.topbar-user { display: flex; align-items: center; gap: .6rem; }
.user-badge { font-size: .85rem; color: var(--ink-soft); font-weight: 500; }

/* ─── Content ───────────────────────────── */
.content { max-width: 1080px; margin: 0 auto; padding: 1.8rem 1.4rem 4rem; display: flex; flex-direction: column; gap: 2rem; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.block-head h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
.empty-hint { color: var(--ink-soft); font-size: .9rem; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; }

/* ─── Selettore stabilimento (header, compatto) ─── */
.plant-switch { display: flex; gap: .2rem; background: #eef0f3; border-radius: 10px; padding: .2rem; flex: none; }
.plant-switch button {
  border: none; background: transparent; color: var(--ink-soft);
  padding: .38rem .8rem; font-size: .85rem; font-weight: 600; border-radius: 8px; white-space: nowrap;
}
.plant-switch button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.plant-switch button:not(.active):hover { color: var(--ink); }

/* ─── Hub a mosaico vivo ─────────────────── */
.hub { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem; align-items: stretch; }

/* Area in evidenza (sinistra) */
.hub-feature {
  background: linear-gradient(150deg, var(--accent) 0%, #0b5d56 100%);
  color: #fff; border-radius: 16px; padding: 1.6rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 280px; position: relative; overflow: hidden;
}
.hub-feature::after {
  content: ''; position: absolute; right: -40px; bottom: -40px; width: 180px; height: 180px;
  background: rgba(255,255,255,.06); border-radius: 50%;
}
.hf-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; position: relative; z-index: 1; }
.hf-ic { width: 46px; height: 46px; border-radius: 12px; background: rgba(255,255,255,.16); display: grid; place-items: center; }
.hf-ic svg { width: 24px; height: 24px; color: #fff; }
.hf-count { font-size: .82rem; font-weight: 600; background: rgba(255,255,255,.16); padding: .25rem .65rem; border-radius: 20px; }
.hf-name { font-size: 1.7rem; font-weight: 700; margin: 0 0 .5rem; position: relative; z-index: 1; }
.hf-desc { font-size: .92rem; line-height: 1.5; color: rgba(255,255,255,.88); margin: 0 0 1.1rem; position: relative; z-index: 1; }
.hf-recent { list-style: none; margin: 0 0 1.1rem; padding: 0; display: flex; flex-direction: column; gap: .35rem; position: relative; z-index: 1; }
.hf-recent li { font-size: .85rem; padding: .4rem .6rem; background: rgba(255,255,255,.1); border-radius: 8px; }
.hf-empty { font-size: .85rem; color: rgba(255,255,255,.78); background: rgba(255,255,255,.08); border-radius: 10px; padding: .7rem .8rem; margin-bottom: 1.1rem; position: relative; z-index: 1; }
.hf-enter { margin-top: auto; align-self: flex-start; background: #fff; color: var(--accent); position: relative; z-index: 1; }
.hf-enter:hover { filter: none; background: #f1faf8; }

/* Rail aree (destra) */
.hub-rail { display: flex; flex-direction: column; gap: .4rem; }
.hub-rail-item {
  flex: 1; display: flex; align-items: center; gap: .65rem; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  padding: .7rem .85rem; cursor: pointer; font-weight: 500; color: var(--ink); transition: .14s;
}
.hub-rail-item:hover, .hub-rail-item.active { border-color: var(--accent); background: var(--accent-soft); }
.hub-rail-item .hri-ic { width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); display: grid; place-items: center; flex: none; transition: .14s; }
.hub-rail-item.active .hri-ic { background: #fff; }
.hub-rail-item .hri-ic svg { width: 17px; height: 17px; color: var(--accent); }
.hri-name { flex: 1; font-size: .92rem; }
.hri-count { font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.hri-chev { width: 15px; height: 15px; color: #c2c8d2; flex: none; }
.hub-rail-item.active .hri-chev { color: var(--accent); }

@media (max-width: 720px) {
  .hub { grid-template-columns: 1fr; }
}

/* ─── Matrix grid ───────────────────────── */
.matrix-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .9rem; }
.matrix-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); cursor: pointer; transition: .15s;
  display: flex; flex-direction: column; gap: .5rem;
}
.matrix-card:hover { transform: translateY(-2px); border-color: #d3d8e0; }
.matrix-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.matrix-ic svg { width: 20px; height: 20px; }
.matrix-name { font-weight: 600; font-size: .98rem; }
.matrix-count { font-size: .82rem; color: var(--ink-soft); }

/* ─── Kit row ───────────────────────────── */
.kit-row { display: flex; gap: .9rem; overflow-x: auto; padding-bottom: .3rem; }
.kit-card {
  flex: none; width: 230px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); cursor: pointer;
}
.kit-card:hover { border-color: var(--accent); }
.kit-name { font-weight: 600; }
.kit-meta { font-size: .8rem; color: var(--ink-soft); margin-top: .3rem; }

/* ─── Doc list ──────────────────────────── */
.doc-list { display: flex; flex-direction: column; gap: .5rem; }
.doc-row {
  display: flex; align-items: center; gap: .8rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; cursor: pointer;
}
.doc-row:hover { border-color: #d3d8e0; }
.doc-title { font-weight: 500; flex: 1; }
.doc-tag { font-size: .75rem; color: var(--accent); background: var(--accent-soft); padding: .15rem .5rem; border-radius: 6px; }

/* ─── Modal ─────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.32); display: grid; place-items: center; z-index: 50; padding: 1.5rem; }
.modal-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 1.6rem; display: flex; flex-direction: column; gap: .9rem; }
.modal-card h3 { margin: 0; font-size: 1.1rem; }
.modal-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--ink-soft); font-weight: 500; }
.modal-card input { padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px; font-size: .95rem; background: #fbfcfd; }
.modal-card input:focus { outline: none; border-color: var(--accent); background: #fff; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .3rem; }

/* ─── Upload ─────────────────────────────── */
.upload-card { max-width: 520px; }
.doc-meta { font-size: .8rem; color: var(--ink-soft); }
.drop-zone {
  border: 2px dashed var(--line); border-radius: 14px; padding: 1.8rem 1rem; text-align: center;
  color: var(--ink-soft); transition: .15s;
}
.drop-zone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-ic { width: 32px; height: 32px; color: var(--accent); margin-bottom: .4rem; }
.drop-zone p { margin: .25rem 0; font-size: .92rem; }
.dz-hint { font-size: .8rem !important; color: var(--ink-soft); }
.link-btn { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; font-size: inherit; text-decoration: underline; }
.up-status { font-size: .9rem; color: var(--ink-soft); display: flex; align-items: center; gap: .55rem; padding: .8rem .2rem; }
.up-err { color: var(--danger); }

.doc-form { display: flex; flex-direction: column; gap: .7rem; }
.doc-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; color: var(--ink-soft); font-weight: 500; }
.doc-form input, .doc-form select, .doc-form textarea {
  padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 9px; font-size: .92rem;
  background: #fbfcfd; color: var(--ink); font-family: inherit;
}
.doc-form input:focus, .doc-form select:focus, .doc-form textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.area-hint { font-size: .82rem; color: var(--ink-soft); background: var(--accent-soft); border-radius: 8px; padding: .5rem .65rem; margin-top: -.2rem; }

/* ─── Vista area ─────────────────────────── */
.area-modal { max-width: 560px; width: 100%; }
.am-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.am-head h3 { margin: 0; }
.area-modal .doc-list { max-height: 60vh; overflow-y: auto; }
