/* FICSIT Remote Monitoring - tema ispirato all'interfaccia di Satisfactory.
   Arancione FICSIT (lo stesso slot colore delle tue macchine), pannelli in acciaio
   scuro con angoli smussati e una striscia di pericolo sotto l'intestazione. */

:root {
  --bg: #16181a;
  --grid: rgba(250, 149, 73, 0.05);
  --steel: #25282c;
  --steel-hi: #2f3338;
  --steel-lo: #1d2023;
  --line: #3a3f45;
  --text: #ece7df;
  --mute: #a1a7ad;
  --dim: #6c7278;
  --orange: #fa9549;
  --orange-dk: #c8692a;

  --ok: #7fd48c;
  --amber: #f2c14e;
  --warn: #ff7a59;
  --bad: #e0405a;
  --slate: #6f8aa3;
  --paused: #8a8f95;
  --unconf: #4b5056;

  --font: "Bahnschrift", "Barlow Condensed", "Roboto Condensed", "Arial Narrow",
    "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 36px 36px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

button, select, input { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

/* ---------- intestazione ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 28px;
  padding: 14px 28px;
  background: var(--steel-lo);
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 42px; height: 42px; flex: none; }
.brand-company { font-size: 13px; color: var(--orange); font-weight: 600; letter-spacing: 0.06em; }
h1 { margin: 0; font-size: 26px; font-weight: 700; line-height: 1.05; }

.session { display: flex; flex-direction: column; min-width: 140px; }
.session .lbl { font-size: 13px; color: var(--mute); }
.session .val { font-size: 18px; font-weight: 600; }

.controls {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}
.controls label { display: flex; align-items: center; gap: 6px; color: var(--mute); font-size: 14px; }

select, input[type="search"] {
  background: var(--steel);
  border: 1px solid var(--line);
  padding: 5px 8px;
}

button {
  background: var(--steel-hi);
  border: 1px solid var(--line);
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
button:hover { border-color: var(--orange); }
button.primary { background: var(--orange); color: #1b1109; border-color: var(--orange); }
button.primary:hover { background: #ffa862; }
button[aria-pressed="true"] { background: var(--orange-dk); color: #1b1109; }

.pill { padding: 4px 12px; font-weight: 700; font-size: 14px; }
.pill.on { background: var(--ok); color: #0e2412; }
.pill.part { background: var(--amber); color: #2a2105; }
.pill.off { background: var(--bad); color: #fff; }
.last { color: var(--mute); font-size: 14px; }

.hazard {
  height: 9px;
  background: repeating-linear-gradient(-45deg, var(--orange) 0 14px, #121314 14px 28px);
}

/* ---------- contenitori ---------- */

main { padding: 22px 28px 40px; max-width: 1680px; margin: 0 auto; }

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 22px;
  margin-top: 22px;
}
.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-12 { grid-column: 1 / -1; }

.panel {
  background: linear-gradient(180deg, var(--steel-hi) 0, var(--steel) 56px);
  border: 1px solid var(--line);
  border-top: 3px solid var(--orange);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%);
  padding: 16px 20px 22px;
  min-width: 0;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 14px;
}
h2 { margin: 0; font-size: 21px; font-weight: 700; }
.note { color: var(--mute); font-size: 14px; }

.empty {
  padding: 18px 0 6px;
  color: var(--mute);
}

/* ---------- indicatori in alto ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--steel);
  border: 1px solid var(--line);
  border-left: 6px solid var(--tone, var(--orange));
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%);
  padding: 10px 14px 12px;
}
.tile .k-label { color: var(--mute); font-size: 14px; }
.tile .k-value { font-size: 36px; font-weight: 700; line-height: 1.1; }
.tile .k-value small { font-size: 18px; font-weight: 600; color: var(--mute); margin-left: 3px; }
.tile .k-sub { color: var(--mute); font-size: 14px; }
.tile.ok { --tone: var(--ok); }
.tile.amber { --tone: var(--amber); }
.tile.warn { --tone: var(--warn); }
.tile.bad { --tone: var(--bad); }
.tile.slate { --tone: var(--slate); }

/* ---------- nastro trasportatore degli stati ---------- */

