/* Shared reset, layout and components. Tokens live in theme.css. */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--company-color); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

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

/* ---------- Application shell ---------- */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-header {
  flex: 0 0 var(--header-h);
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 0; background: transparent; border-radius: var(--radius);
  color: var(--text); cursor: pointer; font-size: 16px;
  position: relative;
}
.icon-btn:hover { background: var(--surface-alt); }

.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; letter-spacing: .5px; }
.brand img { height: 36px; width: auto; }
.brand .sep { width: 2px; height: 28px; background: var(--company-color); }

.header-spacer { flex: 1; }
.connection { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.connection .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.connection[data-state="down"] .dot { background: var(--danger); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--company-color); color: var(--text-on-company);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; border: 0; cursor: pointer; text-transform: uppercase;
}

.badge {
  position: absolute; top: 3px; right: 2px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--company-color); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 18px; text-align: center;
}

.app-body { flex: 1; display: flex; min-height: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
  transition: width 200ms, flex-basis 200ms;
  user-select: none;
}
.sidebar-title {
  height: 45px; line-height: 45px; padding: 0 16px;
  font-size: 18px; font-weight: 500; background: var(--surface-alt);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.nav-group-label {
  padding: 12px 16px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-muted); white-space: nowrap;
}
.nav-link {
  display: flex; align-items: center; gap: 14px;
  height: 48px; padding: 0 16px;
  color: var(--text); text-decoration: none; white-space: nowrap;
  border-left: 3px solid transparent;
}
.nav-link i { flex: 0 0 18px; text-align: center; font-size: 15px; }
.nav-link:hover { background: var(--company-color); color: var(--text-on-company); }
.nav-link[aria-current="page"] {
  background: var(--company-color-faint); border-left-color: var(--company-color); font-weight: 600;
}
.nav-link[aria-current="page"]:hover { color: var(--text-on-company); }

