* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #0c0d10;
  color: #e7e7ea;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #15171c;
  border-right: 1px solid #23262e;
  padding: 18px 16px;
  overflow-y: auto;
}

#sidebar header {
  padding-bottom: 12px;
  border-bottom: 1px solid #23262e;
  margin-bottom: 14px;
}

#sidebar h1 {
  margin: 0 0 4px;
  font-size: 17px;
  letter-spacing: 0.2px;
}

#sidebar .muted {
  color: #8b8e96;
  font-size: 12px;
  margin: 0;
}

#sidebar nav a {
  display: block;
  padding: 8px 10px;
  color: #cfd2d8;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
}
#sidebar nav a:hover { background: #1d2027; color: #fff; }

#sidebar .actions {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #23262e;
}
#sidebar .actions h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6f7480;
  margin: 0 0 10px;
}
#sidebar .btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: #d97757;
  color: #fff;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
}
#sidebar .btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  flex-shrink: 0;
}

/* ---------- Power Nap row: button + help tooltip ---------- */
.power-nap-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.power-nap-btn {
  flex: 1;
  min-width: 0;
}
/* Standalone face slot to the LEFT of the button — just the icon, no chrome. */
.power-nap-face-slot {
  flex-shrink: 0;
  width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #cfd2d8;
  border: 0;
  cursor: help;
  position: relative;
  outline: none;
  transition: color 0.12s ease;
}
.power-nap-face-slot:hover,
.power-nap-face-slot:focus-visible {
  color: #fff;
}
.power-nap-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}
.power-nap-face svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.6;
  transition: opacity 0.2s ease;
}
.power-nap-help {
  flex-shrink: 0;
  width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #8b8e96;
  border: 0;
  cursor: help;
  position: relative;
  transition: color 0.12s ease;
}
.power-nap-help svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}
.power-nap-help:hover { color: #fff; }

/* Tooltip: hidden by default, shown on hover/focus of the help button. */
.power-nap-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  right: -8px;
  width: 240px;
  padding: 10px 12px;
  background: #1a1d24;
  color: #cfd2d8;
  border: 1px solid #2a3344;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
  font-style: normal;
  font-weight: normal;
  letter-spacing: normal;
  text-transform: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  pointer-events: none;
  z-index: 10;
}
.power-nap-tooltip strong { color: #fff; font-weight: 600; }
.power-nap-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 16px;
  border: 6px solid transparent;
  border-top-color: #1a1d24;
}
/* Left-anchored variant for the face tooltip (pointer at left edge). */
.power-nap-tooltip-left {
  right: auto;
  left: -8px;
  width: 200px;
}
.power-nap-tooltip-left::after {
  right: auto;
  left: 16px;
}
.power-nap-help:hover .power-nap-tooltip,
.power-nap-help:focus .power-nap-tooltip,
.power-nap-help:focus-visible .power-nap-tooltip,
.power-nap-face-slot:hover .power-nap-tooltip,
.power-nap-face-slot:focus .power-nap-tooltip,
.power-nap-face-slot:focus-visible .power-nap-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
#sidebar .btn:hover { background: #e08a6e; }
#sidebar .btn:active { background: #c56849; }
#sidebar .hint {
  font-size: 11px;
  color: #6f7480;
  margin: 8px 2px 0;
  line-height: 1.45;
}
#sidebar .hint code {
  background: #1d2027;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
}

#sidebar .placeholder {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #23262e;
  font-size: 12px;
  color: #9aa0a8;
  line-height: 1.5;
}
#sidebar .placeholder h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6f7480;
  margin: 0 0 8px;
}
#sidebar .placeholder code {
  background: #1d2027;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

