/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: calc(100vh - var(--top, 92px)); }
.side { border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: var(--top, 92px); height: calc(100vh - var(--top, 92px)); background: #0b0e13; }
.menu { display: grid; gap: 4px; }
.menu a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-size: 14.5px; font-weight: 500; }
.menu a:hover { color: var(--text); background: var(--bg2); }
.menu a.on { color: var(--text); background: var(--bg3); box-shadow: inset 2px 0 0 var(--accent); }
.menu svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; flex: none; }
.menu a.on svg { stroke: var(--accent); }
.count { margin-left: auto; background: var(--accent2); color: #1a0b02; font-size: 11.5px; font-weight: 700; border-radius: 99px; padding: 1px 7px; min-width: 20px; text-align: center; }
.count.zero { display: none; }
.side-note { color: var(--dim); font-size: 12.5px; padding: 0 12px; }
.side-cta { margin-top: auto; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--bg2); display: grid; gap: 10px; font-size: 13px; color: var(--muted); }
.side-cta .btn { justify-content: center; }

.main { padding: 28px 32px 60px; min-width: 0; }
.view { display: none; }
.view.on { display: block; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
h1 { font-size: 26px; letter-spacing: -.02em; font-weight: 650; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -.005em; }
.sub { color: var(--muted); margin-top: 4px; font-size: 14.5px; max-width: 70ch; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }
.mono { font-family: var(--mono); }
.link { color: var(--accent); }
.live-pill { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; }
.live-pill i, .live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: blink 2s infinite; display: inline-block; }
.live-pill time { font-family: var(--mono); color: var(--text); }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- cards & grids ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, #0e1218, #0b0e13); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.g-map { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-rev { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-add { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; background: var(--bg2); display: grid; gap: 4px; }
.kpi .k { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .v { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .v small { font-size: 16px; color: var(--muted); font-weight: 500; }
.kpi .s { font-size: 12.5px; color: var(--dim); }
.kpi .s.warn { color: var(--accent2); }
.kpi .s.bad { color: var(--bad); }
a.kpi:hover { border-color: var(--line2); }

/* status dots, pills */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--accent2); } .dot.off { background: var(--bad); }
.dot.info { background: var(--accent); } .dot.mute { background: var(--dim); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: rgba(62,224,143,.35); }
.pill.warn { color: var(--accent2); border-color: rgba(255,122,47,.4); }
.pill.off { color: var(--bad); border-color: rgba(255,84,104,.4); }
.pill.info { color: var(--accent); border-color: rgba(95,212,255,.35); }

