*,*::before,*::after{box-sizing:border-box}
/* overflow-x:clip (not hidden) so it does not create a scroll container, which would break
   position:sticky descendants such as the time-range bar on the advanced page. */
html,body{max-width:100%;overflow-x:hidden;overflow-x:clip}
select,input,textarea,button,img,canvas,svg,table{max-width:100%}
.card,.collapsible-small,.collapsible-big,.grid>*{min-width:0}
body{font-family:system-ui;background:#fff;color:#1f2937;margin:0;padding:24px}
.app-shell{display:flex;min-height:100vh;margin:-24px}
.sidebar{position:fixed;top:0;left:0;z-index:5;display:flex;flex-direction:column;width:230px;height:100vh;padding:20px 14px;background:#f3f7f4;border-right:1px solid #d9e6dd}
.sidebar-brand{display:flex;align-items:center;gap:10px;min-width:0;padding:4px 8px 24px;color:#1f2937;text-decoration:none;font-size:1.15rem;font-weight:700}
.sidebar-brand img{flex:0 1 auto;width:clamp(28px,18vw,72px);height:auto;object-fit:contain}
.sidebar-brand span{min-width:0;font-size:clamp(.8rem,5vw,1.15rem);white-space:nowrap}
.sidebar-nav,.sidebar-bottom{display:flex;flex-direction:column;gap:6px}
.sidebar-tab,.sidebar-link{display:block;width:100%;padding:11px 12px;border:0;border-radius:8px;background:transparent;color:#374151;text-align:left;text-decoration:none;font:inherit}
.sidebar-tab:hover,.sidebar-link:hover{background:#e5eee7}
.sidebar-tab.active,.sidebar-link.active{background:#dcefe1;color:#1f2937;font-weight:650}
.sidebar-bottom{margin-top:auto;border-top:1px solid #d9e6dd;padding-top:14px}
.sidebar-user-settings{display:flex;align-items:center;gap:4px;padding-right:10px;color:#6b7280;text-decoration:none}
.sidebar-user-settings:hover{border-radius:8px;background:#e5eee7}
.sidebar-user-settings.active{border-radius:8px;background:#dcefe1;color:#1f2937;font-weight:650}
.sidebar-username{padding:7px 4px 7px 12px;overflow-wrap:anywhere}
.sidebar-user-settings .mdi{font-size:20px}
.sidebar-bottom form{margin:0}
.sidebar-logout{width:100%;background:#fff;color:#374151;border-color:#d1d5db}
.app-main{flex:1;min-width:0;margin-left:230px;padding:24px}
/* The admin panel: a second menu bar on the left (Users / Reports / Payments / Configuration)
   inside the normal sidebar layout. */
.admin-shell{display:flex;gap:16px;align-items:flex-start;margin-top:14px}
/* min-height:100vh makes the nav's right border run the full height of the bar, matching the
   main sidebar on the left; background + z-index keep scrolled content from showing through
   the sticky bar (same as #timecontrols on the advanced page). */
.admin-nav{flex:none;width:170px;display:flex;flex-direction:column;gap:6px;position:sticky;top:0;z-index:8;min-height:100vh;padding:8px 10px;background:#fff;border-right:1px solid #d9e6dd}
.admin-nav-link{display:block;width:100%;padding:11px 12px;border:0;border-radius:8px;background:transparent;color:#374151;text-align:left;text-decoration:none;font:inherit}
.admin-nav-link:hover{background:#e5eee7}
.admin-nav-link.active{background:#dcefe1;color:#1f2937;font-weight:650}
.admin-content{flex:1;min-width:0}
.tab-panel[hidden]{display:none}
.tab-panel>h2{margin-top:0}
.statusbar{display:flex;flex-wrap:wrap;gap:4px}
.discovery-status{color:#6b7280}
.discovery-status.error,.discovery-command-status.error{color:#dc2626}
.device-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(520px,100%),1fr));gap:16px}
.discovery-device{position:relative;align-self:start;max-width:640px}
.discovery-device>summary.collapsible-summary{border-radius:11px 11px 0 0}
.collapsible-big{margin:14px 0;border:1px solid #d9e6dd;border-radius:12px;background:#fff;overflow:hidden}
/* The Tools menu must be able to extend past the device card. */
.discovery-device.collapsible-big{overflow:visible}
/* Base collapsible summary styling - shared chevron indicator */
.collapsible-summary{position:relative;display:flex;align-items:center;gap:8px;padding:6px 10px;cursor:pointer;font-weight:600;color:#1f2937;border-bottom: 1px solid #e5e7eb;}
.collapsible-summary::before{content:'▶';font-size:0.9rem;color:#1f2937;transition:transform 0.5s}
/* Apply rotation when parent details element is open */
details[open]>summary.collapsible-summary::before{transform:rotate(90deg)}
/* Prominent card styling shared by discovery devices and top-level tools. */
.collapsible-big>summary.collapsible-summary{padding:14px 16px 14px 14px;background:#f3f7f4;color:#1f2937;font-size:1.1rem;font-weight:650}
.collapsible-big>summary.collapsible-summary::before{font-size:1rem}
.collapsible-big:not(.discovery-device)[open]>:not(summary){margin:10px 14px}
.discovery-tools-menu button.tool-danger{margin-top:4px;background:#fff;color:#b91c1c;border-color:#fecaca}
.discovery-tools-menu button.tool-danger:hover{background:#fee2e2;border-color:#fca5a5}
.discovery-device-content{padding:10px 14px}
.discovery-device-header{margin-bottom:12px}
.discovery-device-header-row{display:flex;align-items:center;justify-content:space-between;gap:12px}
.discovery-device-meta{flex:1 1 auto;min-width:0;margin:0;color:#6b7280;overflow-wrap:anywhere}
.discovery-device-meta>.discovery-muted{display:block;margin-top:3px}
.discovery-muted{color:#6b7280;font-size:.86em}
.dashboard-svg{display:block;width:100%;margin:8px 0 16px}
.dashboard-svg-image{display:block;width:100%;height:auto}
.discovery-entity{position:relative;display:grid;grid-template-columns:minmax(0,1fr) minmax(110px,auto);gap:8px;align-items:center;padding:6px 6px;border-bottom:1px solid #edf0f2;font-size:.9rem}
.discovery-entity:last-child{border-bottom:0}
.discovery-entity-label{grid-area:1/1;display:flex;align-items:center;gap:8px;min-width:0}
.discovery-device-tools{display:flex;flex:0 0 auto;align-items:center;justify-content:flex-end;min-height:34px}
.discovery-tools{position:relative}
.discovery-entity-name{min-width:0;overflow-wrap:anywhere}
.discovery-plot-link{min-width:0;padding:0;border:0;background:transparent;color:inherit;font:inherit;text-align:left;text-decoration:none;overflow-wrap:anywhere}
.discovery-plot-link:hover,.discovery-plot-link:focus-visible{background:transparent;text-decoration:underline}
.discovery-icon{width:20px;color:#1f2937;text-align:center;overflow:hidden}
.discovery-entity-label .mdi{flex:0 0 20px;color:#1f2937;font-size:20px;text-align:center}
.discovery-values{grid-area:1/2;display:grid;gap:4px;justify-items:end;overflow-wrap:anywhere}
.discovery-value{display:flex;gap:8px;align-items:baseline;text-align:right}
.discovery-control{display:flex;align-items:center;justify-content:flex-end;gap:8px;min-width:0;max-width:100%;padding:4px 0}
.discovery-controls{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap}
.discovery-controls button,.discovery-controls input,.discovery-controls select{font-size:inherit;padding:5px 8px}
.discovery-controls button{transition:filter .4s}
.discovery-controls button.discovery-sent{filter:brightness(.75)}
.discovery-control input[type=checkbox]{width:20px;height:20px;margin:0}
.discovery-control input[type=range]{width:140px;max-width:45vw;accent-color:#3f8f58;padding:0}
.discovery-range-value{min-width:3em;text-align:right;font-variant-numeric:tabular-nums}
.discovery-control input[type=number],.discovery-control input[type=text],.discovery-control select{min-width:80px;width:min(180px,45%)}
.discovery-command-status{display:block;grid-column:1/-1;padding:0 8px 4px;color:#6b7280;font-size:.85em}
.discovery-command-status:empty{display:none}
.discovery-tools-trigger{list-style:none;padding:4px 8px;border:1px solid #d1d5db;border-radius:6px;background:#fff;color:#374151;font-size:.82rem;cursor:pointer}
.discovery-tools-trigger::-webkit-details-marker{display:none}
.discovery-tools-menu{position:absolute;top:100%;right:0;margin-top:4px;z-index:12;display:grid;min-width:210px;gap:6px;padding:8px;border:1px solid #d1d5db;border-radius:8px;background:#fff;box-shadow:0 8px 20px #0002}
.discovery-tools-menu button{width:100%;padding:7px 9px;text-align:left;font-size:.85rem}
.discovery-tools-menu button.tool-blue{background:#2563eb;border-color:#2563eb;color:#fff}
.discovery-tools-menu button.tool-blue:hover{background:#1d4ed8;border-color:#1d4ed8}
.discovery-tools-menu button.tool-green{background:#16a34a;border-color:#16a34a;color:#fff}
.discovery-tools-menu button.tool-green:hover{background:#15803d;border-color:#15803d}
.discovery-tool-status{display:none;min-width:0;margin-top:8px;padding:6px 8px;border-radius:6px;background:#f3f4f6;overflow-wrap:anywhere;color:#6b7280;font-size:.82rem}
.discovery-tool-status:not(:empty){display:block}
.discovery-tool-status.error{color:#dc2626}
.discovery-plot-dialog{width:min(1100px,94vw);max-height:92vh;overflow:auto;padding:20px;background:#fff;border-radius:12px}
.discovery-plot-header{display:flex;align-items:center;justify-content:space-between;gap:16px}
.discovery-plot-actions{display:flex;gap:8px}
.discovery-plot-header h3{margin:0}
.discovery-plot-ranges{margin:12px 0}
.discovery-plot-ranges button.active{background:#3f8f58;border-color:#3f8f58;color:#fff;font-weight:bold}
.discovery-channel-picker{margin:12px 0;padding:10px;border:1px solid #d9e6dd;border-radius:8px}
.discovery-channel-picker summary.collapsible-summary{}
.discovery-channel-picker>input{width:100%;margin-top:10px}
.discovery-channel-picker .topiclist{grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))}
.discovery-channel-picker .topiclist label{display:flex;align-items:flex-start;gap:8px;min-width:0;margin:0}
.discovery-channel-picker .topiclist input[type=checkbox]{flex:0 0 auto;width:auto;margin:3px 0 0}
.discovery-channel-picker .topiclist input[type=radio]{flex:0 0 auto;width:auto;margin:3px 0 0}
.discovery-channel-picker .topiclist label span{min-width:0;overflow-wrap:anywhere}
/* Wrapper around the dashboard plot div: the plot hamburger menu anchors to its top right. */
.discovery-plot-area{position:relative}
.discovery-plot{height:min(60vh,600px);min-height:300px}
.discovery-plot-dialog>p{min-height:1.2em;color:#6b7280}
.discovery-plot-dialog>p.error{color:#dc2626}
.controls{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin:12px 0 20px}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(560px,100%),1fr));gap:16px}
.card{background:#fff;border:1px solid #d9e6dd;border-radius:12px;padding:16px}
select,input,textarea,button{padding:9px 12px;border-radius:8px;background:#fff;color:#1f2937;border:1px solid #b9cdbf}
input[type=checkbox]{accent-color:#3f8f58}
button{cursor:pointer;background:#72C086;border-color:#72C086;color:#14351f}
button:hover{background:#5fb076;border-color:#5fb076}
#rangebtns button.active{background:#3f8f58;border-color:#3f8f58;color:#fff;font-weight:bold}
/* Time range and shift controls share one row: the range buttons may wrap/overflow, the shift
   pair stays together (nowrap, pushed to the right edge) for as long as possible. */
#rangebtns{display:flex;gap:10px;flex-wrap:wrap;align-items:center;min-width:0}
#shiftbtns{display:flex;gap:10px;flex-wrap:nowrap;flex:none;margin-left:auto}
/* Keep the time range / shift buttons usable while scrolling down the graphs: the bar sticks
   to the top of the viewport once it would otherwise scroll away (below the modal overlay). */
#timecontrols{position:sticky;top:0;z-index:8;background:#fff;padding:8px 0;box-shadow:0 8px 10px -10px rgba(0,0,0,.35)}
button.danger{background:#dc2626;border-color:#dc2626;color:#fff}
button.danger:hover{background:#b91c1c}
.collapsible-small{margin:8px 0;border:1px solid #e5e7eb;border-radius:9px;background:#fff;overflow:hidden}
.collapsible-small>summary.collapsible-summary{padding:8px 14px;background:#f9fafb;font-size:.95rem}
.collapsible-small[open]>:not(summary){margin:12px 10px}
#topiccount{font-variant-numeric:tabular-nums}
.publishrow{display:grid;grid-template-columns:auto minmax(0,1fr);gap:10px;align-items:start;margin-top:14px}
.topicline{display:flex;align-items:center;gap:4px;min-width:0}
.topicline input{flex:1;min-width:180px}
.publishrow textarea{grid-column:2;min-height:150px;resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.publishrow button{grid-column:2;justify-self:start}
.publishrow #pubstatus{grid-column:2}
.prefix{color:#6b7280;overflow-wrap:anywhere}
/* Delete-topic search: the text box has a fixed width; matches drop down under it, never a full list. */
.deltowrap{position:relative}
#deltopic{width:26em;flex:none}
/* User search boxes (dashboard, advanced, admin panel): same dropdown pattern, the user list is
   searched on the server (max 10 matches), so it is never rendered as a whole. */
.usersearchwrap{position:relative;display:inline-block}
.usersearchwrap input{width:16em}
.usersearchwrap .suggest{width:16em}
.suggest{position:absolute;top:100%;left:0;z-index:30;width:26em;max-width:100%;max-height:16em;overflow:auto;background:#fff;border:1px solid #d1d5db;border-radius:6px;box-shadow:0 4px 12px rgba(0,0,0,.12)}
.suggest button{display:block;width:100%;text-align:left;padding:6px 10px;border:0;border-radius:0;background:none;cursor:pointer;overflow-wrap:anywhere}
.suggest button:hover,.suggest button.active{background:#f3f7f4}
/* Layout list: always visible and wide (hline + grey "Standard layouts:" header, the standard
   layouts, hline + grey "Custom layouts:" header, then the custom layouts with wastebin buttons).
   The loaded row is highlighted.
   width:auto (not 100%): the generic .collapsible-small[open]>:not(summary) rule adds 10px left and
   right margins, so a 100% width would overflow the box by 20px on narrow windows. max-width keeps
   it wide on large screens; the symmetric margins stay intact. */
.layoutlist{width:auto;max-width:46em;max-height:18em;overflow:auto;background:#fff;border:1px solid #d1d5db;border-radius:6px}
.layoutitem{display:flex;align-items:center}
.layoutitem .layoutname{flex:1;padding:6px 10px;cursor:pointer;overflow-wrap:anywhere}
.layoutitem:hover .layoutname,.layoutitem.active .layoutname{background:#f3f7f4}
.layoutitem.selected .layoutname{background:#d9e6dd;font-weight:600}
.layoutsep{border-top:1px solid #d1d5db;margin:2px 0}
.layoutgroup{padding:4px 10px;color:#6b7280;font-size:small}
.layoutdel{border:0;background:none;color:#dc2626;cursor:pointer;padding:4px 8px;font-size:20px;line-height:1;border-radius:4px;flex:none}
.layoutdel:hover{background:#fee2e2}
h1{margin:0}
.loginlogo{display:block;width:160px;max-width:60%;height:auto;margin:0 auto 16px}
.loginbox h1{text-align:center}
.loginbox p{text-align:center}
.loginpage{min-height:calc(100vh - 48px);display:flex;flex-direction:column;align-items:center;justify-content:center}
.loginbox{width:min(360px,100%);box-sizing:border-box;background:#fff;border:1px solid #d9e6dd;border-radius:12px;padding:28px}
.loginbox h1{font-size:1.6rem;margin-bottom:8px}
.loginbox p{color:#6b7280;margin:0 0 20px}
.loginbox label{display:block;margin:14px 0 6px}
.loginbox input{box-sizing:border-box;width:100%}
.loginbox button{width:100%;margin-top:20px}
.loginbox .loginregister,.loginbox .logincancel{display:block;box-sizing:border-box;width:100%;margin-top:10px;margin-bottom:10px;text-align:center}
/* The Cancel button of the re-send-activation view is a neutral mild-dark grey, not green like the primary actions. */
.loginbox .logincancel{background:#fff;border-color:#6b7280;color:#3e433f}
.loginbox .logincancel:hover{background:#eee;border-color:#6b7280;color:#3e433f}
/* Success messages are plain black text - the interface uses no green text anywhere. */
.loginsuccess{color:#000!important;margin-top:14px!important}
.loginhint{font-size:.85rem;color:#6b7280;margin:8px 0 0}
.loginlinks{text-align:center;margin-top:14px}
.loginerror{color:#dc2626!important;margin-top:14px!important}
.settings-section{max-width:760px;margin:18px 0;padding:16px;border:1px solid #d9e6dd;border-radius:12px;background:#fff}
/* Two columns: the label on the left, the input on the right - so the From/To labels line up
   with their date boxes and checkboxes line up with the text inputs. */
.settings-form{display:grid;grid-template-columns:minmax(180px,auto) minmax(0,1fr);gap:8px 16px;max-width:520px;align-items:center}
.settings-form label{margin:0;overflow-wrap:anywhere}
.settings-form input[type=checkbox]{justify-self:start;width:auto}
.settings-form p{grid-column:1/-1}
.settings-form button{grid-column:1/-1;justify-self:start;margin-top:8px}
.settings-form p.error{color:#dc2626}
/* The admin Configuration editors have long dotted keys, so they get a wider form. */
.config-form{max-width:760px}
.config-form textarea{width:100%;box-sizing:border-box;font:inherit}
.config-form .config-help{grid-column:1/-1;margin-top:-4px;opacity:.7}
.settings-table-wrap{overflow-x:auto}
/* Wrapper for wide tables inside the collapsible boxes (e.g. the admin user management list): the
   table scrolls horizontally when the screen is too narrow, instead of being clipped, because
   .collapsible-small has overflow:hidden. */
.table-scroll{overflow-x:auto}
.settings-table{width:100%;border-collapse:collapse;text-align:left}
.settings-table th,.settings-table td{padding:8px 10px;border-bottom:1px solid #e5e7eb}
.usage-list{display:grid;grid-template-columns:minmax(180px,1fr) minmax(0,2fr);gap:8px 16px}
.usage-list dt{font-weight:600}
.usage-list dd{margin:0;overflow-wrap:anywhere}
.pubbtns{grid-column:2;display:flex;gap:10px;align-items:center;margin-top:8px}
/* JSON editor of the module configuration (Advanced tab): the textarea sits on top of a <pre> that
   renders the same text with colored JSON tokens. Both must keep the exact same font, size,
   line-height and padding, otherwise the highlight drifts from the typed text. */
/* Editor header: label on the left, the Close editor button at the top-right of the text box. */
.cfgedithead{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:0 0 6px}
.cfgedithead label{margin:0}
/* Editor footer row: the JSON validity pill (same .status pill as the MQTT status label,
   green "connected" when valid, red "disconnected" when invalid) left-aligned, the Submit
   button right-aligned. */
.cfgeditfoot{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:8px}
.cfgeditwrap{position:relative;border:1px solid #b9cdbf;border-radius:8px;background:#fff;overflow:hidden}
.cfgeditwrap pre,.cfgeditwrap textarea{margin:0;padding:9px 12px;border:0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.85rem;line-height:1.45;white-space:pre;tab-size:2}
.cfgeditwrap pre{position:absolute;inset:0;overflow:hidden;pointer-events:none}
.cfgeditwrap textarea{position:relative;display:block;width:100%;box-sizing:border-box;min-height:640px;resize:vertical;background:transparent;color:transparent;caret-color:#1f2937}
.cfgeditwrap textarea::placeholder{color:#9ca3af}
.cfgeditwrap .jkey{color:#2563eb}
.cfgeditwrap .jstr{color:#15803d}
.cfgeditwrap .jnum{color:#b91c1c}
.cfgeditwrap .jlit{color:#7c3aed}
/* Brackets: matched pairs in teal, unmatched or mismatched brackets flagged with a red background. */
.cfgeditwrap .jbr{color:#0e7490}
.cfgeditwrap .jbad{background:#fecaca;color:#b91c1c;border-radius:3px}
/* Extra spacing between the "Edit module configuration" button and the download/send file buttons to its right. */
.cfgright{margin-left:28px}
.status{margin:4px 2px; display:inline-block; padding:4px 12px;border-radius:999px;font-size:14px;background:#e5e7eb;color:#374151}
.status.connected{background:#c6e8d0;color:#000}
.status.disconnected{background:#fecaca;color:#7f1d1d}
.status.connecting{background:#fde68a;color:#78350f}
.userform{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
.users td{padding:6px 12px 6px 0}
/* Keep the action buttons (last column) on one line; the table scrolls horizontally instead. */
.users td:last-child{white-space:nowrap}
.users button{padding:4px 10px;margin-right:6px}
.users th button.sort{padding:0;margin:0;border:0;background:none;color:inherit;font:inherit;cursor:pointer}
.users th[aria-sort=ascending]::after{content:" \25B2"}
.users th[aria-sort=descending]::after{content:" \25BC"}
/* Themed pop-up dialogs (js/ui.js, replacing native alert/confirm/prompt): the backdrop washes out
   the rest of the webpage while a dialog is open. z-index above the other modals (.modal, #addmodal). */
.ui-backdrop{position:fixed;inset:0;background:rgba(17,24,39,.45);display:none;align-items:center;justify-content:center;z-index:30}
.ui-backdrop.open{display:flex}
.ui-dialog{background:#fff;padding:16px;border-radius:8px;width:min(420px,92vw);max-height:80vh;overflow:auto;box-shadow:0 10px 30px rgba(0,0,0,.25)}
.ui-dialog .ui-text{white-space:pre-wrap;margin:0 0 12px}
.ui-dialog input{box-sizing:border-box;width:100%;margin:0 0 12px}
.ui-dialog .ui-buttons{display:flex;gap:8px;justify-content:flex-end}
.ui-dialog .ui-buttons button.ghost{background:#fff;color:#1f2937;border:1px solid #b9cdbf}
.ui-dialog .ui-buttons button.ghost:hover{background:#f3f4f6}
.modal{position:fixed;inset:0;background:rgba(0,0,0,.4);display:none;align-items:center;justify-content:center;z-index:10}
.modal .box{background:#fff;padding:16px;border-radius:8px;width:min(420px,92vw);max-height:80vh;overflow:auto}
.modal label{display:block;margin:12px 0 6px}
.modal input,.modal select{box-sizing:border-box;width:100%}
.modal .loginerror{margin:10px 0 0!important}
.plot-wrap{position:relative}
.plot{height:340px}
.plot-loading{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:#fff;color:#6b7280;border-radius:8px;border:1px dashed #b9cdbf;font-size:15px;box-sizing:border-box;z-index:2;pointer-events:none}
/* Hamburger menu of a plot: on the top right of the discovery plot div, and in the card header
   row (next to the plot title) for plot cards. Holds the advanced plot functions
   (select extra topics/channels, select x-axis, CSV and JSON export). */
.plot-menu{position:absolute;top:8px;right:8px;z-index:6}
.plot-menu>.plot-menu-trigger{list-style:none;display:flex;flex-direction:column;justify-content:center;gap:3px;width:32px;height:30px;padding:7px;box-sizing:border-box;border:1px solid #d1d5db;border-radius:6px;background:#fff;cursor:pointer}
.plot-menu>.plot-menu-trigger::-webkit-details-marker{display:none}
.plot-menu>.plot-menu-trigger:hover{background:#f3f4f6}
.plot-menu>.plot-menu-trigger span{display:block;height:2px;border-radius:1px;background:#374151}
.plot-menu-items{position:absolute;top:calc(100% + 4px);right:0;display:grid;gap:6px;min-width:240px;max-width:min(420px,90vw);max-height:70vh;overflow:auto;padding:8px;border:1px solid #d1d5db;border-radius:8px;background:#fff;box-shadow:0 8px 20px #0002}
.plot-menu-items>button{width:100%;padding:7px 9px;text-align:left;font-size:.9rem}
/* Spacer between the channel/x-axis buttons and the CSV/JSON export buttons. */
.plot-menu-items>.savecsv{margin-top:10px}
/* Channel/x-axis pickers live inside the plot menu as nested collapsibles. */
.plot-menu-items .discovery-channel-picker{margin:0}
/* Card header row: the plot title on the left; the hamburger plot menu and the move up/down
   buttons right-aligned next to each other on the right. */
.cardhead{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin-bottom:8px}
.cardhead h3{margin:0}
.cardhead .plot-menu{position:relative;top:auto;right:auto;margin-left:auto}
.cardrow{display:flex;align-items:center}
.movebtn{margin-left:6px;padding:6px 12px}
.movebtn.first{margin-left:0}
#addmodal,#xmodal{position:fixed;inset:0;background:rgba(0,0,0,.4);display:none;align-items:center;justify-content:center;z-index:10}
#addmodal .box,#xmodal .box{background:#fff;padding:16px;border-radius:8px;width:min(720px,92vw);max-height:80vh;overflow:auto}
#addfilter,#xfilter{box-sizing:border-box;width:100%}
.topicbtns{display:flex;gap:10px;margin-top:12px}
/* Same containment fix as .layoutlist: this input sits inside a .collapsible-small, whose children
   get 10px left/right margins from .collapsible-small[open]>:not(summary), so width:100% would
   overflow the box by 20px on narrow windows. An input does not shrink with width:auto. */
#topicfilter{margin-top:12px;box-sizing:border-box;width:calc(100% - 20px)}
.topiclist{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:6px 16px;margin:12px 0}
/* The "Time (default)" entry of the x-axis pickers: full-width line above the topic/channel list. */
.topiclist .xaxis-default{grid-column:1/-1;border-bottom:1px solid #e5e7eb;padding-bottom:8px}
.topiclist .xaxis-default label{display:flex;align-items:center;gap:8px}
.topiclist label{overflow-wrap:anywhere}
.topiclist input{padding:0}
.history{font-size:small;list-style:none;padding:0;margin:0;max-height:340px;overflow:auto;position:relative}
.history li{padding:8px;border-bottom:1px solid #e5e7eb}
.history li.match{background:#fef08a}
/* Search box of a text-topic card: below the card header row, left-aligned with the title. */
.textsearch{display:block;margin:0 0 10px;padding:4px 8px;width:14em;max-width:100%;box-sizing:border-box}
.time{color:#6b7280}
h3{overflow-wrap:anywhere;margin-top:0px;}
.vspace{height:30px;display:flex;align-items:center;justify-content:center}
.vspace::before{content:'';width:30%;border-top:2px dotted #b9cdbf}
@media(max-width:700px){
  .app-shell{display:block}
  .admin-shell{display:block}
  /* On phones the admin nav is a top bar: give it the same floating look as the sticky
     time-range bar (#timecontrols) on the advanced page. */
  .admin-nav{width:100%;min-height:0;flex-direction:row;flex-wrap:wrap;border-right:0;border-bottom:1px solid #d9e6dd;padding:8px 0;box-shadow:0 8px 10px -10px rgba(0,0,0,.35)}
  .admin-nav-link{width:auto}
  .sidebar{position:relative;top:auto;left:auto;width:100%;height:auto;min-height:0;padding:10px 12px;border-right:0;border-bottom:1px solid #d9e6dd}
  .sidebar-brand{padding:2px 6px 8px}
  .sidebar-nav{flex-direction:row}
  .sidebar-tab,.sidebar-link{width:auto}
  .sidebar-bottom{flex-direction:row;align-items:center;flex-wrap:wrap;margin-top:8px;padding-top:8px}
  .sidebar-user-settings{padding-right:6px}
  .sidebar-bottom form{margin-left:auto}
  .app-main{margin-left:0;padding:16px}
  .discovery-plot-dialog{width:96vw;padding:12px}
  .discovery-plot{height:52vh;min-height:260px}
}
