.programming-app-page {
  --bg: #f7f8fb;
  --text: #111827;
  --muted: #687385;
  --border: #dce2ea;
  --shadow: 0 18px 55px rgba(15, 23, 42, 0.12);
  --primary: #0b7cff;
  --primary-dark: #075fc4;
  --panel: #ffffff;
  --panel-soft: #f2f4f7;
  --success: #10a37f;
  --danger: #ef4444;
  --warning: #f59e0b;
  background: var(--bg);
  color: var(--text);
  cursor: auto;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden !important;
}

.programming-app-page::before,
.programming-app-page::after,
.programming-app-page .custom-cursor {
  display: none;
}

.programming-app-page a,
.programming-app-page button,
.programming-app-page input,
.programming-app-page textarea {
  cursor: pointer;
  font-family: inherit;
}

.programming-app-page input,
.programming-app-page textarea {
  cursor: text;
}

.programming-app-page button {
  border: 0;
}

.programming-app-page button:focus-visible,
.programming-app-page input:focus-visible,
.programming-app-page textarea:focus-visible {
  outline: 3px solid rgba(11, 124, 255, 0.24);
  outline-offset: 3px;
}

.programming-app-page header {
  display: none;
}

.programming-shell {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  padding-top: 0;
  overflow: hidden;
}

.chat-app {
  width: 100%;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  margin: 0;
  padding: 0 !important;
  background: var(--bg);
  overflow: hidden;
}

.chat-sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  min-height: 0;
  padding: 14px;
  border-right: 1px solid var(--border);
  background: #f3f5f8;
  overflow: hidden;
}

.sidebar-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.sidebar-action,
.sidebar-icon,
.topbar-icon,
.send-orb,
.tool-chip,
.attach-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.sidebar-action {
  min-height: 42px;
  justify-content: flex-start;
  gap: 10px;
  border-radius: 12px;
  padding: 0 14px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(11, 124, 255, 0.2);
}

.sidebar-action:hover {
  background: var(--primary-dark);
}

.sidebar-icon,
.topbar-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.76);
}

.sidebar-icon:hover,
.topbar-icon:hover {
  background: #e8edf4;
}

.chat-search {
  min-height: 42px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
}

.chat-search i {
  justify-self: center;
}

.chat-search input {
  width: 100%;
  height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}

.chat-search input::placeholder {
  color: #8b95a3;
}

.brain-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  margin-bottom: 16px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.2;
}

.brain-status strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.brain-status-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.14);
}

.brain-status[data-state="ready"] .brain-status-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(16, 163, 127, 0.14);
}

.brain-status[data-state="offline"] .brain-status-dot,
.brain-status[data-state="error"] .brain-status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.14);
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.history-heading button {
  background: transparent;
  color: var(--primary);
  font-weight: 800;
}

.history-heading button:hover {
  color: var(--primary-dark);
}

.chat-history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.history-item {
  width: 100%;
  min-height: 50px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.history-item:hover,
.history-item.active {
  border-color: var(--border);
  background: #fff;
}

.history-copy {
  min-width: 0;
}

.history-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.94rem;
  font-weight: 800;
}

.history-date {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.delete-chat-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
}

.delete-chat-btn:hover {
  background: #fff1f2;
  color: var(--danger);
}

.empty-history {
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.56);
  font-size: 0.92rem;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(17, 24, 39, 0.34);
}

.chat-main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  background: var(--panel);
  overflow: hidden;
}

.chat-topbar {
  position: relative;
  z-index: 7;
  flex: 0 0 58px;
  display: none;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px clamp(12px, 2vw, 22px);
  border-bottom: 1px solid rgba(220, 226, 234, 0.72);
  background: rgba(255, 255, 255, 0.96);
}

.chat-title {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
}

.chat-title strong,
.chat-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title strong {
  font-size: 0.96rem;
  line-height: 1.25;
}

.chat-title span {
  color: var(--muted);
  font-size: 0.84rem;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px clamp(16px, 4vw, 64px) 8px;
  background: var(--panel);
}

.empty-chat-state {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-chat-state h1 {
  max-width: 920px;
  margin: 0;
  color: var(--text);
  font-size: clamp(1.6rem, 2.7vw, 2.55rem);
  font-weight: 500;
  line-height: 1.14;
  letter-spacing: 0;
}

.chat-main.is-empty .chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-top: 8px;
  padding-bottom: 6px;
}