/* map */
#map { height: 400px; border-radius: 10px; background: #0d1117; border: 1px solid var(--line); }
#addMap { height: 260px; border-radius: 10px; background: #0d1117; border: 1px solid var(--line); cursor: crosshair; }
.leaflet-container { font: inherit; background: #0d1117; }
.dark-tiles { filter: invert(1) hue-rotate(195deg) brightness(.82) contrast(.88) saturate(.35); }
.leaflet-control-attribution { background: rgba(10,12,16,.75) !important; color: var(--dim) !important; font-size: 10px !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--bg2) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-tooltip { background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5); font-size: 12.5px; padding: 6px 10px; }
.leaflet-tooltip-top::before { border-top-color: var(--line2); }
.pin { display: block; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid #0a0c10; box-shadow: 0 0 0 1px rgba(255,255,255,.15); position: relative; cursor: pointer; }
.pin.ok { background: var(--ok); }
.pin.warn { background: var(--accent2); }
.pin.off { background: var(--bad); }
.pin.warn::after, .pin.off::after { content: ""; position: absolute; inset: -7px; border-radius: 50%; border: 2px solid currentColor; animation: ring 1.8s ease-out infinite; }
.pin.warn { color: var(--accent2); } .pin.off { color: var(--bad); }
.pin.new { box-shadow: 0 0 0 3px var(--accent); }
@keyframes ring { from { transform: scale(.5); opacity: .9; } to { transform: scale(1.4); opacity: 0; } }

/* feed */
.feed-card { display: flex; flex-direction: column; }
.feed { list-style: none; display: grid; gap: 2px; overflow: auto; max-height: 400px; margin: 0 -8px; padding-right: 4px; }
.feed li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: baseline; padding: 7px 8px; border-radius: 8px; font-size: 13px; }
.feed li:hover { background: var(--bg2); }
.feed li .dot { width: 7px; height: 7px; transform: translateY(-1px); }
.feed li .txt { min-width: 0; }
.feed li .mn { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed li .mn:hover { color: var(--accent); }
.feed li time { color: var(--dim); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed li.new { animation: flash 1.6s ease; }
@keyframes flash { from { background: rgba(95,212,255,.12); } to { background: transparent; } }

/* charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--dim); font-size: 11px; font-family: system-ui, sans-serif; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.tip { position: fixed; z-index: 3000; pointer-events: none; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 10px;
  font-size: 12.5px; box-shadow: 0 8px 24px rgba(0,0,0,.5); opacity: 0; transition: opacity .1s; white-space: nowrap; }
.tip.on { opacity: 1; }
.tip b { font-variant-numeric: tabular-nums; }
.tip span { color: var(--muted); display: block; font-size: 11.5px; }

/* top list */
.top { list-style: none; display: grid; gap: 12px; }
.top li { display: grid; gap: 6px; cursor: pointer; }
.top .row1 { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.top .row1 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .row1 b { font-variant-numeric: tabular-nums; font-weight: 600; }
.top .bar { height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.top .bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.top li:hover .row1 span:first-child { color: var(--accent); }

/* table */
.table-card { padding: 6px 0 0; }
.table-card .card-head { padding: 12px 20px 0; }
.table-wrap { overflow-x: auto; }
.mtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.mtable th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.mtable td { padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mtable tr:last-child td { border-bottom: 0; }
.mtable th:first-child, .mtable td:first-child { padding-left: 20px; }
.mtable tbody tr { cursor: pointer; transition: background .15s; }
.mtable tbody tr:hover { background: var(--bg2); }
.mtable .nm { font-weight: 550; }
.mtable .id { color: var(--dim); font-family: var(--mono); font-size: 12px; margin-left: 6px; }
.mtable .num { text-align: right; }
.mtable .last { color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.mtable .hot { color: var(--bad); font-weight: 600; }
.mtable .lowtxt { color: var(--accent2); }
.mtable .empty { text-align: center; color: var(--muted); padding: 40px; cursor: default; }
.stockbar { display: inline-block; width: 60px; height: 6px; border-radius: 99px; background: var(--bg3); vertical-align: middle; margin-right: 8px; overflow: hidden; }
.stockbar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.stockbar i.low { background: var(--accent2); }

/* toolbar, chips, inputs */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.input { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; color: var(--text); padding: 9px 12px; font: inherit; font-size: 14px; width: 100%; }
.input:focus { outline: none; border-color: var(--accent); }
.toolbar .input { max-width: 320px; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { background: var(--bg2); border: 1px solid var(--line); color: var(--muted); border-radius: 99px; padding: 6px 13px; font-size: 13px; cursor: pointer; }
.chips button:hover { color: var(--text); }
.chips button.on { color: var(--text); border-color: var(--accent); background: rgba(95,212,255,.08); }
.chips button b { font-weight: 600; color: var(--muted); margin-left: 2px; }
.tabs { margin-bottom: 14px; }

/* alerts */
.alerts { list-style: none; display: grid; gap: 10px; }
.alerts li { display: grid; grid-template-columns: 104px 1fr auto; gap: 16px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--bg2); }
.alerts li.critical { border-left: 3px solid var(--bad); }
.alerts li.warning { border-left: 3px solid var(--accent2); }
.alerts li.acked { opacity: .6; border-left-color: var(--line2); }
.sev { justify-self: start; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 6px; white-space: nowrap; }
.sev svg { width: 14px; height: 14px; }
.sev.critical { color: var(--bad); background: rgba(255,84,104,.1); }
.sev.warning { color: var(--accent2); background: rgba(255,122,47,.1); }
.alerts .msg { font-weight: 550; }
.alerts .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.alerts .meta a:hover { color: var(--accent); }
.alerts .empty { grid-template-columns: 1fr; text-align: center; color: var(--muted); padding: 40px; }

/* machine detail */
.d-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 20px; }
.back { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13.5px; padding: 0; margin-bottom: 10px; display: inline-flex; gap: 6px; align-items: center; }
.back:hover { color: var(--text); }
.d-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; color: var(--muted); font-size: 13.5px; }
.d-meta .mono { font-size: 12.5px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.d-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.d-col { display: grid; gap: 16px; min-width: 0; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act { display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--line2); border-radius: 10px; color: var(--text); padding: 11px 12px; cursor: pointer; font-size: 13.5px; font-weight: 550; text-align: left; transition: border-color .15s, background .15s; }
.act:hover:not(:disabled) { border-color: var(--accent); background: rgba(95,212,255,.06); }
.act svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.act:disabled { opacity: .4; cursor: not-allowed; }
.act-note { color: var(--dim); font-size: 12px; margin-top: 10px; }
.stock { list-style: none; display: grid; gap: 12px; }
.stock li { display: grid; grid-template-columns: minmax(0, 1fr) 160px 70px; gap: 14px; align-items: center; font-size: 13.5px; }
.stock .pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.stock .pn i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.stock .track { position: relative; height: 8px; border-radius: 99px; background: var(--bg3); }
.stock .track i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--accent); transition: width .4s; }
.stock .track i.low { background: var(--accent2); }
.stock .track b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); opacity: .55; border-radius: 1px; }
.stock .q { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.stock .q.low { color: var(--accent2); font-weight: 600; }
.log { list-style: none; display: grid; gap: 2px; max-height: 360px; overflow: auto; margin: 0 -8px; }
.log li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: baseline; padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.log li .dot { width: 7px; height: 7px; }
.log li time { color: var(--dim); font-size: 11.5px; font-family: var(--mono); }
.log li.new { animation: flash 1.6s ease; }
.cam { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #000; aspect-ratio: 16 / 10; }
.cam canvas { width: 100%; height: 100%; display: block; }
.cam-note { color: var(--dim); font-size: 12px; margin-top: 8px; }
.notfound { padding: 60px 0; text-align: center; color: var(--muted); }

/* add form */
.form { display: grid; gap: 18px; padding: 22px; }
.form label, .form .field { display: grid; gap: 7px; font-size: 13.5px; color: var(--muted); }
.form .label { font-size: 13.5px; }
.form small { color: var(--dim); font-size: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.form .btn { justify-self: start; }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.pgrid label { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer; color: var(--text); font-size: 13.5px; background: var(--bg); }
.pgrid label:has(input:checked) { border-color: var(--accent); background: rgba(95,212,255,.06); }
.pgrid input { accent-color: var(--accent); width: 16px; height: 16px; }
.pgrid .pr { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.form-err { color: var(--bad); font-size: 13.5px; min-height: 0; }
.form-err:empty { display: none; }
.how h2 { margin-bottom: 14px; }
.how ol { list-style: none; counter-reset: s; display: grid; gap: 14px; }
.how li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 10px; color: var(--muted); font-size: 14px; }
.how li::before { content: "0" counter(s); font-family: var(--mono); color: var(--accent); font-size: 12.5px; padding-top: 2px; }

/* dialog */
.dlg { margin: auto; background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 16px; padding: 24px; width: min(380px, calc(100% - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.dlg::backdrop { background: rgba(5,7,10,.7); backdrop-filter: blur(3px); }
.dlg h2 { font-size: 17px; margin-bottom: 18px; }
.temp-set { display: flex; align-items: center; justify-content: center; gap: 22px; margin-bottom: 14px; }
.temp-set output { font-size: 40px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; min-width: 4.5ch; text-align: center; }
.step { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line2); background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer; }
.step:hover { border-color: var(--accent); }
#tempRange { width: 100%; accent-color: var(--accent); margin-bottom: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 4000; display: grid; gap: 8px; max-width: min(380px, calc(100% - 40px)); }
.toast { background: var(--bg3); border: 1px solid var(--line2); border-left: 3px solid var(--ok); border-radius: 10px; padding: 11px 14px; font-size: 13.5px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5); animation: toastin .25s ease; }
.toast.warn { border-left-color: var(--accent2); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .kpis, .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1180px) {
  .stock li { grid-template-columns: minmax(0, 1fr) 110px 56px; }
  .mtable .c-door, .mtable .c-last, .mtable .c-sales, .mtable .c-city { display: none; }
  .g-map, .g-rev { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
}
@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: var(--top, 92px); z-index: 900; height: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; background: rgba(11,14,19,.95); backdrop-filter: blur(10px); }
  .menu { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
  .menu a { padding: 8px 12px; white-space: nowrap; font-size: 14px; }
  .menu a.on { box-shadow: inset 0 -2px 0 var(--accent); }
  .side-note, .side-cta { display: none; }
  .g-map, .g-rev, .g-add { grid-template-columns: 1fr; }
  .d-grid { grid-template-columns: 1fr; }
  .d-col { display: contents; }
  .a-actions { order: 1; } .a-camera { order: 2; } .a-temp { order: 3; } .a-stock { order: 4; } .a-sales { order: 5; } .a-events { order: 6; }
  .main { padding: 22px 20px 60px; }
}
@media (max-width: 600px) {
  .main { padding: 18px 14px 60px; }
  h1 { font-size: 22px; }
  .kpi .v { font-size: 23px; }
  .kpis, .stats { gap: 10px; }
  .kpi { padding: 12px 14px; }
  #map { height: 300px; }
  .mtable .c-city, .mtable .c-stock, .mtable .c-sales { display: none; }
  .mtable td, .mtable th { padding: 10px 10px; }
  .mtable .id { display: block; margin-left: 0; }
  .form .row { grid-template-columns: 1fr; }
  .stock li { grid-template-columns: minmax(0, 1fr) 90px 56px; gap: 10px; }
  .alerts li { grid-template-columns: 1fr; gap: 10px; }
  .alerts li .btn { justify-self: start; }
  .card { padding: 16px; }
  .table-card { padding: 4px 0 0; }
  .demo-banner { font-size: 12px; }
  .menu a svg { display: none; }
  .menu a { padding: 7px 10px; font-size: 13.5px; }
  .actions-grid { grid-template-columns: 1fr 1fr; }
}