/* ---------- Model picker ---------- */
.model-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #23262e;
}
.model-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6f7480;
  margin: 0 0 8px;
}
#ultra-model-picker {
  position: relative;
}
#ultra-model-picker > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #15171c;
  border: 1px solid #23262e;
  border-radius: 6px;
  color: #cfd2d8;
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: border-color 0.12s ease;
}
#ultra-model-picker > summary::-webkit-details-marker { display: none; }
#ultra-model-picker > summary:hover { border-color: #2a3344; }
#ultra-model-picker[open] > summary { border-color: #d97757; }
.model-current {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: #6f7480;
  transition: transform 0.15s ease;
}
#ultra-model-picker[open] .chevron { transform: rotate(180deg); }
.model-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  background: #15171c;
  border: 1px solid #23262e;
  border-radius: 6px;
}
.model-list::-webkit-scrollbar { width: 8px; }
.model-list::-webkit-scrollbar-thumb { background: #2a2d35; border-radius: 4px; }
.model-option {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: #cfd2d8;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s ease;
}
.model-option:hover { background: #1d2027; color: #fff; }
.model-option.is-current {
  background: rgba(217, 119, 87, 0.14);
  color: #fff;
  border-left: 2px solid #d97757;
  padding-left: 8px;
}

/* ---------- Conversations section ---------- */
#sidebar {
  display: flex;
  flex-direction: column;
}
.conversations {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #23262e;
  display: flex;
  flex-direction: column;
}
.conversations .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
}
.conversations h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6f7480;
  margin: 0;
}
.icon-btn {
  background: transparent;
  border: 0;
  color: #6f7480;
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.12s ease;
}
.icon-btn:hover { color: #fff; }
.icon-btn svg { width: 14px; height: 14px; stroke-width: 2; }
.icon-btn.spinning svg { animation: ultra-spin 0.8s linear infinite; }
@keyframes ultra-spin { to { transform: rotate(360deg); } }

.ultra-sessions {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  /* ~4 items visible (~36px each), then internal scroll for the rest. */
  max-height: 148px;
}
.ultra-sessions::-webkit-scrollbar { width: 8px; }
.ultra-sessions::-webkit-scrollbar-thumb {
  background: #2a2d35;
  border-radius: 4px;
}
.ultra-session {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: #cfd2d8;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.35;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s ease;
}
.ultra-session:hover { background: #1d2027; color: #fff; }
.ultra-session.is-current {
  background: rgba(217, 119, 87, 0.14);
  color: #fff;
  border-left: 2px solid #d97757;
  padding-left: 8px;
}
#ultra-sessions-empty {
  margin: 8px 2px 0;
}
.ultra-sessions:not(:empty) + #ultra-sessions-empty { display: none; }

/* ---------- Footer ---------- */
.sidebar-footer {
  margin-top: auto;       /* push to bottom of the sidebar column */
  padding-top: 12px;
  border-top: 1px solid #23262e;
}
.footer-links {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.footer-links a {
  color: #8b8e96;
  text-decoration: none;
}
.footer-links a:hover { color: #fff; }
.dot-sep { color: #4a4e57; }
.sidebar-footer .muted { margin: 6px 0 0; font-size: 11px; }

/* ---------- Ultra chat panel (main area) ---------- */
#ultra-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;          /* allow flex item to shrink */
  background: #0c0d10;
}

#ultra-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px clamp(20px, 6vw, 80px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Message bubbles ---------- */
.ultra-msg {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  max-width: 760px;
  width: 100%;
  align-self: flex-start;
}
.ultra-msg-you {
  align-self: flex-end;
  grid-template-columns: 1fr 32px;  /* avatar on the right */
}

.ultra-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  color: #fff;
  user-select: none;
}
.ultra-avatar svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.75;
}
.ultra-msg-assistant .ultra-avatar {
  background: linear-gradient(135deg, #d97757 0%, #a85539 100%);
  grid-column: 1;
  grid-row: 1;
}
.ultra-msg-you .ultra-avatar {
  background: linear-gradient(135deg, #4a8df5 0%, #2563d0 100%);
  grid-column: 2;
  grid-row: 1;
}

.ultra-msg-bubble {
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.55;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  min-width: 0;          /* allow shrinking inside grid */
}
.ultra-msg-assistant .ultra-msg-bubble {
  background: #1a1d24;
  border: 1px solid #23262e;
  border-left: 3px solid #d97757;
  grid-column: 2;
  grid-row: 1;
}
.ultra-msg-you .ultra-msg-bubble {
  background: #1d2a3f;
  border: 1px solid #2a3a55;
  border-right: 3px solid #4a8df5;
  grid-column: 1;
  grid-row: 1;
  text-align: left;
  white-space: pre-wrap;   /* user-typed newlines preserved */
}

.ultra-msg-role {
  display: none;  /* avatars replace the role label */
}

/* ---------- Markdown body styling ---------- */
.ultra-msg-bubble > *:first-child { margin-top: 0; }
.ultra-msg-bubble > *:last-child  { margin-bottom: 0; }
.ultra-msg-bubble p { margin: 0 0 10px; }
.ultra-msg-bubble p:last-child { margin-bottom: 0; }
.ultra-msg-bubble ul, .ultra-msg-bubble ol {
  margin: 8px 0;
  padding-left: 22px;
}
.ultra-msg-bubble li { margin: 4px 0; }
.ultra-msg-bubble li > p { margin: 0; }
.ultra-msg-bubble h1, .ultra-msg-bubble h2, .ultra-msg-bubble h3,
.ultra-msg-bubble h4, .ultra-msg-bubble h5, .ultra-msg-bubble h6 {
  margin: 14px 0 6px;
  font-weight: 600;
  line-height: 1.3;
}
.ultra-msg-bubble h1 { font-size: 18px; }
.ultra-msg-bubble h2 { font-size: 16px; }
.ultra-msg-bubble h3 { font-size: 15px; }
.ultra-msg-bubble code {
  background: #0c0d10;
  border: 1px solid #2a2d35;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.ultra-msg-bubble pre {
  background: #0c0d10;
  border: 1px solid #23262e;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.45;
  margin: 8px 0;
}
.ultra-msg-bubble pre code {
  background: transparent;
  border: 0;
  padding: 0;
}
.ultra-msg-bubble a {
  color: #6ea8ff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ultra-msg-bubble a:hover { color: #9bc1ff; }
.ultra-msg-bubble blockquote {
  border-left: 3px solid #3a3d44;
  margin: 8px 0;
  padding: 2px 0 2px 12px;
  color: #b5b8c0;
}
.ultra-msg-bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.ultra-msg-bubble th, .ultra-msg-bubble td {
  border: 1px solid #2a2d35;
  padding: 4px 8px;
  text-align: left;
}
.ultra-msg-bubble th { background: #1a1d24; }
.ultra-msg-bubble img {
  max-width: 100%;
  border-radius: 6px;
  margin: 6px 0;
}
.ultra-msg-bubble hr {
  border: 0;
  border-top: 1px solid #2a2d35;
  margin: 12px 0;
}
.ultra-msg-system {
  align-self: center;
  grid-template-columns: 1fr;  /* no avatar */
  max-width: none;
  text-align: center;
}
.ultra-msg-system .ultra-avatar { display: none; }
.ultra-msg-system .ultra-msg-bubble {
  background: transparent;
  border: 0;
  border-left: 0;
  color: #6f7480;
  font-size: 12px;
  font-style: italic;
  padding: 4px 8px;
  grid-column: 1;
}

/* ---------- Thinking indicator ---------- */
#ultra-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: flex-start;
  max-width: 760px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #15171c;
  border: 1px solid #23262e;
  color: #8b8e96;
  font-size: 13px;
  font-style: italic;
}
.ultra-dots {
  display: inline-flex;
  gap: 4px;
}
.ultra-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d97757;
  animation: ultra-blink 1.2s infinite ease-in-out both;
}
.ultra-dots span:nth-child(1) { animation-delay: -0.32s; }
.ultra-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes ultra-blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40%           { opacity: 1;    transform: scale(1.0);  }
}

#ultra-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px clamp(20px, 6vw, 80px) 20px;
  border-top: 1px solid #23262e;
  background: #0c0d10;
}
#ultra-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#ultra-attachments:empty { display: none; }
.ultra-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1a1d24;
  border: 1px solid #2a3344;
  border-radius: 999px;
  padding: 4px 10px 4px 12px;
  font-size: 12px;
  color: #cfd2d8;
  max-width: 220px;
}
.ultra-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ultra-chip-size {
  color: #6f7480;
  font-size: 11px;
}
.ultra-chip-remove {
  background: transparent;
  color: #8b8e96;
  border: 0;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}