.belt {
  display: flex;
  height: 38px;
  background: #0f1011;
  border: 1px solid var(--line);
  overflow: hidden;
}
.seg { position: relative; height: 100%; min-width: 2px; background: var(--c); }
.seg + .seg { border-left: 1px solid #0f1011; }
.seg.producing::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(110deg, transparent 0 9px, rgba(0, 0, 0, 0.3) 9px 14px, transparent 14px);
  background-size: 28px 100%;
  animation: belt 1.4s linear infinite;
}
@keyframes belt { to { background-position-x: 28px; } }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 12px 0 4px;
  font-size: 15px;
}
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
.sw { width: 12px; height: 12px; background: var(--c); flex: none; }
.legend b { font-weight: 700; }

/* ---------- tabelle ---------- */

.scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th {
  text-align: left;
  font-weight: 600;
  color: var(--mute);
  padding: 6px 10px;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
  user-select: none;
}
table.data th[data-sort] { cursor: pointer; }
table.data th[data-sort]:hover { color: var(--text); }
table.data th.sorted { color: var(--orange); }
table.data td { padding: 6px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); vertical-align: middle; }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:hover td { background: rgba(250, 149, 73, 0.06); }
.neg { color: var(--warn); }
.pos { color: var(--ok); }
.dim { color: var(--dim); }

.meter { height: 8px; background: #121416; min-width: 70px; }
.meter > i { display: block; height: 100%; background: var(--c, var(--ok)); max-width: 100%; }

.mini-belt { display: flex; height: 10px; background: #121416; min-width: 120px; }
.mini-belt i { display: block; height: 100%; background: var(--c); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 12px; }
.toolbar input[type="search"] { min-width: 220px; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--mute); }

/* ---------- energia ---------- */

.gauge { height: 22px; background: #0f1011; border: 1px solid var(--line); position: relative; }
.gauge > i { display: block; height: 100%; background: var(--c, var(--ok)); }
.gauge-row { display: flex; justify-content: space-between; margin-top: 6px; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 18px; margin: 16px 0; }
.stat .s-label { color: var(--mute); font-size: 14px; }
.stat .s-value { font-size: 22px; font-weight: 700; }

.spark-box { margin-top: 12px; }
.spark-box .note { display: flex; justify-content: space-between; }
.spark { width: 100%; height: 48px; display: block; background: #121416; border: 1px solid var(--line); }
.spark polyline { fill: none; stroke-width: 2; stroke: var(--c, var(--orange)); }

/* ---------- treni ---------- */

.trains { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 18px; }
.train {
  background: var(--steel-lo);
  border: 1px solid var(--line);
  border-left: 6px solid var(--c, var(--slate));
  padding: 8px 12px 10px;
}
.train .t-name { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.train .t-state { color: var(--c, var(--slate)); font-weight: 700; }
.train .t-meta { color: var(--mute); font-size: 14px; overflow-wrap: anywhere; }

h3 { margin: 18px 0 8px; font-size: 17px; font-weight: 700; }

details.raw { margin-top: 14px; color: var(--mute); font-size: 14px; }
details.raw summary { cursor: pointer; }
details.raw pre {
  max-height: 260px;
  overflow: auto;
  background: #101113;
  border: 1px solid var(--line);
  padding: 10px;
  font-size: 12.5px;
  color: var(--text);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* ---------- problemi ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  padding: 4px 12px;
  background: var(--steel-lo);
  border: 1px solid var(--line);
  cursor: pointer;
  font-weight: 600;
  clip-path: none;
}
.chip[aria-pressed="true"] { background: var(--orange); color: #1b1109; border-color: var(--orange); }

.problems { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto; }
.problems li {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 4px 12px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.problems .bar { background: var(--c); width: 6px; height: 100%; }
.problems .p-title { font-weight: 700; }
.problems .p-detail { color: var(--mute); font-size: 14px; }

/* ---------- piè di pagina ---------- */

footer { margin-top: 26px; color: var(--mute); font-size: 14px; }
footer ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 22px; }
footer .okc { color: var(--ok); }
footer .errc { color: var(--bad); }

/* Dati non aggiornati: i pannelli restano leggibili ma si vede che sono vecchi. */
.stale .kpis, .stale .grid { opacity: 0.5; filter: grayscale(0.7); }

/* ---------- adattamento ---------- */

@media (max-width: 1180px) {
  .span-7, .span-5, .span-6 { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  main { padding: 16px 14px 32px; }
  .controls { margin-left: 0; }
  h1 { font-size: 22px; }
  .tile .k-value { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .seg.producing::after { animation: none; }
}