body.sidebar-collapsed .sidebar { flex-basis: var(--sidebar-w-collapsed); width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .nav-link { padding: 0 13px; }
body.sidebar-collapsed .nav-link span,
body.sidebar-collapsed .nav-group-label,
body.sidebar-collapsed .sidebar-title { display: none; }

/* ---------- Content ---------- */
/* The content area never scrolls itself: the page header stays put and each page fills the rest of the height. */
.content { flex: 1; min-width: 0; min-height: 0; overflow: hidden; padding: 0; display: flex; flex-direction: column; }

.page-header {
  display: flex; align-items: center; gap: 12px;
  flex: none; flex-wrap: wrap; min-height: 45px; padding: 4px 14px; margin: 0;
  background: var(--surface-alt); border-bottom: .5px solid var(--border);
}
.page-title { font-size: 18px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.page-actions { margin-left: auto; display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; min-width: 0; }
.page-actions .btn { padding: 4px 12px; }
.page-actions .chip { font-size: 12px; padding: 3px 10px; }
.page-clock { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 10px; border-left: 1px solid var(--border); }
.page-clock b { font-size: 15px; font-weight: 600; }
.page-clock span { font-size: 11px; color: var(--text-muted); }

.grid { display: grid; gap: 10px; grid-template-columns: repeat(12, 1fr); }
.col-12 { grid-column: span 12; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }
@media (max-width: 1100px) { .col-6, .col-4, .col-3 { grid-column: span 12; } }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); padding: 0 10px 10px;
  transition: box-shadow 300ms ease-in-out;
}
.panel:hover { box-shadow: var(--shadow-hover); }
.panel-header {
  display: flex; align-items: center; gap: 8px;
  margin: 0 -10px 10px; padding: 0 10px; height: 30px; flex: none; /* never squeezed when the panel is a short flex column */
  background: var(--surface-head); border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.panel-body { padding: 0 2px; }
/* What sits at the right of a panel header (buttons, selects, chart tools). */
.panel-aside { margin-left: auto; font-weight: 400; font-size: 13px; display: flex; align-items: center; gap: 6px; }
/* Compact controls: a button or select in a header never makes the bar taller than its normal 30 px (.btn-sm is the same size for toolbars). */
.panel-header .btn, .panel-header select, .panel-header .input, .btn-sm {
  box-sizing: border-box; height: 24px; padding: 2px 10px; font-size: 13px; line-height: 1.4; gap: 6px;
}
.panel-header select, .panel-header .input { padding-right: 6px; }
.panel-header .input.date { width: 140px; }
.panel-header .icon-btn { width: 26px; height: 26px; }

.info-table { width: 100%; border-collapse: collapse; }
.info-table th { text-align: left; font-weight: 600; padding: 8px 12px 8px 0; width: 38%; vertical-align: top; white-space: nowrap; }
.info-table td { padding: 8px 0; color: var(--text-muted); vertical-align: top; overflow-wrap: anywhere; }
.info-table tr + tr { border-top: 1px solid var(--border); }

.map-frame { width: 100%; height: 100%; min-height: 240px; border: 0; display: block; flex: 1; }

/* ---------- Forms & buttons ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--text-muted); }
.input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--input-border); border-radius: var(--radius);
  background: var(--bg);
}
.input:focus { border-color: var(--company-color); outline: none; box-shadow: 0 0 0 1px var(--company-color); }
.input[type="color"] { padding: 2px; height: 38px; width: 70px; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 24px; border: 1px solid var(--text); border-radius: var(--radius);
  background: var(--bg); color: var(--text); cursor: pointer; font-size: 14px;
  transition: all 200ms ease-in-out;
}
.btn:hover:not(:disabled) { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary { background: var(--company-color); color: var(--text-on-company); border-color: var(--company-color); }
.btn-primary:hover:not(:disabled) { background: var(--company-color); border-color: var(--company-color); filter: brightness(.9); color: var(--text-on-company); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: 10px 12px; border-left: 4px solid var(--info); background: var(--tint-info); margin-bottom: 14px; }
.alert-danger { border-left-color: var(--danger); background: var(--tint-danger); }
.alert-warn { border-left-color: var(--warn); background: var(--tint-warn); }
.alert-ok { border-left-color: var(--ok); background: var(--tint-ok); }

/* ---------- Menus, toasts, banners ---------- */
.menu {
  position: absolute; right: 12px; top: calc(var(--header-h) - 4px); z-index: 50;
  min-width: 230px; background: var(--bg); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0,0,0,.16);
}
.menu-head { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.menu-head strong { display: block; }
.menu-head span { color: var(--text-muted); font-size: 12px; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px;
  border: 0; background: transparent; text-align: left; text-decoration: none; color: var(--text); cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-alt); }
.menu-foot { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  min-width: 240px; max-width: 360px; padding: 10px 14px; background: var(--text); color: var(--bg);
  border-left: 4px solid var(--company-color); box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.error { border-left-color: var(--danger); }

.update-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 12px; background: var(--company-color); color: var(--text-on-company);
}
.update-banner button { border: 1px solid currentColor; background: transparent; color: inherit; padding: 3px 12px; cursor: pointer; }

.loading { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--text-muted); }
.empty { padding: 40px 10px; text-align: center; color: var(--text-muted); }

/* ---------- Narrow screens: sidebar becomes a drawer ---------- */
@media (max-width: 800px) {
  .sidebar { position: fixed; z-index: 40; top: var(--header-h); bottom: 0; left: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform 200ms; }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 24px rgba(0,0,0,.25); }
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
  body.sidebar-collapsed .nav-link span, body.sidebar-collapsed .nav-group-label, body.sidebar-collapsed .sidebar-title { display: revert; }
  body.sidebar-collapsed .nav-link { padding: 0 16px; }
  .connection { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: .01ms !important; } }

.content:focus { outline: none; }
.inline-row { display: flex; align-items: center; gap: 8px; }
.field .input { flex: 0 0 auto; }

