/* ===================================================
   FONTS
   =================================================== */
@font-face {
  font-family: "Kave-Haffer";
  src: url("./fonts/KaveHafferDisplay/KaveHafferDisplay-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kave-Haffer";
  src: url("./fonts/KaveHafferDisplay/KaveHafferDisplay-RegularItalic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Kave-HafferText";
  src: url("./fonts/KaveHafferText/KaveHafferText-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kave-HafferText";
  src: url("./fonts/KaveHafferText/KaveHafferText-RegularItalic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Kave-HafferText";
  src: url("./fonts/KaveHafferText/KaveHafferText-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kave-HafferText";
  src: url("./fonts/KaveHafferText/KaveHafferText-SemiBoldItalic.woff2") format("woff2");
  font-weight: 600;
  font-style: italic;
  font-display: swap;
}

/* ===================================================
   DESIGN TOKENS
   =================================================== */
:root {
  /* Primitives */
  --neutral-50:  #ffffff;
  --neutral-100: #f7f6f4;
  --neutral-200: #f0efeb;
  --neutral-300: #d7d6d2;
  --neutral-400: #bdbcb7;
  --neutral-500: #a1a19b;
  --neutral-600: #888882;
  --neutral-700: #6c6c66;
  --neutral-800: #53534c;
  --neutral-900: #383831;
  --neutral-950: #000000;

  --linen:      #f2f1e7;
  --clay:       #dadac7;
  --sand:       #bdafa0;
  --terracota:  #a9431e;

  /* Semantic */
  --color-fg-default:  var(--neutral-950);
  --color-fg-muted:    var(--neutral-700);
  --color-fg-subtle:   var(--neutral-500);

  --color-bg-page:    #ffffff;
  --color-bg-default: var(--neutral-50);
  --color-bg-muted:   var(--neutral-100);
  --color-bg-subtle:  var(--neutral-200);

  --color-border-default:  var(--neutral-300);
  --color-border-muted:    var(--neutral-200);
  --color-border-emphasis: var(--neutral-950);

  --color-bg-error-muted:    #ffdee5;
  --color-fg-error:          #a40928;
  --color-border-error-muted: #ff98ac;

  --color-fg-warning: #8a3a26;

  --color-link: var(--terracota);

  /* Typography */
  --font-display: "Kave-Haffer", "Poppins", Helvetica, Arial, sans-serif;
  --font-text:    "Kave-HafferText", "Poppins", Helvetica, Arial, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ===================================================
   RESET / BASE
   =================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font-text);
  font-size: 16px;
  background: var(--color-bg-page);
  color: var(--color-fg-default);
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
}

/* ===================================================
   PAGE SHELL
   =================================================== */
html, body {
  height: 100%;
}

.page-shell {
  max-width: 960px;
  margin: 0 auto;
  height: 100vh;
  padding: 0 16px 32px;
  display: flex;
  flex-direction: column;
}

/* ===================================================
   HEADER
   =================================================== */
.env-badge {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 4px 16px;
  font-family: var(--font-text);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--color-fg-warning);
  background: var(--color-bg-error-muted);
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 0 20px;
  border-bottom: 1px solid var(--color-border-default);
  margin-bottom: 24px;
}

.brand-block h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--color-fg-default);
}

.privacy-banner {
  margin: -12px 0 20px;
  font-size: 0.8125rem;
  color: var(--color-fg-subtle);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-summary {
  display: flex;
  flex-direction: column;
  text-align: right;
  font-size: 0.875rem;
  color: var(--color-fg-muted);
  line-height: 1.4;
}

.user-summary strong {
  color: var(--color-fg-default);
  font-weight: 600;
}

/* ===================================================
   CHAT SHELL
   =================================================== */
.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative; /* needed for drop-overlay */
}

/* ===================================================
   MESSAGE PANEL
   =================================================== */
.message-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-bottom: 8px;
}

.message {
  padding: 16px 20px;
  border-radius: 4px;
}

.message-user {
  background: var(--linen);
  border: 1px solid var(--clay);
}

.message-assistant {
  background: var(--neutral-100);
  border: 1px solid var(--color-border-muted);
}

