:root { color-scheme: light; --accent: #0a6; --accent-hover: #098; --border: #e2e2e2; --bg: #fff; --side-bg: #f7f7f8; --text: #1f2328; --mut: #6b7280; }
* { box-sizing: border-box; }
body { font-family: system-ui, -apple-system, sans-serif; margin: 0; height: 100vh; overflow: hidden; color: var(--text); background: var(--bg); }
#layout { display: flex; height: 100vh; }
.hidden { display: none !important; }
.muted { color: var(--mut); }

/* ---- sidebar ---- */
#sidebar { width: 250px; border-right: 1px solid var(--border); background: var(--side-bg); display: flex; flex-direction: column; min-height: 0; }
#side-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.brand { font-size: 17px; margin: 0; }
#side-nav { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.side-section { margin-bottom: 8px; }
.side-label { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--mut); padding: 8px 6px 4px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.row-between button { border: 1px solid var(--border); background: var(--bg); color: var(--accent); border-radius: 6px; width: 22px; height: 22px; cursor: pointer; font-size: 14px; line-height: 1; }
#sidebar ul { list-style: none; margin: 0; padding: 0; }
#sidebar li { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 8px; }
#sidebar li:hover { background: #ececee; }
#sidebar li.active { background: var(--accent); color: #fff; }
#sidebar li.empty { cursor: default; color: var(--mut); font-size: 13px; }
#sidebar li.empty:hover { background: transparent; }
#side-foot { padding: 10px; border-top: 1px solid var(--border); }
.nav-btn { width: 100%; padding: 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 14px; color: var(--text); }
.nav-btn:hover { background: #efeff1; }

/* ---- chat ---- */
#chat-view, #settings-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
#chat-name { font-size: 17px; margin: 0; }
#chat-meta { font-size: 12px; }
#controls { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--mut); }
#controls select, #controls input { padding: 4px; border-radius: 5px; border: 1px solid var(--border); }
#messages { flex: 1; overflow-y: auto; padding: 16px; }
.msg { max-width: 72%; margin: 8px 0; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.msg.user { background: var(--accent); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg.bot { background: #f0f0f0; color: var(--text); margin-right: auto; border-bottom-left-radius: 4px; }
.msg.system { background: transparent; color: var(--mut); font-style: italic; margin-right: auto; }
#composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
#composer input { flex: 1; padding: 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 15px; }
#composer button { padding: 12px 18px; border-radius: 8px; border: none; background: var(--accent); color: #fff; font-size: 15px; cursor: pointer; }
#composer button:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- settings ---- */
#settings-layout { display: flex; flex: 1; min-height: 0; }
#settings-nav { width: 190px; border-right: 1px solid var(--border); padding: 12px; background: var(--side-bg); }
#settings-nav ul { list-style: none; margin: 0; padding: 0; }
#settings-nav li { padding: 9px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
#settings-nav li:hover { background: #ececee; }
#settings-nav li.active { background: var(--accent); color: #fff; }
#settings-content { flex: 1; overflow-y: auto; padding: 22px 28px; }
#settings-content h3 { margin-top: 0; }
#settings-back { margin: 12px 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--mut); margin-bottom: 4px; }
.field input, .field select { padding: 8px; border-radius: 6px; border: 1px solid var(--border); width: 260px; font-size: 14px; }
.field textarea { padding: 8px; border-radius: 6px; border: 1px solid var(--border); width: min(620px, 100%); font-size: 14px; font-family: inherit; resize: vertical; }
.small-hint { font-size: 12px; margin: 4px 0 0; }
hr.settings-sep { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
#bot-editor-save { padding: 9px 18px; border-radius: 7px; border: none; background: var(--accent); color: #fff; cursor: pointer; font-size: 14px; }
#bot-editor-save:hover { background: var(--accent-hover); }
#bot-editor-save:disabled { opacity: 0.6; cursor: not-allowed; }
/* --- mqtt alerter settings --- */
.ghost-btn { padding: 8px 14px; border-radius: 7px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; font-size: 13px; }
.ghost-btn:hover { background: #efeff1; }
.field-row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.ar-in { padding: 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 14px; }
.ar-wide { flex: 1; min-width: 240px; }
.alerter-title { font-weight: 600; margin-bottom: 10px; }
.alerter-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.alerter-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.alerter-name { font-weight: 600; }
.alerter-topic { font-family: ui-monospace, monospace; font-size: 12px; }
.alerter-msg { margin: 6px 0; font-size: 13px; }
.alerter-targets { margin: 6px 0; }
.alerter-chip { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #eef6f2; color: var(--accent); font-size: 12px; margin-right: 6px; }
.alerter-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.alerter-actions button { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 12.5px; }
.alerter-actions button:hover { background: #efeff1; }
.alerter-bots { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 4px; }
.alerter-bot { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 400; color: var(--text); cursor: pointer; }
.alerter-sim-row { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.alerter-sim-row input { padding: 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; flex: 1; min-width: 160px; }
.alerter-sim-row button { padding: 8px 16px; border-radius: 7px; border: none; background: var(--accent); color: #fff; cursor: pointer; }
.bot-list-settings { list-style: none; padding: 0; }
.bot-list-settings li { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }

/* tools grant matrix */
table.tools-matrix { border-collapse: collapse; margin-top: 6px; min-width: 520px; }
.tools-matrix th, .tools-matrix td { border-bottom: 1px solid var(--border); padding: 9px 12px; font-size: 13px; text-align: left; }
.tools-matrix th { font-weight: 600; }
.tools-matrix .cell-center { text-align: center; }
.tool-name { font-weight: 600; font-size: 13px; }
.tool-desc { font-size: 12px; max-width: 380px; }
.tool-toggle { width: 16px; height: 16px; cursor: pointer; }
.toggler-status { margin-top: 10px; font-size: 12px; min-height: 16px; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--bg); border-radius: 12px; padding: 22px 24px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-card h2 { margin: 0 0 14px; font-size: 17px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--mut); margin-bottom: 12px; }
.modal-card input, .modal-card select { padding: 8px; border-radius: 6px; border: 1px solid var(--border); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-actions button { padding: 8px 14px; border-radius: 7px; border: none; background: var(--accent); color: #fff; cursor: pointer; font-size: 13px; }
.modal-actions button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
