/* base styles moved to /styles/base.css */

.chat-modal {
  position: fixed;
  z-index: 10;
  width: min(980px, 96vw);
  min-width: 320px;
  max-width: 96vw;
  height: min(680px, 88vh);
  min-height: 200px;
  max-height: 92vh;
  background: linear-gradient(180deg, #060f22 0%, #040b1b 100%);
  border: 1px solid rgba(73, 154, 240, 0.3);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 10, 40, 0.65), inset 0 1px 0 rgba(122, 176, 255, 0.15);
  display: none;
  overflow: hidden;
}

@media (prefers-color-scheme: light) {
  .chat-modal {
    box-shadow: 0 20px 60px rgba(5, 23, 57, 0.35), inset 0 1px 0 rgba(122, 176, 255, 0.15);
  }
}

.chat-modal.visible {
  display: flex;
  flex-direction: column;
}

.chat-modal.maximized {
  left: 1rem !important;
  top: 1rem !important;
  right: 1rem !important;
  bottom: 1rem !important;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  transform: none !important;
}

.chat-modal.maximized .chat-resize-corner {
  display: none;
}

.chat-titlebar {
  cursor: move;
  background: linear-gradient(180deg, rgba(20, 35, 56, 0.96) 0%, rgba(12, 24, 42, 0.96) 100%);
  border-bottom: 1px solid rgba(87, 140, 208, 0.35);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  font-size: 14px;
  color: #dce8ff;
}

.chat-modal.maximized .chat-titlebar {
  cursor: default;
}

.chat-title-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-brand-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(33, 168, 255, 0.3), rgba(35, 255, 188, 0.2));
  border: 1px solid rgba(78, 189, 255, 0.55);
  color: #9ceeff;
  text-shadow: 0 0 8px rgba(125, 244, 255, 0.65);
}

.chat-title-text {
  font-weight: 600;
  letter-spacing: 0.02em;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.chat-title-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-settings-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(77, 211, 236, 0.8);
  background: radial-gradient(circle at 30% 25%, #3cd8f2 0%, #1ba9c7 38%, #0b5267 100%);
  color: #e6feff;
  box-shadow: inset 0 1px 0 rgba(205, 255, 255, 0.45), 0 0 0 1px rgba(2, 25, 35, 0.65);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}

.chat-settings-btn:hover,
.chat-settings-btn.active {
  filter: brightness(1.08);
  border-color: rgba(112, 242, 255, 0.95);
}

.chat-settings-popup {
  position: absolute;
  top: 62px;
  right: 16px;
  width: min(420px, calc(100% - 32px));
  max-height: min(72vh, 520px);
  overflow: auto;
  border-radius: 14px;
  border: 1px solid rgba(85, 152, 225, 0.38);
  background: linear-gradient(180deg, rgba(10, 17, 35, 0.98) 0%, rgba(5, 10, 24, 0.98) 100%);
  box-shadow: 0 24px 50px rgba(2, 8, 28, 0.78);
  z-index: 25;
}

.chat-settings-popup-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(108, 166, 234, 0.28);
  background: linear-gradient(105deg, rgba(61, 30, 117, 0.78) 0%, rgba(33, 136, 186, 0.78) 100%);
}

.chat-settings-popup-title {
  color: #e9f5ff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.chat-settings-popup-subtitle {
  margin-top: 2px;
  color: rgba(213, 236, 255, 0.88);
  font-size: 12px;
}

.chat-settings-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(147, 204, 255, 0.35);
  background: rgba(13, 29, 50, 0.64);
  color: #dcf0ff;
  cursor: pointer;
}

.chat-settings-close-btn:hover {
  border-color: rgba(177, 226, 255, 0.7);
  background: rgba(23, 46, 77, 0.75);
}

.chat-settings-popup-content {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.chat-settings-field {
  display: grid;
  gap: 6px;
  color: #dcecff;
  font-size: 12px;
}

.chat-settings-field > span {
  font-weight: 600;
  color: #e3f1ff;
}

.chat-settings-hint {
  color: #7dc4df;
  font-size: 11px;
}

.chat-settings-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chat-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: #9fc4f7;
  border: 1px solid rgba(103, 151, 219, 0.35);
  background: rgba(37, 63, 97, 0.28);
}

.chat-status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px color-mix(in srgb, currentColor 70%, transparent);
}

.chat-status-pill-awaiting {
  color: #9fc4f7;
  border-color: rgba(103, 151, 219, 0.4);
  background: rgba(37, 63, 97, 0.28);
}

