/* ChatGPT-ish light UI + markdown styling */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: #f7f7f8;
  color: #0f172a;
  overflow: hidden;
}

.app-layout {
  width: min(1240px, calc(100% - 48px));
  height: min(calc(100vh - 48px), 860px);
  height: min(calc(100dvh - 48px), 860px);
  margin: 24px auto;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
}

.disclaimer-panel {
  background: rgba(156, 163, 175, 0.22);
  border: 1px solid rgba(107, 114, 128, 0.28);
  border-radius: 16px;
  padding: 16px;
  overflow-y: auto;
  backdrop-filter: blur(2px);
}

.disclaimer-toggle {
  display: none;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(107, 114, 128, 0.35);
  background: rgba(107, 114, 128, 0.08);
  color: #1f2937;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 8px 10px;
  margin-bottom: 10px;
  cursor: pointer;
}

.disclaimer-panel h2 {
  margin: 0 0 10px 0;
  font-size: 1.05rem;
  color: #1f2937;
}

.disclaimer-panel p {
  margin: 0 0 10px 0;
  font-size: 0.93rem;
  line-height: 1.45;
  color: #374151;
}

.disclaimer-panel .disclaimer-warning {
  color: #b91c1c;
  font-weight: 600;
}

.disclaimer-panel a {
  color: #0f3b66;
}

.disclaimer-panel a:hover {
  color: #0b2f52;
}

.contact-block h2 {
  margin-bottom: 6px;
}

.contact-block p {
  margin-bottom: 4px;
  line-height: 1.25;
}

.chat-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

header {
  position: relative;
  padding: 16px 18px;
  border-bottom: 1px solid #e5e7eb;
  text-align: center;
  background: #ffffff;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
  color: #111827;
  font-weight: 650;
}

.header-actions {
  position: absolute;
  top: 12px;
  right: 14px;
}

.end-chat-btn {
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.84rem;
  cursor: pointer;
}

.end-chat-btn:hover {
  background: #f9fafb;
}

.model-status {
  margin-top: 8px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #4b5563;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 3px 10px;
  background: #f9fafb;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9ca3af;
  display: inline-block;
}

.model-status.is-working {
  color: #1f2937;
  border-color: #c7d2fe;
  background: #eef2ff;
}

.model-status.is-working .status-dot {
  background: #4f46e5;
  animation: statusPulse 1s ease-in-out infinite;
}

.model-status.is-queued {
  color: #1e3a8a;
  border-color: #bfdbfe;
  background: #eff6ff;
}

.model-status.is-queued .status-dot {
  background: #2563eb;
  animation: statusPulse 1.1s ease-in-out infinite;
}

.model-status.is-degraded {
  color: #92400e;
  border-color: #fcd34d;
  background: #fffbeb;
}

.model-status.is-degraded .status-dot {
  background: #f59e0b;
  animation: statusPulse 1.2s ease-in-out infinite;
}

.model-status.is-error {
  color: #991b1b;
  border-color: #fecaca;
  background: #fef2f2;
}

.model-status.is-error .status-dot {
  background: #dc2626;
}

@keyframes statusPulse {
  0% { opacity: 0.3; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0.3; transform: scale(0.95); }
}

.conversation {
  flex: 1;
  padding: 18px 18px 10px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #ffffff;
}

.bubble {
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.98rem;
  line-height: 1.45;
  max-width: 78%;
  word-wrap: break-word;
  box-shadow: none;
}

.bubble.user {
  align-self: flex-end;
  background: #dcfce7;
  color: #052e16;
}

.bubble.assistant {
  align-self: flex-start;
  background: #ffffff;
  color: #111827;
  border: 1px solid #e5e7eb;
}