.dialog { border: 1px solid var(--border); padding: 0; box-shadow: 0 8px 32px rgba(0,0,0,.3); max-width: min(460px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog form { padding: 20px 24px; }
.dialog h3 { margin: 0 0 10px; font-weight: 600; }
.dialog p { margin: 0 0 18px; color: var(--text-muted); line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Navigation: collapsible groups, inverter list, alarm count ---------- */
.bell .badge { background: var(--danger); }
/* active alarms: the bell turns red and flashes, the count badge pulses (reduced motion: red, no flashing) */
.bell.has-active > i { color: var(--danger); animation: bell-flash 1s steps(1, end) infinite; }
.bell.has-active .badge { animation: bell-pulse 1s ease-in-out infinite; }
@keyframes bell-flash { 0% { opacity: 1; } 50% { opacity: .25; } }
@keyframes bell-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.bell[hidden] { display: none; }

.nav-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 12px 16px 4px; border: 0; background: transparent; cursor: pointer; font: inherit;
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted);
}
.nav-toggle:hover { color: var(--text); }
.nav-toggle i { font-size: 10px; transition: transform 150ms; }
.nav-group.closed .nav-toggle i { transform: rotate(-90deg); }
.nav-group.closed .nav-items { display: none; }

.nav-link .badge {
  position: static; margin-left: auto; background: var(--danger); font-style: normal;
}

.nav-item-row { position: relative; }
.nav-item-row > .nav-link { padding-right: 44px; }
.nav-expand {
  position: absolute; top: 0; right: 0; width: 40px; height: 48px; border: 0; background: transparent;
  color: inherit; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.nav-expand i { font-size: 11px; transition: transform 150ms; }
.nav-expand.open i { transform: rotate(90deg); }
.nav-item-row > .nav-link:hover + .nav-expand { color: var(--text-on-company); }
.nav-expand:hover { background: var(--surface-alt); color: var(--text); }

.nav-sub { display: none; padding: 4px 8px 8px 41px; background: var(--surface-alt); border-left: 3px solid transparent; }
.nav-sub.open { display: block; }
.nav-block { display: grid; grid-template-columns: 52px repeat(4, 1fr); align-items: center; gap: 4px; padding: 2px 0; font-size: 11px; color: var(--text-muted); }
.nav-chip {
  display: block; padding: 3px 0; text-align: center; font-size: 12px; text-decoration: none; color: var(--text);
  background: var(--bg); border: 1px solid var(--border);
}
.nav-chip:hover { background: var(--company-color); border-color: var(--company-color); color: var(--text-on-company); }
.nav-chip[aria-current="page"] { background: var(--company-color); border-color: var(--company-color); color: var(--text-on-company); font-weight: 600; }

body.sidebar-collapsed .nav-toggle, body.sidebar-collapsed .nav-expand, body.sidebar-collapsed .nav-sub { display: none; }
body.sidebar-collapsed .nav-group.closed .nav-items { display: block; }
body.sidebar-collapsed .nav-link .badge { display: none; }
@media (max-width: 800px) {
  body.sidebar-collapsed .nav-toggle, body.sidebar-collapsed .nav-expand { display: flex; }
  body.sidebar-collapsed .nav-sub.open { display: block; }
}

/* ---------- Header toggles, resizable menu, "fit to screen" ---------- */
.icon-btn.active { background: var(--company-color-faint); color: var(--company-color); }

.sidebar-resizer {
  flex: 0 0 5px; width: 5px; margin: 0 -2px 0 -3px; position: relative; z-index: 5;
  cursor: col-resize; touch-action: none; background: transparent; transition: background 150ms;
}
.sidebar-resizer:hover, .sidebar-resizer:focus-visible, body.resizing .sidebar-resizer { background: var(--company-color-soft); outline: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .sidebar { transition: none; }
body.sidebar-collapsed .sidebar-resizer { display: none; }
@media (max-width: 800px) { .sidebar-resizer { display: none; } }

[hidden] { display: none !important; }
.page { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page-body { flex: 1; min-height: 0; min-width: 0; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
/* The page's own view takes exactly the space that is left; what does not fit scrolls inside it. */
.page-body > * { flex: 1 1 0; min-height: 0; min-width: 0; }
.page-body > .alert, .page-body > .btn { flex: none; }
.fill { flex: 1 1 0; min-height: 0; min-width: 0; }
.panel.fill { display: flex; flex-direction: column; }
.scroll-y { overflow: auto; min-height: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; flex: 1; }
.tab-list { flex: none; }
.tab-list { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border: 0; border-bottom: 3px solid transparent;
  background: transparent; color: var(--text-muted); cursor: pointer; white-space: nowrap; margin-bottom: -1px;
}
.tab:hover { color: var(--text); background: var(--surface-alt); }
.tab[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--company-color); }
.tab i { color: var(--icon-color); }
.tab-badge {
  font-style: normal; font-size: 11px; font-weight: 700; padding: 0 6px; min-width: 18px; line-height: 18px; text-align: center;
  border-radius: 9px; background: var(--danger); color: #fff;
}
.tab-body { min-width: 0; min-height: 0; flex: 1; display: flex; flex-direction: column; }
.tab-panel { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; flex: 1; overflow: auto; }
.tab-panel[hidden] { display: none; }
.tab-stack { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; flex: 1; }
.tab-panel > :not(.fill):not(.tab-stack), .tab-stack > :not(.fill) { flex: none; }
.tab-panel > .alert { flex: none; }

/* ---------- Chart panels: fill the space, full screen, save as picture ---------- */
.chart-host.fill { flex: 1 1 0; min-height: 160px; }
.chart-host.fill .chart { position: absolute; left: 0; top: 0; }
.chart-tools { margin-left: auto; display: inline-flex; gap: 4px; }
.panel-aside .chart-tools { margin-left: 6px; }
.chart-tools .icon-btn { width: 26px; height: 26px; font-size: 13px; }
.panel:fullscreen { display: flex; flex-direction: column; padding: 0 16px 14px; background: var(--surface); overflow: auto; }
.panel:fullscreen .chart-host { flex: 1 1 0; min-height: 200px; }
.panel:fullscreen .chart-host .chart { position: absolute; left: 0; top: 0; }

/* ---------- Users page and other pages with their own tab bar ---------- */
.tab-content { display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.fill-col { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.fill-col > .filters, .fill-col > .pager-row { flex: none; }
.users-page .tab-list { margin: 0 -10px 10px; padding: 0 10px; background: var(--surface-alt); }
.charts-page > .tabs { flex: 0 0 36%; min-height: 190px; }

/* Chart "span" option (chartbox.js): on, a chart panel in full screen uses the whole screen height; off, it keeps its normal height. */
.chart-tools .icon-btn.active { color: var(--company-color); }
.panel.span-off:fullscreen .chart-host { flex: none; height: 420px; min-height: 0; }

/* ---------- The last box fills what is left ---------- */
/* One rule for every page: the last panel of a page, or of the open tab, takes the height that remains. Its own last child
   (table wrapper, chart, box grid, list) grows to fill it and scrolls inside itself when its content is taller.
   A panel that already has `.fill` is left alone: its page lays out its own inner parts (for example a table with a pager under it).
   `.fill-last` marks a box that the rule does not find by itself (for example one wrapped in another element);
   `.no-fill-last` switches the rule off for a box that should keep its own height. */
.dashboard > .panel:last-child:not(.fill), .tab-stack > .panel:last-child:not(.fill), .tab-panel > .panel:last-child:not(.fill), .page-body > .panel:last-child:not(.fill), .fill-last {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
}
:is(.dashboard, .tab-stack, .tab-panel, .page-body) > .panel:last-child:not(.fill) > :last-child:not(.panel-header):not([hidden]), .fill-last > :last-child:not(.panel-header) {
  flex: 1 1 auto; min-height: 0; overflow: auto;
}
:is(.dashboard, .tab-stack, .tab-panel, .page-body) > .panel.no-fill-last { flex: none; display: block; }
:is(.dashboard, .tab-stack, .tab-panel, .page-body) > .panel.no-fill-last > :last-child { flex: none; overflow: visible; }
/* long tables keep their header in view while the rows scroll */
.table-wrap > .table > thead > tr > th { position: sticky; top: 0; z-index: 1; background: var(--surface-head); }
.chart-host.fill { min-height: 240px; }

/* Install app (PWA) instructions (js/core/pwa.js) */
.pwa-dialog { max-width: 440px; }
.pwa-steps { margin: 8px 0 12px; padding-left: 22px; line-height: 1.55; }
.pwa-steps li { margin: 6px 0; }
.impersonate-banner { background: var(--warn, #c77700); color: #fff; }
/* Alarm bell list (js/app.js bellMenu): the current project's active alarms, or every project's on the portfolio pages */
.bell-menu { width: 380px; max-width: calc(100vw - 16px); max-height: min(70vh, 560px); display: flex; flex-direction: column; }
.bell-projects { flex: none; border-bottom: 1px solid var(--border); max-height: 180px; overflow: auto; }
.bell-projects .bell-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell-count { font-style: normal; font-size: 11px; font-weight: 700; padding: 0 6px; line-height: 18px; border-radius: 9px; background: var(--danger); color: #fff; }
.bell-list { flex: 1 1 auto; min-height: 0; overflow: auto; }
.menu .bell-item { align-items: flex-start; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.bell-time { flex: none; width: 42px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.bell-text { display: flex; flex-direction: column; min-width: 0; font-size: 13px; }
.bell-text > span { overflow-wrap: anywhere; }
.bell-text small { color: var(--text-muted); font-size: 11px; }
.bell-empty { padding: 14px; color: var(--text-muted); font-size: 13px; }
.menu .bell-foot { flex: none; border-top: 1px solid var(--border); }

/* ---------- Icons: one colour in every theme ----------
   Every Font Awesome icon is #339898 (--icon-color), whatever the theme's accent. :where() keeps this rule weaker than any
   page rule, so status icons (alarm, danger, on/off) keep their own colour. Icons on a filled background take the text colour. */
:where(i.fas, i.far, i.fab, i.fa) { color: var(--icon-color); }
.btn-primary i, .btn-primary:hover i, .nav-link:hover i, .nav-link[aria-current="page"]:hover i, .nav-chip:hover i, .nav-chip[aria-current="page"] i,
.nav-item-row > .nav-link:hover + .nav-expand i, .update-banner i, .avatar i, .ai-avatar i, .ai-welcome-logo i, .nav-range.active i,
.impersonate-banner i, .table tbody tr[class^="alarm-"] td i, .btn-danger i,
.icon-btn.danger i, .text-danger i, .secret-saved i, .prio i, .bell-count i, .badge i { color: inherit; }

/* ---------- Fit page to screen: the quick summary is sized to show whole (no scroll bar), so its tiles are compact ---------- */
body.fit-page .qs-list { gap: 4px; }
body.fit-page :is(.qs-list, .side-summary, .str-quick, .quick-grid) .stat { padding: 3px 10px 2px; }
body.fit-page :is(.qs-list, .side-summary, .str-quick, .quick-grid) .stat-body { padding: 1px 0 0; }
body.fit-page :is(.qs-list, .side-summary, .str-quick, .quick-grid) .stat-value { font-size: 20px; line-height: 1.15; }
body.fit-page :is(.qs-list, .side-summary, .str-quick, .quick-grid) .donut-host svg { max-height: 78px; }
body.fit-page .side-summary .side-alarm-box { flex-basis: 110px; min-height: 110px; }

/* Fit page to screen: every Quick Summary column reaches the bottom of the page, its tiles share the height (no scroll bar);
   the page is scaled so the tiles fit (core/shell.js), and the alarm list under them shows what fits ("View all" for the rest) */
body.fit-page .qs-fill { display: flex; flex-direction: column; min-height: 0; align-self: stretch; }
body.fit-page .str-quick > .qs-fill { flex: 1 1 auto; }
body.fit-page .qs-fill > :not(.panel-header), body.fit-page .qs-fill > :not(.panel-header) > :not(.qs-list, .quick-grid, .stat, .side-alarm-head, .side-alarms) { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
body.fit-page .qs-fill :is(.qs-list, .quick-grid) { flex: 1 1 auto; display: flex; flex-direction: column; gap: 4px; }
body.fit-page .qs-fill :is(.qs-list, .quick-grid) > .stat { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center; }
body.fit-page .qs-fill .side-alarm-box { flex: 0 0 auto; }
body.fit-page .qs-fill .side-alarms { overflow: hidden; flex: none; }
body.fit-page .qs-fill .side-alarms > .side-alarm:nth-child(n+3) { display: none; }   /* the newest two; "View all" for the rest */

/* ---------- Find and replace bar (js/core/findreplace.js) above the JSON editors ---------- */
.fr-bar { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-alt); }
.fr-bar[hidden] { display: none; }
.fr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.fr-row[hidden] { display: none; }
.fr-row .input { flex: 1 1 200px; min-width: 0; padding: 5px 8px; font-family: var(--font-mono, ui-monospace, Consolas, monospace); font-size: 13px; }
.fr-row .input.invalid { border-color: var(--danger); }
.fr-count { min-width: 70px; font-size: 12px; white-space: nowrap; }
.fr-opt { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; user-select: none; }
.fr-btn { width: 30px; height: 30px; font-size: 13px; }

/* Back / Forward beside the menu title (app.js navButtons, recordVisit): the last 50 pages of this tab */
.sidebar-title { display: flex; align-items: center; gap: 6px; }
.sidebar-title-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-hist-btns { flex: none; display: inline-flex; gap: 2px; }
.icon-btn.nav-hist { width: 28px; height: 28px; font-size: 13px; color: inherit; }
.icon-btn.nav-hist:disabled { opacity: .35; cursor: default; background: transparent; }

/* My profile > Appearance: segmented choices (pages/profile.js appearancePanel) */
.appearance { display: flex; flex-wrap: wrap; gap: 6px 32px; align-items: flex-start; padding-top: 4px; }
.appearance > p { flex-basis: 100%; margin: 0; font-size: 13px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--input-border); border-radius: var(--radius); overflow: hidden; margin-top: 4px; }
.seg > button { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border: 0; border-right: 1px solid var(--input-border); background: var(--bg); color: var(--text); cursor: pointer; }
.seg > button:last-child { border-right: 0; }
.seg > button:hover { background: var(--surface-alt); }
.seg > button[aria-checked="true"] { background: var(--company-color); color: var(--text-on-company); font-weight: 600; }
.seg > button[aria-checked="true"] i { color: inherit; }

/* colours a theme row can set (core/theme.js themeVars); without one they fall back to the design's own */
.app-header, .app-header .icon-btn, .app-header .brand { color: var(--header-text, var(--text)); }
.sidebar { background: var(--sidebar-bg, var(--bg)); color: var(--sidebar-text, var(--text)); }
.sidebar .nav-link:not(:hover) { color: var(--sidebar-text, var(--text)); }
.input { color: var(--input-text, var(--text)); background-color: var(--field-bg, var(--bg)); }

/* My profile > Theme settings: the themes of light and dark mode */
.theme-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; margin: 6px 0 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.theme-slots .field > label { font-weight: 600; font-size: 13px; }
.theme-slots .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