.chat-status-pill-executing {
  color: #ffad4f;
  border-color: rgba(255, 173, 79, 0.48);
  background: rgba(133, 74, 19, 0.3);
  animation: chat-status-pulse 1.2s ease-in-out infinite;
}

.chat-status-pill-complete {
  color: #52f09a;
  border-color: rgba(82, 240, 154, 0.4);
  background: rgba(41, 120, 77, 0.25);
}

.chat-status-pill-attention {
  color: #ff6c6c;
  border-color: rgba(255, 108, 108, 0.45);
  background: rgba(130, 34, 34, 0.28);
}

.chat-status-pill-alternating {
  animation: chat-status-fade 1.2s ease-in-out infinite;
}

@keyframes chat-status-pulse {
  0%,
  100% {
    opacity: 1;
    filter: brightness(1);
  }
  50% {
    opacity: 0.45;
    filter: brightness(1.15);
  }
}

@keyframes chat-status-fade {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.38;
  }
}

.chat-close-btn,
.chat-maximize-btn {
  background: rgba(17, 37, 64, 0.7);
  border: 1px solid rgba(95, 151, 227, 0.4);
  color: #b8d5ff;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.chat-close-btn:hover,
.chat-maximize-btn:hover {
  border-color: rgba(138, 196, 255, 0.8);
  background: rgba(28, 54, 90, 0.82);
}

.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: radial-gradient(circle at 20% -10%, rgba(40, 89, 178, 0.22), transparent 38%), #02091a;
}

.chat-lock-card {
  margin: 12px 14px 0;
  border: 1px solid rgba(64, 127, 175, 0.42);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(20, 35, 56, 0.95) 0%, rgba(12, 24, 42, 0.94) 100%);
  box-shadow: inset 0 1px 0 rgba(110, 176, 234, 0.14);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.chat-lock-title {
  color: #45e3d2;
  font-size: 14px;
  font-weight: 700;
}

.chat-lock-subtitle {
  color: #d4e4f8;
  font-size: 12px;
  margin-top: 4px;
}

.chat-lock-step {
  display: grid;
  gap: 8px;
}

.chat-lock-question {
  color: #dce9fc;
  font-size: 12px;
}

.chat-lock-mode-buttons {
  display: flex;
  gap: 8px;
}

.chat-lock-mode-btn {
  border: 1px solid rgba(86, 154, 210, 0.45);
  background: rgba(15, 32, 55, 0.82);
  color: #d6e8ff;
  border-radius: 8px;
  font-size: 12px;
  padding: 7px 10px;
  cursor: pointer;
}

.chat-lock-mode-btn.active,
.chat-lock-mode-btn:hover {
  border-color: rgba(111, 219, 229, 0.8);
  color: #8ef8ec;
}

.chat-lock-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chat-lock-field {
  display: grid;
  gap: 6px;
  color: #dce9fc;
  font-size: 12px;
}

.chat-lock-field input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(68, 123, 197, 0.5);
  background: rgba(10, 23, 44, 0.8);
  color: #cfe2ff;
  border-radius: 8px;
  font-size: 12px;
  padding: 7px 9px;
}

.chat-lock-field input::placeholder {
  color: #88a2c7;
}

.chat-lock-error {
  color: #ff8080;
  font-size: 12px;
}

.chat-lock-warning {
  color: #ffd27f;
  font-size: 12px;
}

.chat-lock-sync-message {
  color: #8ef8ec;
  font-size: 12px;
}

.chat-lock-proceed-btn,
.chat-lock-status-actions button {
  width: fit-content;
  border: 1px solid rgba(81, 139, 210, 0.56);
  background: linear-gradient(180deg, rgba(18, 38, 64, 0.96), rgba(10, 26, 46, 0.96));
  color: #84f4e4;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
}

.chat-lock-proceed-btn:disabled,
.chat-lock-status-actions button:disabled,
.chat-send-btn:disabled,
.chat-reset-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-lock-status-bar {
  margin: 10px 14px 0;
  border: 1px solid rgba(80, 153, 215, 0.45);
  border-radius: 10px;
  background: rgba(12, 27, 48, 0.88);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}

.chat-lock-status-title {
  color: #5cecd4;
  font-size: 12px;
  font-weight: 700;
}

.chat-lock-status-details {
  color: #d5e7ff;
  font-size: 11px;
}

.chat-lock-status-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-log {
  flex: 1;
  overflow: auto;
  padding: 18px 20px;
  background: transparent;
  font-size: 13px;
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: rgba(73, 123, 188, 0.65) transparent;
}

.chat-log::-webkit-scrollbar {
  width: 12px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(73, 123, 188, 0.65);
  border-radius: 999px;
}

.chat-log::-webkit-scrollbar-thumb:hover {
  background: rgba(118, 177, 255, 0.9);
}