.msg-label {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.msg-time {
  font-size: 0.72rem;
  opacity: 0.8;
  white-space: nowrap;
}

.feedback-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.feedback-label {
  font-size: 0.78rem;
  color: #4b5563;
}

.feedback-btn {
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  border-radius: 8px;
  padding: 4px 8px;
  line-height: 1;
  cursor: pointer;
}

.feedback-btn:hover {
  background: #f3f4f6;
}

.feedback-btn:disabled {
  cursor: default;
  opacity: 0.75;
}

.feedback-btn.is-selected {
  border-color: #0f766e;
  background: #e6fffb;
}

.feedback-status {
  font-size: 0.78rem;
  color: #065f46;
}

.msg-text {
  white-space: normal; /* markdown renderer controls spacing */
}

/* Input bar */
form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  background: #ffffff;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 118px;
}

form textarea {
  flex: 1;
  border: 1px solid #e5e7eb;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  border-radius: 12px;
  background: #f9fafb;
  resize: none;
  min-height: 48px;
  max-height: 180px;
  line-height: 1.35;
  font-family: inherit;
}

form textarea:focus {
  background: #ffffff;
  border-color: #cbd5e1;
}

form button {
  border: 1px solid #0f766e;
  background: #0f766e;
  color: #ffffff;
  cursor: pointer;
  border-radius: 12px;
  padding: 0 16px;
  font-size: 1rem;
  height: 48px;
  transition: transform 0.05s ease, background 0.15s ease;
}

form button:hover {
  background: #0b6a63;
}

form button:active {
  transform: translateY(1px);
}

form button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.input-actions .end-chat-btn {
  height: 36px;
  border-color: #dc2626;
  background: #fef2f2;
  color: #991b1b;
  font-size: 0.84rem;
  padding: 0 10px;
  font-weight: 700;
}

.input-actions .end-chat-btn:hover {
  background: #fee2e2;
}

.prompt-warning {
  margin: 0;
  font-size: 0.6rem;
  line-height: 1.25;
  color: #b91c1c;
  font-weight: 700;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 8px 10px;
}

.prompt-deletion-code {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.2;
  color: #6b7280;
  padding: 0 2px;
}

.inline-download-code-btn {
  margin-left: 6px;
  vertical-align: baseline;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #374151;
  border-radius: 6px;
  font-size: 0.62rem;
  line-height: 1;
  padding: 1px 4px;
  cursor: pointer;
  height: auto;
  min-height: 0;
  display: inline-block;
}

.inline-download-code-btn:hover {
  background: #f9fafb;
}

#debrief-download-code.modal-secondary-btn {
  font-size: 0.82rem;
  padding: 5px 9px;
}

/* Logo outside chat window */
.ddc-logo-outside {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 170px;
  height: auto;
  opacity: 0.95;
  pointer-events: none;
  z-index: 9999;
}

.app-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12000;
  padding: 16px;
  overflow-y: auto;
}

.app-modal[hidden] {
  display: none !important;
}

.app-modal-card {
  width: min(560px, 100%);
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  padding: 18px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}

.app-modal-card h2 {
  margin: 0 0 10px 0;
  font-size: 1.15rem;
  color: #111827;
}

.app-modal-card p {
  margin: 0 0 10px 0;
  font-size: 0.96rem;
  line-height: 1.45;
  color: #374151;
}

.gdpr-more {
  margin: 8px 0 10px 0;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f9fafb;
}

.gdpr-more summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: #1f2937;
}

.gdpr-more[open] summary {
  margin-bottom: 8px;
}

