/* ============================================================
   SAP Chat Aggregator — app layout
   (translated from the Claude Design prototype's inline styles)
   ============================================================ */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #5A6A7E;
  overflow: hidden;
  font-family: "Microsoft Sans Serif", Tahoma, sans-serif;
  -webkit-font-smoothing: none;
}
a { color: #1F6BB8; }
a:hover { color: #C8281E; }

@keyframes sap-marquee { from { background-position: 0 0; } to { background-position: 20px 0; } }
@keyframes sap-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

textarea.sap-input { height: auto; resize: none; line-height: 1.4; }
select.sap-input { height: 22px; }

/* uiFontSize prototype prop: default 16px -> zoom 16/12 */
.app-root {
  box-sizing: border-box;
  zoom: 1.3333;
  height: calc(100vh / 1.3333);
  padding: 8px;
  background: #5A6A7E;
  display: flex;
}
.app-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- Toolbar ----------------------------------------- */
.toolbar-model-label { margin: 0 2px 0 4px; }
.model-select { width: 220px; }
.endpoint-tag { margin-left: 4px; }
.spacer { flex: 1; }
.model-count { font-size: 10px; color: var(--fg-muted); }

/* ---------- Main split -------------------------------------- */
.app-main {
  flex: 1;
  display: flex;
  min-height: 0;
  gap: 6px;
  padding: 6px;
}

/* ---------- Sidebar ----------------------------------------- */
.sidebar {
  width: 240px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-2);
  box-shadow: var(--bevel-out-strong);
}
.sidebar-new { padding: 6px; border-bottom: 1px solid var(--border-mid); }
.btn-new-session { width: 100%; justify-content: center; }
.btn-label { margin-left: 4px; }
.sidebar-header {
  padding: 4px 6px;
  font-weight: 700;
  font-size: 11px;
  background: var(--gradient-toolbar);
  border-bottom: 1px solid var(--border-mid);
}
.conv-list {
  flex: 1;
  overflow-y: auto;
  background: var(--surface-inset);
  box-shadow: var(--bevel-in);
  min-height: 0;
}
.conv-item {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border-mid);
  background: var(--surface-inset);
}
.conv-item:hover { background: var(--accent-pale); }
.conv-item.selected, .conv-item.selected:hover { background: var(--accent); }
.conv-item-row { display: flex; align-items: center; gap: 4px; }
.conv-item-row svg { flex: none; }
.conv-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}
.conv-item-x {
  font-weight: 700;
  font-size: 11px;
  color: var(--fg-muted);
  padding: 0 3px;
}
.conv-item-x:hover { color: var(--status-error); }
.conv-item-meta {
  font-size: 9px;
  color: var(--fg-muted);
  margin-top: 1px;
  padding-left: 16px;
}
.sidebar-footer {
  padding: 6px;
  border-top: 1px solid var(--border-mid);
  display: flex;
  align-items: center;
  gap: 6px;
}
.operator-avatar { width: 24px; height: 24px; font-size: 10px; }
.operator-info { flex: 1; min-width: 0; }
.operator-name { font-weight: 700; font-size: 11px; }
.operator-meta { font-size: 9px; color: var(--fg-muted); }

/* ---------- Chat column ------------------------------------- */
.chat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.crumb-bar {
  padding: 3px 8px;
  background: var(--surface-3);
  box-shadow: var(--bevel-in);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}
.crumb-sep { color: var(--fg-muted); }
.crumb-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-count { font-size: 10px; color: var(--fg-muted); font-variant-numeric: tabular-nums; }

.msgs {
  flex: 1;
  overflow-y: auto;
  background: var(--surface-inset);
  box-shadow: var(--bevel-in-strong);
  padding: 12px 14px;
  min-height: 0;
}

/* Empty state */
.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--fg-muted);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  background: var(--surface-2);
  box-shadow: var(--bevel-in);
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state-title { font-weight: 700; color: var(--fg); }
.empty-state-hint { font-size: 10px; }

