* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100%; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif; color: #1f2937; background: #f3f4f6; }
.primary-btn, .secondary-btn, .ghost-btn, .tab-btn, .session-item { cursor: pointer; border: 0; border-radius: 14px; font-size: 14px; }
.primary-btn { background: #16a34a; color: #fff; padding: 12px 16px; }
.secondary-btn { background: #e5f6eb; color: #166534; padding: 10px 14px; }
.ghost-btn { background: #f3f4f6; color: #374151; padding: 10px 14px; }
.status-pill { padding: 6px 10px; border-radius: 999px; background: #fef3c7; color: #92400e; font-size: 12px; }
.status-healthy { background: #dcfce7; color: #166534; }
.status-unknown { background: #f3f4f6; color: #4b5563; }
.status-degraded { background: #fef3c7; color: #92400e; }
.status-down { background: #fee2e2; color: #b91c1c; }

.chat-body { background: #ededed; height: 100%; overflow: hidden; }
.chat-shell { max-width: 720px; margin: 0 auto; height: var(--app-height, 100vh); min-height: var(--app-height, 100vh); display: flex; flex-direction: column; overflow: hidden; }
.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; background: rgba(255,255,255,.95); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 2; }
.chat-header p { margin: 4px 0 0; color: #6b7280; font-size: 12px; }
.message-list { flex: 1 1 auto; min-height: 0; padding: 16px 12px 10px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.message-row { display: flex; align-items: flex-start; gap: 8px; }
.message-row.system, .message-row.agent { justify-content: flex-start; }
.message-row.user { justify-content: flex-end; }
.message-avatar { width: 34px; height: 34px; border-radius: 7px; flex: 0 0 34px; display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.message-avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; display: block; }
.avatar-system, .avatar-agent { background: #16a34a; color: #fff; }
.avatar-user { background: #d1d5db; color: #374151; }
.message-stack { max-width: min(74%, 520px); display: grid; gap: 4px; }
.stack-user { justify-items: end; }
.message-name { color: #8a8a8a; font-size: 12px; line-height: 1.2; padding: 0 2px; }
.bubble { max-width: min(74%, 520px); padding: 10px 12px; border-radius: 6px; box-shadow: none; position: relative; font-size: 15px; }
.message-stack .bubble { max-width: 100%; }
.bubble-system { background: #fff; }
.bubble-agent { background: #fff; }
.bubble-user { background: #95ec69; }
.bubble-system::before, .bubble-agent::before { content: ""; position: absolute; left: -5px; top: 12px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-right: 5px solid #fff; }
.bubble-user::after { content: ""; position: absolute; right: -5px; top: 12px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 5px solid #95ec69; }
.bubble p { margin: 0; line-height: 1.55; white-space: pre-wrap; }
.button-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.button-group.is-used button { opacity: .55; cursor: default; }
.button-group button:disabled { pointer-events: none; }
.guide-image { width: 100%; border-radius: 12px; margin-top: 8px; border: 1px solid #e5e7eb; }
.guide-gallery { display: flex; flex-wrap: nowrap; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 2px; }
.guide-thumb-link { display: block; width: 72px; height: 96px; border-radius: 10px; overflow: hidden; border: 1px solid #d1d5db; background: #fff; }
.guide-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-footer { position: relative; z-index: 3; flex: 0 0 auto; background: #f7f7f7; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid #d9d9d9; }
.chat-composer { display: flex; align-items: stretch; gap: 8px; }
.chat-footer textarea { width: 100%; min-height: 40px; height: 40px; max-height: 72px; border: 1px solid #d1d5db; border-radius: 6px; padding: 10px 12px; resize: none; font: inherit; font-size: 14px; line-height: 20px; background: #fff; overflow-y: auto; }
.chat-footer textarea::placeholder { color: #9ca3af; }
.chat-footer .primary-btn { font-size: 14px; border-radius: 6px; padding: 0 14px; min-width: 58px; height: 40px; box-shadow: none; background: #16a34a; flex-shrink: 0; align-self: flex-end; }
.leave-dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 420px); }
.leave-dialog form { padding: 18px; display: grid; gap: 12px; }
.leave-dialog label { display: grid; gap: 6px; font-size: 14px; }
.leave-dialog input, .leave-dialog textarea { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 10px; font: inherit; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.gallery-dialog { border: 0; padding: 0; width: min(96vw, 960px); max-width: 960px; background: transparent; }
.gallery-dialog::backdrop { background: rgba(0, 0, 0, .72); }
.gallery-viewer { position: relative; display: flex; align-items: center; justify-content: center; min-height: min(80vh, 720px); padding: 20px 54px; }
.gallery-image { max-width: 100%; max-height: 76vh; border-radius: 14px; background: #fff; box-shadow: 0 20px 50px rgba(0,0,0,.28); }
.gallery-nav, .gallery-close { position: absolute; border: 0; background: rgba(15,23,42,.72); color: #fff; cursor: pointer; }
.gallery-nav { top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 999px; font-size: 28px; line-height: 1; }
.gallery-prev { left: 8px; }
.gallery-next { right: 8px; }
.gallery-close { top: 6px; right: 6px; width: 36px; height: 36px; border-radius: 999px; font-size: 24px; line-height: 1; }

.admin-login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg,#e9f8ee,#f3f4f6); }
.login-card { width: min(92vw, 380px); display: grid; gap: 14px; background: #fff; padding: 28px; border-radius: 20px; box-shadow: 0 24px 60px rgba(15,23,42,.08); }
.login-card label, .stack-form label { display: grid; gap: 6px; font-size: 14px; }
.login-card input, .stack-form input, .stack-form textarea, .inline-form input, .inline-form textarea { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 10px; font: inherit; }
.error-text { color: #dc2626; min-height: 1.4em; }

.admin-body { min-height: 100vh; background: #f4f5f7; }
.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.admin-sidebar { background: #0f172a; color: #fff; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.admin-sidebar h1 { margin: 0 0 10px; font-size: 20px; }
.tab-btn { text-align: left; padding: 12px 14px; background: rgba(255,255,255,.08); color: #e5e7eb; }
.tab-btn.is-active { background: #16a34a; color: #fff; }
.logout-btn { margin-top: auto; }
.admin-main { padding: 20px; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.admin-card { background: #fff; border-radius: 18px; padding: 18px; box-shadow: 0 14px 40px rgba(15,23,42,.06); margin-bottom: 18px; }
.admin-card h3 { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.metric { font-size: 34px; font-weight: 700; color: #111827; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { border-bottom: 1px solid #e5e7eb; padding: 10px; vertical-align: top; text-align: left; }
.admin-table.compact textarea { min-height: 80px; }
.message-editor { display: grid; gap: 12px; }
.message-editor-list { display: grid; gap: 12px; }
.message-editor-item { border: 1px solid #e5e7eb; border-radius: 14px; padding: 12px; background: #f9fafb; display: grid; gap: 12px; }
.message-editor-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.message-editor-head strong { font-size: 14px; }
.message-editor-sort { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.message-editor-sort .ghost-btn { padding: 7px 9px; font-size: 12px; }
.message-editor-grid { display: grid; gap: 12px; }
.message-editor-grid select { width: 100%; border: 1px solid #d1d5db; border-radius: 12px; padding: 10px; font: inherit; background: #fff; }
.message-editor-grid small { color: #6b7280; display: block; margin-top: 6px; }
.message-editor-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button-config-editor { display: grid; gap: 10px; }
.button-config-rows { display: grid; gap: 10px; }
.button-config-row { display: grid; grid-template-columns: 1fr 1.2fr 1.3fr 1fr auto; gap: 8px; align-items: end; padding: 10px; border: 1px solid #e5e7eb; border-radius: 12px; background: #fff; }
.button-config-row label { gap: 5px; font-size: 12px; color: #4b5563; }
.button-config-row input, .button-config-row select { width: 100%; border: 1px solid #d1d5db; border-radius: 10px; padding: 9px; font: inherit; background: #fff; color: #111827; }
.button-config-row .ghost-btn { min-height: 38px; padding: 8px 10px; white-space: nowrap; }
.message-image-upload { display: grid; gap: 8px; }
.message-image-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.message-image-preview { width: 58px; height: 58px; border-radius: 10px; object-fit: cover; border: 1px solid #d1d5db; background: #fff; }
.message-gallery-upload { display: grid; gap: 8px; }
.message-gallery-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.message-gallery-preview { display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.message-gallery-thumb { width: 58px; height: 74px; flex: 0 0 auto; border-radius: 10px; object-fit: cover; border: 1px solid #d1d5db; background: #fff; }
.admin-inline-image { width: 140px; max-width: 100%; border-radius: 10px; border: 1px solid #e5e7eb; display: block; margin-top: 8px; }
.admin-inline-gallery { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.admin-inline-thumb { width: 60px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid #e5e7eb; background: #fff; }
.admin-inline-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.admin-inline-button { display: inline-flex; align-items: center; height: 30px; padding: 0 10px; border-radius: 999px; background: #ecfdf3; color: #166534; font-size: 12px; }
.image-upload-field { display: grid; gap: 8px; }
.image-upload-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-upload-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; }
.file-upload-btn.is-loading { opacity: .65; pointer-events: none; }
.file-upload-btn input { display: none; }
.image-upload-preview { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid #d1d5db; background: #fff; }
.inline-form, .stack-form { display: grid; gap: 12px; }
.inline-form { grid-template-columns: 2fr 1fr 120px auto auto; align-items: center; }
.session-workspace { display: grid; grid-template-columns: 320px minmax(0,1fr); gap: 18px; align-items: start; }
.session-list { display: grid; gap: 10px; max-height: 70vh; overflow: auto; }
.session-item { background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 16px; padding: 12px 14px; text-align: left; display: grid; gap: 6px; transition: background .18s ease, border-color .18s ease, transform .18s ease; }
.session-item:hover { background: #fff; border-color: #cbd5e1; transform: translateY(-1px); }
.session-item.is-active { background: #eff6ff; border-color: #93c5fd; box-shadow: inset 0 0 0 1px #bfdbfe; }
.session-item-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.session-item strong { font-size: 14px; color: #111827; }
.session-item span, .session-item small { color: #6b7280; }
.session-item small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.45; }
.session-chip { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; background: #ecfdf3; color: #166534 !important; font-size: 12px; white-space: nowrap; }
.session-detail-empty { color: #6b7280; min-height: 320px; display: flex; align-items: center; justify-content: center; background: #f8fafc; border: 1px dashed #d1d5db; border-radius: 16px; }
.session-thread { min-height: 70vh; display: grid; grid-template-rows: auto minmax(0,1fr) auto; border: 1px solid #e5e7eb; border-radius: 18px; overflow: hidden; background: #fff; }
.session-thread-head { padding: 14px 16px; border-bottom: 1px solid #e5e7eb; background: rgba(255,255,255,.92); }
.session-thread-head strong { display: block; font-size: 15px; color: #111827; }
.session-thread-sub { margin-top: 4px; color: #6b7280; font-size: 12px; }
.session-thread-body { min-height: 0; background: linear-gradient(180deg,#d9f4df 0,#f4f5f7 16%,#f4f5f7 100%); padding: 14px; }
.session-messages { display: grid; gap: 12px; max-height: 56vh; overflow: auto; padding-right: 4px; }
.admin-message-row { display: flex; }
.admin-message-row.user { justify-content: flex-start; }
.admin-message-row.agent { justify-content: flex-end; }
.admin-message-row.system { justify-content: center; }
.admin-message { width: min(100%, 78%); border: 1px solid #e5e7eb; border-radius: 18px; padding: 12px 14px; background: #fff; box-shadow: 0 8px 18px rgba(15,23,42,.04); }
.admin-message.user { background: #fff; border-top-left-radius: 8px; }
.admin-message.agent { background: #95ec69; border-color: #86db5f; border-top-right-radius: 8px; }
.admin-message.system { background: #f3f4f6; border-style: dashed; }
.admin-message-meta { margin-bottom: 6px; color: #6b7280; font-size: 12px; }
.admin-message p { margin: 0; line-height: 1.6; white-space: pre-wrap; }
.admin-message pre { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; }
.reply-form { display: grid; gap: 10px; margin-top: 12px; }
.reply-form textarea { min-height: 90px; border: 1px solid #d1d5db; border-radius: 12px; padding: 10px; font: inherit; }
.session-reply-form { margin-top: 0; padding: 12px 14px; border-top: 1px solid #e5e7eb; background: #fff; }
.session-reply-form textarea { min-height: 78px; }

@media (max-width: 960px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar { position: sticky; top: 0; z-index: 10; }
  .grid-2 { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .button-config-row { grid-template-columns: 1fr; }
  .session-workspace { grid-template-columns: 1fr; }
  .admin-message { width: 100%; }
  .session-thread { min-height: auto; }
  .session-messages { max-height: 52vh; }
  .gallery-viewer { padding: 16px 40px; min-height: 70vh; }
  .gallery-nav { width: 34px; height: 34px; font-size: 24px; }
  .gallery-close { width: 32px; height: 32px; font-size: 22px; }
}