.gdpr-more p {
  margin: 0 0 8px 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.gdpr-more ol {
  margin: 0 0 8px 18px;
  padding-left: 16px;
  font-size: 0.84rem;
  line-height: 1.3;
}

.gdpr-more li {
  font-size: 0.84rem;
  line-height: 1.3;
  margin: 0 0 4px 0;
}

.gdpr-more ol li,
.gdpr-more ol li strong {
  font-size: 0.84rem;
  line-height: 1.3;
}

.app-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.modal-primary-btn,
.modal-secondary-btn,
.modal-danger-btn {
  border-radius: 10px;
  font-size: 0.92rem;
  padding: 8px 12px;
  cursor: pointer;
}

.modal-primary-btn {
  border: 1px solid #0f766e;
  background: #0f766e;
  color: #ffffff;
}

.modal-primary-btn:hover {
  background: #0b6a63;
}

.modal-primary-btn:disabled {
  border-color: #9ca3af;
  background: #d1d5db;
  color: #6b7280;
  cursor: not-allowed;
}

.modal-secondary-btn {
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
}

.modal-secondary-btn:hover {
  background: #f9fafb;
}

.modal-danger-btn {
  border: 1px solid #dc2626;
  background: #ffffff;
  color: #b91c1c;
}

.modal-danger-btn:hover {
  background: #fef2f2;
}

.debrief-label {
  display: block;
  margin: 8px 0 6px 0;
  font-size: 0.9rem;
  color: #374151;
}

.party-links {
  font-size: 0.9rem;
  line-height: 1.5;
}

.deletion-code-note {
  font-size: 0.9rem;
  line-height: 1.45;
  color: #374151;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px 10px;
}

.deletion-code-actions {
  display: block;
  margin-top: 8px;
}

.party-links a {
  color: #0f766e;
  text-decoration: none;
}

.party-links a:hover {
  text-decoration: underline;
}

.debrief-textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
}

.briefing-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.92rem;
  color: #374151;
}

.briefing-consent input[type="checkbox"] {
  margin-top: 2px;
}

/* ---- Markdown styling (ChatGPT-ish) ---- */
.msg-text p {
  margin: 0.25rem 0;
}

.msg-text strong {
  font-weight: 650;
}

.msg-text em {
  font-style: italic;
}

.msg-text ul,
.msg-text ol {
  margin: 0.25rem 0 0.25rem 1.2rem;
  padding-left: 1.2rem;
}

.msg-text li {
  margin: 0.15rem 0;
}

.msg-text code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.92em;
}

.msg-text pre {
  background: #f3f4f6;
  padding: 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0.4rem 0;
}

.msg-text pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

@media (max-width: 980px) {
  .disclaimer-panel h2 {
    font-size: 0.95rem;
  }

  .disclaimer-panel p {
    font-size: 0.84rem;
    line-height: 1.35;
  }

  header h1 {
    font-size: 1.2rem;
  }

  .model-status {
    font-size: 0.75rem;
  }

  .app-layout {
    width: min(900px, calc(100% - 24px));
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    margin: 12px auto;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "chat"
      "disclaimer";
  }

  .disclaimer-panel {
    grid-area: disclaimer;
    max-height: 64px;
    min-height: 64px;
    overflow: hidden;
    padding: 10px 12px;
  }

  .chat-container {
    grid-area: chat;
  }

  .disclaimer-panel.is-expanded {
    max-height: min(42vh, 320px);
    overflow-y: auto;
  }

  .disclaimer-panel:not(.is-expanded) h2,
  .disclaimer-panel:not(.is-expanded) p {
    display: none;
  }

  .disclaimer-toggle {
    display: block;
    margin-bottom: 0;
  }

  .disclaimer-panel.is-expanded .disclaimer-toggle {
    margin-bottom: 10px;
  }

  .bubble {
    max-width: 92%;
    font-size: 0.9rem;
    line-height: 1.35;
    padding: 8px 10px;
  }

  .msg-label {
    font-size: 0.68rem;
  }

  .msg-time {
    font-size: 0.66rem;
  }

  form textarea {
    font-size: 0.92rem;
    padding: 10px 12px;
  }

  form button {
    font-size: 0.9rem;
    height: 44px;
  }

  .input-actions .end-chat-btn {
    height: 32px;
    font-size: 0.76rem;
  }

  .ddc-logo-outside {
    display: none;
  }

  .header-actions {
    position: static;
    margin-top: 10px;
    text-align: center;
  }

  body.chat-live-mode .app-layout {
    grid-template-rows: 1fr;
    grid-template-areas: "chat";
  }

  body.chat-live-mode .disclaimer-panel {
    display: none;
  }

  body.chat-live-mode header {
    padding: 10px 12px;
  }

  body.chat-live-mode header h1 {
    display: none;
  }

  body.chat-live-mode .prompt-warning {
    display: none;
  }
}
