/**
 * Copyright (c) 2014 The xterm.js authors. All rights reserved.
 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
 * https://github.com/chjj/term.js
 * @license MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Originally forked from (with the author's permission):
 *   Fabrice Bellard's javascript vt100 for jslinux:
 *   http://bellard.org/jslinux/
 *   Copyright (c) 2011 Fabrice Bellard
 *   The original design remains. The terminal itself
 *   has been extended to include xterm CSI codes, among
 *   other features.
 */.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm .xterm-scroll-area{visibility:hidden}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{-webkit-user-select:text;user-select:text;white-space:pre}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}:root{--bg: #f5f7fa;--card: #ffffff;--primary: #1f7ae0;--text: #1a2330;--muted: #6b7280;--border: #e3e8ef;--danger: #c0392b}*{box-sizing:border-box}html,body,#root{margin:0;height:100%}body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:var(--bg);color:var(--text)}.center{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:24px}.muted{color:var(--muted)}.small{font-size:13px}.card{background:var(--card);width:100%;max-width:360px;padding:32px;border-radius:12px;box-shadow:0 6px 24px #141e3214;display:flex;flex-direction:column;gap:14px}.brand{font-size:20px;font-weight:700;margin:0}.card>.muted{margin:-8px 0 4px}label{display:flex;flex-direction:column;gap:6px;font-size:14px;font-weight:600}input{padding:10px 12px;border:1px solid var(--border);border-radius:8px;font-size:15px;font-weight:400}input:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px #1f7ae026}button{padding:10px 14px;border:none;border-radius:8px;background:var(--primary);color:#fff;font-size:15px;font-weight:600;cursor:pointer}button:disabled{opacity:.6;cursor:default}button.ghost{background:transparent;color:var(--primary);border:1px solid var(--border)}.alert{background:#fdecea;color:var(--danger);padding:10px 12px;border-radius:8px;font-size:14px}.page{min-height:100vh}.topbar{display:flex;align-items:center;justify-content:space-between;padding:14px 24px;background:#fff;border-bottom:1px solid var(--border)}.topbar .user{display:flex;align-items:center;gap:12px}.content{max-width:760px;margin:0 auto;padding:28px 24px}.clinic-list{list-style:none;padding:0;margin:16px 0 0;display:flex;flex-direction:column;gap:10px}.clinic{display:flex;align-items:center;gap:14px;background:#fff;border:1px solid var(--border);border-radius:10px;padding:14px 16px}.logo{width:44px;height:44px;border-radius:8px;object-fit:cover;flex-shrink:0}.logo.placeholder{display:flex;align-items:center;justify-content:center;background:var(--primary);color:#fff;font-weight:700;font-size:18px}.clinic-info{flex:1;min-width:0}.clinic-name{font-weight:600}.badge{font-size:11px;background:#eef4ff;color:var(--primary);padding:2px 6px;border-radius:5px;margin-left:6px;vertical-align:middle}.clinic-button{cursor:pointer;transition:border-color .15s,box-shadow .15s}.clinic-button:hover{border-color:var(--primary);box-shadow:0 2px 8px #1f7ae01a}.clinic-button:focus-visible{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px #1f7ae026}.chevron{color:var(--muted);font-size:24px;line-height:1;flex-shrink:0}.chat-layout{display:flex;flex-direction:column;height:100vh}.topbar-left{display:flex;align-items:center;gap:14px;min-width:0}.chat-clinic{display:flex;align-items:center;gap:8px;min-width:0}.chat-clinic-name{font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.small-btn{padding:6px 10px;font-size:13px}.chat-messages{flex:1;overflow-y:auto;background:var(--bg)}.chat-thread{max-width:760px;margin:0 auto;min-height:100%;padding:24px;background:#fff;display:flex;flex-direction:column;gap:14px}.bubble-row{display:flex;gap:10px;align-items:flex-start}.bubble-row.user{justify-content:flex-end}.avatar{width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:13px;flex-shrink:0}.assistant-avatar{background:var(--primary);color:#fff}.bubble{padding:10px 14px;border-radius:12px;max-width:75%;white-space:pre-wrap;word-wrap:break-word;line-height:1.45;font-size:15px}.bubble.assistant{background:#fff;border:1px solid var(--border);border-top-left-radius:4px}.md>*:first-child{margin-top:0}.md>*:last-child{margin-bottom:0}.md p{margin:0 0 8px}.md ul,.md ol{margin:0 0 8px;padding-left:20px}.md li{margin:2px 0}.md h1,.md h2,.md h3,.md h4{margin:10px 0 6px;font-size:15px;font-weight:700}.md code{background:#f0f3f8;padding:1px 5px;border-radius:4px;font-size:13px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}.md pre{background:#0b0e14;color:#e6edf3;padding:10px 12px;border-radius:8px;overflow-x:auto;margin:0 0 8px}.md pre code{background:none;padding:0;color:inherit;font-size:12.5px}.md a{color:var(--primary)}.md table{border-collapse:collapse;margin:0 0 8px;font-size:13px}.md th,.md td{border:1px solid var(--border);padding:4px 8px;text-align:left}.md blockquote{margin:0 0 8px;padding-left:10px;border-left:3px solid var(--border);color:var(--muted)}.bubble.user{background:var(--primary);color:#fff;border-top-right-radius:4px}.typing{display:inline-flex;gap:4px;align-items:center}.typing-after{margin-top:8px}.typing .dot{width:7px;height:7px;border-radius:50%;background:var(--muted);opacity:.4;animation:typing-blink 1.2s infinite ease-in-out}.typing .dot:nth-child(2){animation-delay:.2s}.typing .dot:nth-child(3){animation-delay:.4s}@keyframes typing-blink{0%,80%,to{opacity:.25}40%{opacity:.9}}.content.wide{max-width:1100px}.usage-card{background:#fff;border:1px solid var(--border);border-radius:10px;padding:14px 16px;margin-bottom:16px}.usage-head{display:flex;align-items:baseline;gap:10px;margin-bottom:12px}.usage-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}@media (max-width: 640px){.usage-grid{grid-template-columns:1fr}}.usage-label{font-size:14px;font-weight:600;margin-bottom:6px}.usage-label .muted{font-weight:400}.usage-bar{height:8px;background:#eef1f5;border-radius:999px;overflow:hidden}.usage-bar-fill{height:100%;border-radius:999px;transition:width .4s}.usage-foot{margin-top:12px;padding-top:10px;border-top:1px solid var(--border)}.admin-table{width:100%;border-collapse:collapse;background:#fff;border:1px solid var(--border);border-radius:10px;overflow:hidden;margin-top:16px}.admin-table th,.admin-table td{text-align:left;padding:10px 12px;border-bottom:1px solid var(--border);font-size:14px;vertical-align:middle}.admin-table th{background:#f0f3f8;font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.03em;color:var(--muted)}.admin-table tr:last-child td{border-bottom:none}.state{display:inline-block;padding:2px 8px;border-radius:999px;font-size:12px;font-weight:600}.state.ok{background:#e6f6ec;color:#1a7f37}.state.off{background:#f0f1f3;color:var(--muted)}.badge.update{background:#fff4e5;color:#b45309;margin-left:6px}.badge.pin{background:transparent;padding:0;margin-left:6px;font-size:12px}.small-btn.attn{border-color:#f59e0b;color:#b45309;font-weight:600}.actions{display:flex;gap:6px;flex-wrap:wrap}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;background:#0a0f198c;display:flex;align-items:center;justify-content:center;padding:20px;z-index:50}.modal{background:#fff;border-radius:12px;box-shadow:0 10px 40px #0a14284d;max-width:95vw;max-height:92vh;display:flex;flex-direction:column;overflow:hidden}.modal-head{display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-bottom:1px solid var(--border);font-weight:600;font-size:14px}.tui-modal{width:auto}.tui-term{background:#0b0e14;padding:8px;overflow:auto}.composer{display:flex;gap:10px;padding:14px 16px;border-top:1px solid var(--border);background:#fff;align-items:flex-end}.composer-input{flex:1;resize:none;border:1px solid var(--border);border-radius:10px;padding:10px 12px;font:inherit;font-size:15px;max-height:160px;overflow-y:auto;scrollbar-width:none}.composer-input::-webkit-scrollbar{display:none}.assistant-msg{width:100%;font-size:15px;line-height:1.5;color:var(--text)}.composer-input:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px #1f7ae026}.send-btn{padding:10px 18px;flex-shrink:0}