.message-role {
  margin: 0 0 8px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-fg-subtle);
}

.message-body {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--color-fg-default);
}

/* ===================================================
   MARKDOWN BODY
   =================================================== */
.markdown-body {
  white-space: normal;
}

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child  { margin-bottom: 0; }

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body pre,
.markdown-body blockquote {
  margin: 0 0 10px;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 20px;
}

.markdown-body li + li {
  margin-top: 4px;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-bg-subtle);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-muted);
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.markdown-body a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-body blockquote {
  border-left: 2px solid var(--color-border-default);
  padding-left: 12px;
  color: var(--color-fg-muted);
}

/* ===================================================
   ATTACHMENTS
   =================================================== */
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 2px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-default);
  color: var(--color-fg-muted);
  font-size: 0.8125rem;
}

/* ===================================================
   PENDING STATE
   =================================================== */
.message-pending .message-body {
  min-height: 1.2rem;
}

.pending-status {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-fg-subtle);
  font-size: 0.875rem;
}

.pending-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--color-fg-subtle);
  animation: pulse 1.1s ease-in-out infinite;
}

/* ===================================================
   TICKET BOX
   =================================================== */
.ticket-box {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.875rem;
  color: var(--color-fg-muted);
}

.ticket-box a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ===================================================
   CONVERSATION FEEDBACK
   =================================================== */
.conversation-feedback {
  margin: 12px 0;
  padding: 14px 16px;
  border: 1px solid var(--color-border-default);
  border-radius: 6px;
  background: var(--color-bg-muted);
}

.conversation-feedback-prompt {
  margin: 0 0 10px;
  font-weight: 600;
  color: var(--color-fg-default);
}

.conversation-feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.conversation-feedback-actions[hidden],
.conversation-feedback-reasons[hidden] {
  display: none;
}

.conversation-feedback-yes,
.conversation-feedback-no,
.conversation-feedback-submit {
  border: 1px solid var(--color-border-emphasis);
  background: var(--color-bg-page);
  color: var(--color-fg-default);
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.conversation-feedback-yes:hover,
.conversation-feedback-no:hover,
.conversation-feedback-submit:hover {
  background: var(--color-fg-default);
  color: var(--color-bg-page);
}

.conversation-feedback-no:disabled {
  opacity: 0.5;
  cursor: default;
}

.conversation-feedback-reasons {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border-muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conversation-feedback-reasons-label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-fg-muted);
}

.conversation-feedback-reason {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--color-fg-default);
}

.conversation-feedback-reason-other {
  flex-wrap: wrap;
}

.conversation-feedback-other-input {
  flex: 1;
  min-width: 160px;
  border: 1px solid var(--color-border-default);
  border-radius: 2px;
  padding: 4px 8px;
  font-size: 0.8125rem;
  font-family: var(--font-text);
}

.conversation-feedback-submit {
  align-self: flex-start;
  margin-top: 4px;
}

.conversation-feedback-thanks {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-fg-muted);
}

/* ===================================================
   EMPTY STATE
   =================================================== */
.empty-state {
  margin: auto 0;
  padding: 48px 12px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--color-fg-default);
}

.empty-state p {
  max-width: 480px;
  margin: 0 auto;
  font-size: 0.9375rem;
  color: var(--color-fg-muted);
  line-height: 1.6;
}

/* ===================================================
   NEW CONVERSATION
   =================================================== */
.new-conversation-row {
  display: flex;
  justify-content: center;
  padding: 4px 0 2px;
}

.new-conversation-btn {
  background: transparent;
  color: var(--color-fg-subtle);
  border-color: transparent;
  font-size: 0.8125rem;
  font-weight: 400;
  padding: 6px 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.new-conversation-btn:hover {
  opacity: 1;
  color: var(--color-fg-default);
}

/* ===================================================
   COMPOSER
   =================================================== */
.composer-panel {
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(to top, var(--color-bg-page) 80%, transparent);
}

.composer-form {
  background: var(--color-bg-default);
  border: 1px solid var(--color-border-default);
  border-radius: 6px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

textarea {
  width: 100%;
  background: transparent;
  color: var(--color-fg-default);
  border: 0;
  padding: 0;
  resize: vertical;
  font: inherit;
  font-size: 0.9375rem;
  line-height: 1.6;
  min-height: 72px;
}

textarea::placeholder {
  color: var(--color-fg-subtle);
}

textarea:focus {
  outline: none;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.composer-footer {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border-muted);
}

.attach-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.confidential-notice {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-fg-warning);
  white-space: nowrap;
}

.confidential-notice-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin-top: 1px;
  color: inherit;
}