.chat-main.is-empty .empty-chat-state {
  min-height: 100%;
}

.chat-main.is-empty .chat-composer {
  margin-top: 0;
  margin-bottom: 0;
}

.message-row {
  display: flex;
  max-width: 900px;
  margin: 0 auto 16px;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(82%, 780px);
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  line-height: 1.58;
  overflow-wrap: anywhere;
}

.message-row.user .message-bubble {
  border-color: #e4e7ec;
  border-bottom-right-radius: 7px;
  background: #f3f4f6;
}

.message-row.assistant .message-bubble {
  border-bottom-left-radius: 7px;
}

.message-bubble.loading {
  color: var(--muted);
}

.message-bubble.loading::after {
  content: "";
  display: inline-block;
  width: 1.1em;
  text-align: left;
  animation: thinkingDots 1.1s infinite steps(4, end);
}

.message-bubble a {
  color: var(--primary);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.message-sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.86rem;
}

.code-block {
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid #d8dee8;
  border-radius: 14px;
  background: #0f172a;
  color: #e5edf8;
}

.code-header {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  font-size: 0.8rem;
  font-weight: 800;
}

.copy-code-btn {
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #e5edf8;
  font-size: 0.78rem;
  font-weight: 800;
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.code-block pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
}

.code-block code {
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.55;
}

.chat-composer {
  position: relative;
  z-index: 8;
  flex: 0 0 auto;
  width: min(calc(100% - 32px), 700px);
  margin: 0 auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.composer-card {
  position: relative;
  width: 100%;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.09);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer-card:focus-within {
  border-color: rgba(11, 124, 255, 0.48);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.1), 0 0 0 3px rgba(11, 124, 255, 0.08);
}

.send-orb {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-size: 0.92rem;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.22);
}

.send-orb:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.26);
}

.send-orb:active,
.tool-chip:active,
.attach-chip:active {
  transform: scale(0.97);
}

.send-orb[disabled],
#coachInput[disabled] {
  opacity: 0.64;
}

#coachInput {
  width: 100%;
  max-height: 220px;
  min-height: 52px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 1px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.42;
}

#coachInput::placeholder {
  color: #8a93a1;
}

.composer-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}

.composer-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.tool-chip,
.attach-chip {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #d8dee8;
  border-radius: 999px;
  padding: 0 11px;
  background: #f8fafc;
  color: #536071;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.tool-chip:hover,
.attach-chip:hover {
  border-color: #c9d2df;
  color: var(--text);
  transform: translateY(-1px);
}

.tool-chip.is-active {
  border-color: rgba(37, 99, 235, 0.3);
  background: #eef5ff;
  color: #1d4ed8;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.08);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

.attachment-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 0 8px 0 11px;
  background: #f8fafc;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 750;
}

.attachment-pill span {
  max-width: min(250px, 58vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-attachment {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: transparent;
  color: #64748b;
}

.remove-attachment:hover {
  background: #e2e8f0;
  color: #0f172a;
}

@keyframes thinkingDots {
  0% {
    content: "";
  }

  25% {
    content: ".";
  }

  50% {
    content: "..";
  }

  75%,
  100% {
    content: "...";
  }
}

@media (min-width: 901px) {
  #closeSidebarBtn,
  #openSidebarBtn,
  .sidebar-backdrop {
    display: none;
  }
}

@media (max-width: 900px) {
  .chat-app {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 340px);
    transform: translateX(-104%);
    transition: transform 0.22s ease;
    box-shadow: 18px 0 36px rgba(15, 23, 42, 0.12);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  .chat-topbar {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
  }
}

@media (max-width: 700px) {
  .chat-title {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .chat-messages {
    padding: 18px 12px 6px;
  }

  .empty-chat-state h1 {
    font-size: clamp(1.45rem, 7vw, 2.1rem);
  }

  .message-bubble {
    max-width: 91%;
  }

  .chat-composer {
    width: calc(100% - 20px);
    margin-bottom: 0;
  }

  .composer-card {
    min-height: 116px;
    border-radius: 22px;
    padding: 12px;
  }

  .composer-toolbar {
    align-items: flex-end;
    gap: 10px;
  }

  #coachInput {
    min-height: 52px;
    padding-top: 0;
  }

  .tool-chip {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.76rem;
  }
}

@media (max-width: 430px) {
  .composer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .send-orb {
    align-self: flex-end;
  }

  .send-orb {
    width: 38px;
    height: 38px;
  }
}