.chat-msg {
  margin: 8px 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: inherit;
}

.chat-msg[data-role="user"]::before {
  content: none;
}

.chat-msg[data-role="assistant"]::before {
  content: "";
  position: absolute;
  left: -48px;
  top: 6px;
  width: 36px;
  height: 36px;
  opacity: 0.9;
  background: url("/BotIcon.JPG") center / contain no-repeat;
}

.chat-msg[data-role="assistant"] > div:first-child {
  display: inline;
}

.chat-msg[data-role="user"] {
  position: relative;
  opacity: 0.96;
  color: #d5e6ff;
  text-align: left;
  width: fit-content;
  max-width: min(48%, 56ch);
  margin-left: auto;
  margin-right: 56px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(76, 134, 210, 0.42);
  background: linear-gradient(180deg, rgba(15, 34, 61, 0.92) 0%, rgba(8, 22, 44, 0.96) 100%);
  box-shadow: inset 0 1px 0 rgba(118, 174, 245, 0.12);
  overflow-wrap: anywhere;
}

.chat-msg[data-role="user"]::after {
  content: "";
  position: absolute;
  right: -44px;
  top: 6px;
  width: 32px;
  height: 32px;
  opacity: 0.95;
  background: url("/HumanIcon.JPG") center / contain no-repeat;
}

.chat-msg[data-role="user"] > div,
.chat-msg[data-role="user"] {
  display: block;
}

.chat-msg[data-role="assistant"] {
  position: relative;
  margin-left: 56px;
  max-width: min(74ch, 88%);
  color: #9af7b0;
  background: linear-gradient(180deg, rgba(16, 32, 52, 0.88) 0%, rgba(9, 22, 39, 0.94) 100%);
  border: 1px solid rgba(61, 121, 194, 0.38);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: inset 0 1px 0 rgba(114, 170, 243, 0.12);
}

.chat-msg[data-role="assistant"][data-error="true"] {
  color: #ff6c6c;
}

.chat-msg[data-role="debug"] {
  font-size: 11px;
  opacity: 0.92;
  border-left: 2px solid rgba(80, 143, 232, 0.45);
  padding-left: 10px;
  margin-left: 4px;
}

.chat-msg[data-role="debug"][data-tone="muted"] {
  color: #6eeeff;
}

.chat-msg[data-role="debug"][data-tone="dark"] {
  color: #6eeeff;
}

.chat-msg[data-role="debug"] .meta-event {
  color: #6eeeff;
}

.chat-msg[data-role="debug"] .meta-event.meta-event-message {
  color: #9af7b0;
}

.chat-msg[data-role="debug"] .meta-event.meta-event-completion,
.chat-msg[data-role="debug"] .meta-event.meta-event-system,
.chat-msg[data-role="debug"] .meta-event.meta-event-tool-call,
.chat-msg[data-role="debug"] .meta-event.meta-event-tool-result {
  color: #2f855a;
}

.chat-msg[data-role="debug"] .meta-event.meta-event-error,
.chat-msg[data-role="debug"] .meta-event.meta-event-response.meta-event-error,
.chat-msg[data-role="debug"] .meta-event.meta-event-stderr,
.chat-msg[data-role="debug"] .meta-event.meta-event-stderr_raw,
.chat-msg[data-role="debug"] .meta-event.meta-event-exit {
  color: #c53030;
}

.chat-msg[data-role="debug"] .meta-label {
  font-weight: 600;
  margin-right: 6px;
}

.chat-msg[data-role="debug"] .meta-kv {
  margin-right: 8px;
}

.chat-msg[data-role="debug"] .meta-status {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 10px;
  border: 1px solid currentColor;
  font-size: 10px;
  line-height: 1.5;
}

.chat-msg[data-role="debug"] .meta-status.in-progress {
  color: #b7791f;
  border-color: #b7791f;
  background: rgba(183, 121, 31, 0.12);
  opacity: 1;
}

.chat-msg[data-role="debug"] .meta-status.complete {
  color: #2f855a;
  border-color: #2f855a;
  background: rgba(47, 133, 90, 0.12);
  opacity: 1;
}

.chat-msg[data-role="debug"] .meta-truncate {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.chat-msg .md-h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 8px 0 4px;
}

.chat-msg .md-h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 6px 0 4px;
}

.chat-msg .md-h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 4px 0 2px;
}

.chat-msg .md-li {
  margin: 2px 0;
  padding-left: 8px;
}

.chat-msg .md-code {
  background: rgba(31, 58, 98, 0.45);
  padding: 8px;
  margin: 4px 0;
  border-radius: 4px;
  overflow-x: auto;
}