/* User message */
.msg-user { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.msg-user-inner { max-width: 72%; }
.msg-user-meta {
  text-align: right;
  font-size: 9px;
  color: var(--fg-muted);
  margin-bottom: 2px;
}
.msg-user-bubble {
  background: var(--accent-pale);
  box-shadow: var(--bevel-out-strong);
  padding: 5px 9px;
  white-space: pre-wrap;
  font-size: 12px;
  overflow-wrap: break-word;
}

/* Assistant message */
.msg-assistant { margin-bottom: 14px; }
.msg-assistant-head { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; }
.msg-assistant-who { font-weight: 700; font-size: 11px; }
.msg-assistant-time { font-size: 9px; color: var(--fg-muted); }
.msg-assistant-body {
  padding-left: 17px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: break-word;
}
.msg-assistant-body.plain { white-space: pre-wrap; }

/* Markdown elements, restyled for the retro SAP look */
.msg-assistant-body > :first-child { margin-top: 0; }
.msg-assistant-body > :last-child { margin-bottom: 0; }
.msg-assistant-body p { margin: 0 0 8px; }
.msg-assistant-body h1,
.msg-assistant-body h2,
.msg-assistant-body h3,
.msg-assistant-body h4,
.msg-assistant-body h5,
.msg-assistant-body h6 {
  font-family: var(--font-bold);
  font-weight: 700;
  color: var(--header-blue-1);
  margin: 10px 0 6px;
}
.msg-assistant-body h1 { font-size: 16px; }
.msg-assistant-body h2 { font-size: 14px; }
.msg-assistant-body h3 { font-size: 13px; }
.msg-assistant-body h4,
.msg-assistant-body h5,
.msg-assistant-body h6 { font-size: 12px; }
.msg-assistant-body ul,
.msg-assistant-body ol { margin: 0 0 8px; padding-left: 22px; }
.msg-assistant-body li { margin: 2px 0; }
.msg-assistant-body blockquote {
  margin: 6px 0 8px;
  padding: 3px 8px;
  background: var(--surface-2);
  color: var(--fg-muted);
  box-shadow: inset 3px 0 0 var(--border-mid), inset 0 0 0 1px var(--border-mid);
}
.msg-assistant-body blockquote > :last-child { margin-bottom: 0; }
.msg-assistant-body hr {
  border: none;
  border-top: 1px solid var(--border-dark);
  border-bottom: 1px solid var(--border-light);
  margin: 8px 0;
}
.msg-assistant-body table {
  border-collapse: collapse;
  background: var(--surface-inset);
  box-shadow: var(--bevel-in-strong);
  font-size: 11px;
  margin: 6px 0 8px;
}
.msg-assistant-body th,
.msg-assistant-body td {
  padding: 2px 6px;
  border-right: 1px solid var(--border-mid);
  border-bottom: 1px solid var(--border-mid);
  text-align: left;
}
.msg-assistant-body thead th {
  background: var(--gradient-toolbar);
  box-shadow: var(--bevel-out);
  font-family: var(--font-bold);
  font-weight: 700;
  padding: 3px 6px;
}
.msg-assistant-body img { max-width: 100%; }
.msg-assistant-actions {
  padding-left: 17px;
  margin-top: 3px;
  display: flex;
  gap: 10px;
  font-size: 10px;
}

/* Error message */
.msg-error { margin-bottom: 14px; }
.msg-error span { overflow-wrap: break-word; min-width: 0; }

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 12px;
  background: var(--fg);
  vertical-align: text-bottom;
  animation: sap-blink 0.8s step-end infinite;
}

/* Rich text: inline code, code blocks */
.rich-code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border-mid);
  padding: 0 3px;
}
.code-block {
  margin: 6px 0;
  background: var(--surface-inset);
  box-shadow: var(--bevel-in-strong);
}
.code-block-head {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gradient-toolbar);
  border-bottom: 1px solid var(--border-mid);
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.code-block-head .sap-link { font-weight: 400; text-transform: none; }
.code-block pre {
  margin: 0;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre;
}
.tok-comment { color: var(--fg-muted); font-style: italic; }
.tok-string { color: var(--status-success); }
.tok-number { color: var(--link-visited); }
.tok-keyword { color: var(--link); font-weight: 700; }

/* ---------- Input row --------------------------------------- */
.input-row {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.draft { flex: 1; padding: 4px 6px; font-size: 12px; }
.input-side {
  display: flex;
  flex-direction: column;
  gap: 3px;
  justify-content: flex-end;
  width: 90px;
}
.search-check { font-size: 10px; justify-content: center; }
.btn-send { justify-content: center; }
.send-hint { font-size: 9px; color: var(--fg-muted); text-align: center; }
.disclaimer {
  font-size: 9px;
  color: var(--fg-muted);
  text-align: center;
  margin-top: 3px;
}

/* ---------- Status bar -------------------------------------- */
.status-icon { flex: none; }
.status-progress { width: 90px; }
.status-progress[hidden] { display: none; }
.status-progress .bar { width: 100%; animation: sap-marquee 0.6s linear infinite; }
.status-clock { font-variant-numeric: tabular-nums; }

/* ---------- Confirm dialog ---------------------------------- */
.confirm-overlay {
  position: fixed;
  left: 0;
  top: 0;
  width: calc(100vw / 1.3333);
  height: calc(100vh / 1.3333);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.confirm-overlay[hidden] { display: none; }
.confirm-dialog { width: 320px; }

/* ---------- HTML preview dialog ----------------------------- */
.preview-dialog { width: min(760px, 92%); }
.preview-body { padding: 8px; }
.preview-frame-wrap {
  background: var(--surface-inset);
  box-shadow: var(--bevel-in-strong);
  padding: 2px;
}
.preview-frame-wrap iframe {
  display: block;
  width: 100%;
  height: min(440px, calc(100vh / 1.3333 - 150px));
  border: 0;
  background: #fff;
}
.confirm-body { display: flex; gap: 8px; align-items: flex-start; }
.confirm-icon { flex: none; }