.ultra-chip-remove:hover { color: #fff; }

#ultra-form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
#ultra-attach {
  align-self: flex-end;
  width: 44px;
  height: 56px;
  background: transparent;
  border: 1px solid #23262e;
  border-radius: 8px;
  color: #8b8e96;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
}
#ultra-attach:hover {
  background: #15171c;
  color: #fff;
  border-color: #2a3344;
}
#ultra-input {
  flex: 1;
  min-height: 56px;
  max-height: 240px;
  padding: 12px 14px;
  background: #15171c;
  border: 1px solid #23262e;
  border-radius: 8px;
  color: #e7e7ea;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
}
#ultra-input:focus {
  outline: none;
  border-color: #d97757;
}
#ultra-send {
  align-self: flex-end;
  padding: 0 18px;
  height: 56px;
  background: #d97757;
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
}
#ultra-send:hover { background: #e08a6e; }
#ultra-send:disabled { background: #3a3d44; cursor: not-allowed; }

/* ---------- Raw mode: full-screen OpenClaw escape hatch ---------- */
body.raw-mode #layout { display: none; }
body.raw-mode #openclaw {
  position: fixed !important;
  inset: 0 !important;
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 1 !important;
  border: 0 !important;
}
.raw-back {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10000;
  background: #15171c;
  color: #fff;
  border: 1px solid #d97757;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: background 0.12s ease;
}
.raw-back:hover { background: #d97757; }

/* ---------- Hidden OpenClaw engine ---------- *
 * Keep iframe at a normal desktop size so the SPA doesn't hit a
 * mobile breakpoint and skip rendering the chat textarea (we need
 * that textarea to puppet). Move the whole frame off-screen instead. */
#openclaw {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1280px;
  height: 800px;
  border: 0;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}
