/* Energy Manager - shared UI styles (site + central). Colours build on charts.css tokens. */
:root {
  --ui-accent: #1f6fd1;
  --ui-accent-ink: #ffffff;
  --ui-accent-soft: rgba(31, 111, 209, 0.10);
  --ui-bg: var(--emc-page);
  --ui-surface: var(--emc-surface);
  --ui-surface-2: var(--emc-surface-2);
  --ui-ink: var(--emc-ink);
  --ui-ink-2: var(--emc-ink-2);
  --ui-muted: var(--emc-muted);
  --ui-border: var(--emc-border);
  --ui-line: var(--emc-grid);
  --ui-nav-bg: #14202e;
  --ui-nav-ink: #c9d3de;
  --ui-nav-ink-2: #8193a6;
  --ui-nav-active: #ffffff;
  --ui-nav-hover: rgba(255, 255, 255, 0.06);
  --ui-danger: #c62f2f;
  --ui-ok: #0e8a3a;
  --ui-warn: #b36b00;
  --ui-radius: 8px;
  --ui-shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 2px 8px rgba(11, 11, 11, 0.04);
  --ui-font: var(--emc-font);
  --ui-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ui-accent: #4a95ea; --ui-accent-soft: rgba(74, 149, 234, 0.16); --ui-nav-bg: #0f1419;
    --ui-danger: #f06a64; --ui-ok: #3ccf74; --ui-warn: #f0b24a; color-scheme: dark;
    --ui-shadow: 0 1px 2px rgba(0,0,0,.4); }
}
:root[data-theme="dark"] { --ui-accent: #4a95ea; --ui-accent-soft: rgba(74, 149, 234, 0.16); --ui-nav-bg: #0f1419;
  --ui-danger: #f06a64; --ui-ok: #3ccf74; --ui-warn: #f0b24a; color-scheme: dark; --ui-shadow: 0 1px 2px rgba(0,0,0,.4); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--ui-bg); color: var(--ui-ink); font: 14px/1.45 var(--ui-font); -webkit-font-smoothing: antialiased; }
a { color: var(--ui-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
code, .mono { font-family: var(--ui-mono); font-size: 12.5px; }
.muted { color: var(--ui-muted); }
.ink2 { color: var(--ui-ink-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.stack > * + * { margin-top: 12px; }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--ui-nav-bg); color: var(--ui-nav-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav .brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; }
.nav .brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #2a78d6, #1baf7a); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.nav .brand b { display: block; font-size: 14px; line-height: 1.2; }
.nav .brand span { display: block; font-size: 11px; color: var(--ui-nav-ink-2); }
.nav .group { padding: 10px 16px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ui-nav-ink-2); }
.nav a.item { display: flex; align-items: center; gap: 10px; padding: 7px 16px; color: var(--ui-nav-ink); border-left: 3px solid transparent; font-size: 13.5px; }
.nav a.item:hover { background: var(--ui-nav-hover); text-decoration: none; color: #fff; }
.nav a.item.active { color: var(--ui-nav-active); background: rgba(255,255,255,.08); border-left-color: #4a95ea; }
.nav a.item svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav a.item .count { margin-left: auto; background: var(--ui-danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; }
.nav .foot { margin-top: auto; padding: 12px 16px; font-size: 11px; color: var(--ui-nav-ink-2); border-top: 1px solid rgba(255,255,255,.06); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--ui-surface); border-bottom: 1px solid var(--ui-border); position: sticky; top: 0; z-index: 20; }
.topbar .crumbs { font-size: 13px; color: var(--ui-muted); }
.topbar .crumbs b { color: var(--ui-ink); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .menu-btn { display: none; }
.content { padding: 20px 24px 40px; max-width: 1600px; width: 100%; }
.banner { padding: 8px 24px; font-size: 13px; background: #fff4d6; color: #6b4b00; border-bottom: 1px solid rgba(0,0,0,.06); }
:root[data-theme="dark"] .banner { background: #3a2f12; color: #f6d88d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3a2f12; color: #f6d88d; } }
.banner.info { background: var(--ui-accent-soft); color: var(--ui-ink); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: fixed; z-index: 50; width: 260px; transform: translateX(-100%); transition: transform .18s; }
  .app.nav-open .nav { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 8px 16px; }
}
@media (max-width: 640px) {
  /* phone: keep the top bar on one line (breadcrumb prefix and user name are in the menu / page title) */
  .topbar .crumbs > span, .topbar .row > span.small { display: none; }
  .topbar .crumbs { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .row { flex-wrap: nowrap; }
}

/* ---------------------------------------------------------------- page header */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; }
.page-head .sub { color: var(--ui-muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- cards / grid */
.card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow); min-width: 0; }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--ui-line); }
.card > .hd h3 { font-size: 14px; }
.card > .hd .sub { color: var(--ui-muted); font-size: 12px; }
.card > .hd .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card > .bd { padding: 14px 16px; }
.card > .bd.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }  /* wide tables / charts in a grid cell must not widen the whole column (mobile) */
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-kpi { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
@media (max-width: 1200px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span3 { grid-column: span 2; } }
@media (max-width: 760px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; } }

.kpi-tile { padding: 14px 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .lbl { font-size: 12px; color: var(--ui-muted); }
.stat .val { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .val small { font-size: 13px; font-weight: 500; color: var(--ui-ink-2); margin-left: 3px; }

/* ---------------------------------------------------------------- buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--ui-border);
  background: var(--ui-surface); color: var(--ui-ink); font: 500 13px var(--ui-font); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--ui-surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 1px; }
.btn.primary { background: var(--ui-accent); color: var(--ui-accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--ui-danger); }
.btn.danger.solid { background: var(--ui-danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.icon { width: 32px; padding: 0; }
.btn[disabled], a.btn.disabled { opacity: .5; cursor: default; pointer-events: none; }
a.btn { text-decoration: none; }
.btn svg { width: 15px; height: 15px; }
input, select, textarea { font: 13.5px var(--ui-font); color: var(--ui-ink); background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 6px; padding: 6px 9px; min-height: 32px; max-width: 100%; }
textarea { min-height: 70px; resize: vertical; width: 100%; }
input[type=checkbox] { min-height: 0; width: 16px; height: 16px; accent-color: var(--ui-accent); vertical-align: -3px; }
select { padding-right: 24px; }
.input-sm { min-height: 28px; padding: 3px 7px; font-size: 12.5px; }
label.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--ui-border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--ui-surface); color: var(--ui-ink-2); padding: 0 10px; height: 30px; font: 500 12.5px var(--ui-font); cursor: pointer; border-right: 1px solid var(--ui-border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ui-accent-soft); color: var(--ui-accent); }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form.one { grid-template-columns: 1fr; }
.form .f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form .f.full { grid-column: 1 / -1; }
.form .f > label { font-size: 12px; font-weight: 600; color: var(--ui-ink-2); }
.form .f > label .req { color: var(--ui-danger); }
.form .f .help { font-size: 11.5px; color: var(--ui-muted); }
.form .f input:not([type=checkbox]), .form .f select { width: 100%; }
.form .f.err input, .form .f.err select { border-color: var(--ui-danger); }
.form .sect { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ui-muted); border-bottom: 1px solid var(--ui-line); padding-bottom: 4px; margin-top: 6px; }
@media (max-width: 640px) { .form { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--ui-ink-2); padding: 8px 10px; border-bottom: 1px solid var(--ui-line); background: var(--ui-surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--ui-ink); }
.tbl th .arrow { opacity: .6; font-size: 10px; margin-left: 3px; }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--ui-line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--ui-accent-soft); }
.tbl tbody tr.sel td { background: var(--ui-accent-soft); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .empty { text-align: center; color: var(--ui-muted); padding: 28px 10px; }
.tbl-tools { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--ui-line); flex-wrap: wrap; }
.tbl-tools input[type=search] { width: 240px; }
.tbl-foot { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 8px 12px; font-size: 12px; color: var(--ui-muted); border-top: 1px solid var(--ui-line); }

/* ---------------------------------------------------------------- badges / dots */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--ui-surface-2); color: var(--ui-ink-2); white-space: nowrap; }
.badge.ok { background: rgba(14,138,58,.12); color: var(--ui-ok); }
.badge.warn { background: rgba(179,107,0,.13); color: var(--ui-warn); }
.badge.bad { background: rgba(198,47,47,.12); color: var(--ui-danger); }
.badge.info { background: var(--ui-accent-soft); color: var(--ui-accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ui-muted); flex: none; }
.dot.ok { background: var(--emc-good); } .dot.warn { background: var(--emc-warn); } .dot.bad { background: var(--emc-bad); }
.sev-critical { color: #fff; background: var(--emc-bad); } .sev-high { background: rgba(208,59,59,.14); color: var(--ui-danger); }
.sev-medium { background: rgba(250,178,25,.18); color: var(--ui-warn); } .sev-low { background: var(--ui-accent-soft); color: var(--ui-accent); }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--ui-line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: 500 13.5px var(--ui-font); color: var(--ui-ink-2); cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--ui-ink); }
.tabs button.on { color: var(--ui-accent); border-bottom-color: var(--ui-accent); }

/* ---------------------------------------------------------------- modal / toast */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 12, 18, .45); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--ui-surface); color: var(--ui-ink); border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(920px, 100%); }
.modal.xwide { width: min(1240px, 100%); }
.modal .mh { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--ui-line); }
.modal .mh h3 { font-size: 15px; }
.modal .mh .x { margin-left: auto; }
.modal .mb { padding: 16px 18px; overflow-y: auto; }
.modal .mf { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--ui-line); flex-wrap: wrap; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1e2a38; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25); border-left: 4px solid #4a95ea; }
.toast.ok { border-left-color: #3ccf74; } .toast.err { border-left-color: #f06a64; } .toast.warn { border-left-color: #f0b24a; }

/* ---------------------------------------------------------------- misc components */
.empty-state { text-align: center; padding: 40px 16px; color: var(--ui-muted); }
.empty-state h3 { color: var(--ui-ink); margin-bottom: 6px; }
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; background: var(--ui-accent-soft); }
.alert.err { background: rgba(198,47,47,.10); color: var(--ui-danger); }
.alert.ok { background: rgba(14,138,58,.10); color: var(--ui-ok); }
.alert.warn { background: rgba(179,107,0,.12); color: var(--ui-warn); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv > div:nth-child(odd) { color: var(--ui-muted); }
.log { font: 12px/1.5 var(--ui-mono); background: var(--ui-surface-2); border-radius: 6px; padding: 10px; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.progress { height: 6px; background: var(--ui-surface-2); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ui-accent); transition: width .3s; }
.progress.warn > i { background: var(--ui-warn); }
.progress.bad > i { background: var(--ui-danger); }
.tree { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.tree ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--ui-line); margin-left: 7px; }
.tree li > .node { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.tree li > .node:hover { background: var(--ui-accent-soft); }
.tree li > .node.sel { background: var(--ui-accent-soft); color: var(--ui-accent); font-weight: 600; }
.tree .node .meta { margin-left: auto; color: var(--ui-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-box { width: 100%; min-height: 120px; }
.picker { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 9px; border-radius: 12px; background: var(--ui-surface-2); font-size: 12.5px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--ui-muted); font-size: 14px; line-height: 1; padding: 2px 4px; }
.value-live { font-variant-numeric: tabular-nums; font-weight: 600; }
.q-uncertain { color: var(--ui-warn); } .q-bad { color: var(--ui-danger); }
.medium-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 20% 0%, rgba(42,120,214,.16), transparent), var(--ui-bg); }
.login { width: min(380px, 100%); }
.login .brand { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
.login .brand .logo { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #2a78d6, #1baf7a); color: #fff; display: grid; place-items: center; font-weight: 700; }
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.tour-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
@media print { .nav, .topbar, .page-head .actions, .no-print { display: none !important; } .app { display: block; } .content { padding: 0; } .card { box-shadow: none; break-inside: avoid; } }

/* ---- hierarchy tree + dashboards (v1.5) */
.split > * { min-width: 0; }
.tree-card > .bd { max-height: calc(100vh - 210px); overflow: auto; }
.tree-ic { display: inline-grid; place-items: center; width: 18px; color: var(--ui-muted); font-size: 12px; }
.tree-ic.t-site { color: var(--ui-accent); } .tree-ic.t-equipment { color: var(--emc-s3, #d98a1c); }
.pt-editor { display: flex; flex-direction: column; gap: 6px; }
.pt-row { display: grid; grid-template-columns: minmax(150px, 1.2fr) minmax(170px, 1.5fr) 100px minmax(200px, 1.6fr) auto; gap: 8px; align-items: center; }
.pt-row input[type=text], .pt-row select { width: 100%; min-width: 0; }
.pt-head { font-size: 12px; color: var(--ui-muted); font-weight: 600; }
@media (max-width: 900px) { .pt-row { grid-template-columns: 1fr 1fr; } .pt-head { display: none; } }
.dash-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.dash-bar .full { flex-basis: 100%; }
.dash-where { font-size: 15px; }
.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 150px; gap: 14px; grid-auto-flow: row dense; }
.dash-grid > * { min-width: 0; }
.widget { display: flex; flex-direction: column; overflow: hidden; }
.widget > .hd { padding: 8px 12px; min-height: 38px; }
.widget > .hd h3 { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.widget .w-body { flex: 1; min-height: 0; overflow: auto; padding: 8px 12px 10px; position: relative; }
.widget.w-kpi_energy .w-body, .widget.w-kpi_point .w-body { padding: 4px 14px; }
.widget.w-equipment_table .w-body { padding: 0; }
.w-empty { display: grid; place-items: center; height: 100%; text-align: center; padding: 8px; }
.w-text { white-space: pre-wrap; font-size: 13.5px; }
.w-point .val { font-size: 26px; }
.w-status { display: flex; flex-direction: column; }
.w-status-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--ui-line); font-size: 13px; }
.w-status-row:last-child { border-bottom: 0; }
.w-alarms { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.w-alarm { display: flex; gap: 8px; align-items: center; }
.w-alarm .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-tools { margin-left: auto; display: flex; gap: 2px; flex-wrap: wrap; }
.dash-grid.editing .widget > .hd { flex-wrap: wrap; row-gap: 4px; }
.dash-grid.editing .widget > .hd h3 { flex: 1 1 100%; }
.dash-grid.editing .widget > .hd .w-tools { margin-left: 0; }
.w-point .val small { font-size: 13px; font-weight: 400; color: var(--ui-muted); }
.w-btn { border: 1px solid var(--ui-line); background: var(--ui-bg, transparent); color: inherit; border-radius: 4px; width: 20px; height: 20px; cursor: pointer; font-size: 11px; line-height: 1; padding: 0; }
.w-btn:hover { background: var(--ui-accent-soft); }
.dash-grid.editing .widget { outline: 2px dashed var(--ui-line); cursor: grab; }
.dash-grid.editing .widget.dragging { opacity: .45; }
.dash-grid.editing .widget.drop { outline-color: var(--ui-accent); }
.w-lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.w-lib-item { display: flex; gap: 10px; align-items: center; text-align: left; padding: 10px 12px; border: 1px solid var(--ui-line); border-radius: 8px; background: transparent; color: inherit; cursor: pointer; font: inherit; font-size: 13px; }
.w-lib-item:hover, .w-lib-item:focus-visible { border-color: var(--ui-accent); background: var(--ui-accent-soft); }
.w-lib-ic { width: 38px; text-align: center; font-size: 16px; color: var(--ui-accent); flex: none; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; grid-auto-rows: minmax(150px, auto); } .dash-grid > .widget { grid-column: auto !important; grid-row: span 2 !important; }
  .dash-grid > .widget.w-kpi_energy, .dash-grid > .widget.w-kpi_point, .dash-grid > .widget.w-text { grid-row: span 1 !important; } }

/* ---- Copilot (v1.7) */
.cp-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cp-layout { grid-template-columns: 1fr; } }
.cp-card > .bd { padding: 0; }
.cp-chat { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 460px; }
.cp-msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.cp-msg { display: flex; }
.cp-user { justify-content: flex-end; }
.cp-bubble { max-width: min(760px, 92%); padding: 10px 14px; border-radius: 12px; background: var(--ui-surface-2); border: 1px solid var(--ui-line); font-size: 14px; line-height: 1.5; }
.cp-user .cp-bubble { background: var(--ui-accent); color: #fff; border-color: transparent; }
.cp-md p { margin: 0 0 6px; } .cp-md ul { margin: 4px 0 8px 18px; padding: 0; } .cp-md h4 { margin: 8px 0 4px; font-size: 14px; }
.cp-md code { font-size: 12px; }
.cp-meta { margin-top: 8px; font-size: 11px; color: var(--ui-muted); }
.cp-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--ui-line); align-items: flex-end; }
.cp-input textarea { flex: 1; resize: vertical; min-height: 44px; }
.cp-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px; }
.cp-chip { border: 1px solid var(--ui-line); background: transparent; color: inherit; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.cp-chip:hover { border-color: var(--ui-accent); color: var(--ui-accent); }
.cp-act { border: 1px solid var(--ui-line); border-radius: 10px; padding: 10px 12px; background: var(--ui-surface); color: var(--ui-ink); }
.cp-act-hd { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; } .cp-act-hd svg { width: 16px; height: 16px; }
.cp-slides { margin: 4px 0 8px 18px; padding: 0; columns: 2; }
.cp-wlist { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.cp-params { display: block; margin-bottom: 8px; white-space: pre-wrap; word-break: break-all; }
.cp-kpis { margin-top: 4px; }
.cp-ctx { font-size: 11px; opacity: .85; margin-top: 3px; }
.cp-explain { border-left: 3px solid var(--ui-accent); background: var(--ui-accent-soft); padding: 8px 12px; border-radius: 6px; margin: 8px 0; font-size: 13px; }
.cp-anom { padding: 12px 14px; border-left: 4px solid var(--ui-warn); }
.cp-anom.cp-sev-high, .cp-anom.cp-sev-critical { border-left-color: var(--ui-danger); }
.cp-anom-hd { display: flex; align-items: flex-start; gap: 10px; }
.cp-anom-ic { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--ui-surface-2); font-size: 15px; flex: none; }
.cp-wo .form { margin-bottom: 8px; } .cp-wo textarea { width: 100%; }
.cp-chat.compact { height: auto; min-height: 0; flex: 1; }
.cp-chat.compact .cp-msgs { padding: 12px; }
.cp-chat.compact .cp-bubble { max-width: 100%; font-size: 13px; }
.cp-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: var(--ui-surface); border-left: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow); z-index: 150; display: flex; flex-direction: column; transform: translateX(105%); transition: transform .18s ease; }
.cp-drawer.open { transform: none; }
.cp-drawer-hd { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--ui-line); }
.cp-drawer-hd svg { width: 18px; height: 18px; color: var(--ui-accent); }
.cp-drawer-bd { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.cp-drawer-bd .cp-chat { flex: 1; min-height: 0; }
.cp-x { border: 0; background: transparent; color: inherit; font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.cp-x:hover { background: var(--ui-surface-2); }
@media (prefers-reduced-motion: reduce) { .cp-drawer { transition: none; } }
.cp-hist a { display: block; padding: 5px 0; border-bottom: 1px solid var(--ui-line); font-size: 13px; } .cp-hist a:last-child { border-bottom: 0; }