.attachment-summary {
  flex: 1;
  min-width: 140px;
}

.file-picker {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 2px;
  border: 1px solid var(--color-border-default);
  background: transparent;
  color: var(--color-fg-muted);
  cursor: pointer;
  font-size: 0.8125rem;
  font-family: var(--font-text);
  transition: border-color 0.15s, color 0.15s;
}

.file-picker:hover {
  border-color: var(--color-border-emphasis);
  color: var(--color-fg-default);
}

.attachment-count {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-fg-subtle);
  overflow-wrap: anywhere;
}

/* ===================================================
   BUTTONS
   =================================================== */
button {
  font-family: var(--font-text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--color-border-emphasis);
  border-radius: 2px;
  padding: 8px 18px;
  background: var(--color-border-emphasis);
  color: var(--neutral-50);
  transition: opacity 0.15s;
}

button:hover {
  opacity: 0.85;
}

/* Secondary (outline) */
.secondary-button {
  background: transparent;
  color: var(--color-fg-default);
  border-color: var(--color-border-default);
}

.secondary-button:hover {
  opacity: 1;
  border-color: var(--color-border-emphasis);
}

.lang-select {
  font-family: var(--font-text);
  font-size: 0.8125rem;
  color: var(--color-fg-default);
  background: transparent;
  border: 1px solid var(--color-border-default);
  border-radius: 2px;
  padding: 7px 10px;
  cursor: pointer;
}

.lang-select:hover {
  border-color: var(--color-border-emphasis);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-loading {
  min-width: 7.5rem;
  font-size: 0.875rem;
  color: var(--color-fg-subtle);
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

/* ===================================================
   ERROR BANNER
   =================================================== */
.error-banner {
  background: var(--color-bg-error-muted);
  border: 1px solid var(--color-border-error-muted);
  color: var(--color-fg-error);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 0.875rem;
}

/* ===================================================
   UTILITIES
   =================================================== */
.subtle {
  color: var(--color-fg-subtle);
}

/* ===================================================
   ANIMATIONS
   =================================================== */
@keyframes pulse {
  0%   { opacity: 0.3; transform: scale(0.85); }
  50%  { opacity: 1;   transform: scale(1); }
  100% { opacity: 0.3; transform: scale(0.85); }
}

/* ===================================================
   DROP ZONE
   =================================================== */
.drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  border: 2px dashed var(--color-border-emphasis);
  border-radius: 6px;
  background: rgba(242, 241, 231, 0.9);
  align-items: center;
  justify-content: center;
  font-size: 0.9375rem;
  color: var(--color-fg-muted);
  pointer-events: none; /* let drop events pass through to #chat-shell */
  letter-spacing: 0.01em;
}

.drop-active .drop-overlay {
  display: flex;
}

/* ===================================================
   ATTACHMENT PREVIEW STRIP (pre-send thumbnails)
   =================================================== */
.attachment-preview {
  display: none; /* shown via JS when pendingFiles.length > 0 */
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 4px;
}

.thumb-item {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.thumb-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--color-border-default);
  display: block;
}

.thumb-name {
  max-width: 120px;
  font-size: 0.8125rem;
  color: var(--color-fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-default);
  border-radius: 2px;
}

.thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  padding: 0;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  background: var(--neutral-800);
  color: var(--neutral-50);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
  transition: opacity 0.15s;
}

/* ===================================================
   SENT MESSAGE THUMBNAILS
   =================================================== */
.attachment-thumb img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--color-border-default);
  display: block;
}

/* ===================================================
   RESPONSIVE
   =================================================== */
@media (max-width: 680px) {
  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .user-summary {
    text-align: left;
  }

  .empty-state h2 {
    font-size: 1.5rem;
  }
}