.chat-msg .md-inline-code {
  background: rgba(31, 58, 98, 0.45);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 12px;
}

.chat-input {
  padding: 8px 12px 10px;
  background: linear-gradient(180deg, rgba(8, 18, 34, 0.96) 0%, rgba(6, 14, 27, 0.98) 100%);
  border-top: 1px solid rgba(75, 140, 228, 0.26);
  display: grid;
  gap: 8px;
}

.chat-repo-input,
.chat-model-select,
.chat-autonomy-select,
.chat-reasoning-select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(68, 123, 197, 0.5);
  background: rgba(10, 23, 44, 0.8);
  color: #cfe2ff;
  border-radius: 8px;
  font-size: 12px;
  padding: 6px 8px;
}

.chat-level-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.chat-repo-input::placeholder {
  color: #8ca7ca;
}

.chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.chat-secondary-box {
  border: 1px solid rgba(64, 125, 210, 0.42);
  background: rgba(6, 17, 34, 0.9);
  border-radius: 10px;
  overflow: hidden;
}

.chat-secondary-toggle {
  width: 100%;
  border: 0;
  background: rgba(17, 37, 64, 0.72);
  color: #cfe2ff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.chat-secondary-toggle:hover {
  background: rgba(24, 49, 82, 0.82);
}

.chat-secondary-title {
  font-weight: 600;
}

.chat-secondary-chevron {
  color: #9ec6ff;
}

.chat-secondary-content {
  max-height: 130px;
  overflow: auto;
  padding: 10px;
  border-top: 1px solid rgba(64, 125, 210, 0.35);
}

.chat-secondary-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #bfe9ff;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.chat-secondary-box.collapsed .chat-secondary-content {
  display: none;
}

.chat-input textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: rgba(5, 16, 33, 0.95);
  color: #d8eaff;
  border: 1px solid rgba(64, 125, 210, 0.56);
  border-radius: 8px;
  padding: 9px 11px;
  resize: none;
  overflow-y: hidden;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.45;
}

.chat-input textarea:focus {
  outline: none;
  border-color: rgba(106, 173, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(56, 137, 241, 0.25);
}

.chat-send-btn,
.chat-reset-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(81, 139, 210, 0.56);
  background: linear-gradient(180deg, rgba(39, 103, 176, 0.9), rgba(21, 62, 112, 0.95));
  color: #dff1ff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.chat-send-btn:hover,
.chat-reset-btn:hover {
  filter: brightness(1.08);
  border-color: rgba(134, 192, 255, 0.9);
}

.spinner-icon {
  display: inline-block;
  width: 1em;
  color: #ffffff;
}

.chat-msg[data-role="loading"] {
  font-size: 11px;
}

.spinner-status {
  color: #ffffff;
  font-size: 11px;
}

.chat-resize-corner {
  position: absolute;
  right: 0;
  bottom: 0;
  cursor: se-resize;
  font-size: 12px;
  color: #5f8fcf;
  line-height: 1;
  padding: 0 6px 6px 0;
  user-select: none;
}

.chat-open-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: linear-gradient(180deg, rgba(21, 49, 86, 0.96), rgba(14, 36, 66, 0.98));
  color: #dce8ff;
  border: 1px solid rgba(95, 156, 228, 0.52);
  box-shadow: 0 12px 26px rgba(0, 9, 27, 0.5);
  padding: 10px 14px;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: 10px;
}

.chat-open-btn:hover {
  filter: brightness(1.08);
}

@media (max-width: 640px) {
  .chat-modal {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    left: 0 !important;
    top: 0 !important;
    transform: none !important;
  }

  .chat-titlebar {
    padding: 12px;
  }

  .chat-status-pill {
    display: none;
  }

  .chat-settings-popup {
    right: 10px;
    left: 10px;
    width: auto;
    top: 58px;
    max-height: 62vh;
  }

  .chat-settings-field-grid {
    grid-template-columns: 1fr;
  }

  .chat-lock-grid {
    grid-template-columns: 1fr;
  }

  .chat-msg[data-role="user"],
  .chat-msg[data-role="debug"] .meta-event.meta-event-message {
    max-width: 88%;
  }

  .chat-msg[data-role="assistant"] {
    margin-left: 46px;
  }

  .chat-msg[data-role="assistant"]::before {
    left: -42px;
    width: 32px;
    height: 32px;
  }

  .chat-msg[data-role="user"] {
    margin-right: 46px;
  }

  .chat-msg[data-role="user"]::after {
    right: -38px;
    width: 28px;
    height: 28px;
  }
}

/* link color in base.css */
