:root {
  --bg: #faf8f3;
  --card: #ffffff;
  --ink: #2b2f36;
  --muted: #6f7683;
  --faint: #9aa1ad;
  --border: #e8e2d6;
  --green-50: #edf6f0;
  --green-100: #dbefe2;
  --green-200: #c2e2cf;
  --green-600: #2e7d5c;
  --green-700: #256747;
  --blue-50: #edf3fd;
  --blue-100: #d9e6fa;
  --blue-200: #bccff0;
  --blue-600: #2f63c4;
  --blue-700: #274fa3;
  --orange-100: #f9e4cb;
  --orange-500: #dd8a3d;
  --notice-bg: #fbf6ec;
  --notice-border: #efe0c6;
  --notice-text: #7c6a4c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60, 54, 40, 0.05), 0 4px 14px rgba(60, 54, 40, 0.06);
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  background-image:
    radial-gradient(52vmax 42vmax at -12vmax -14vmax, #e3f1e7 0%, rgba(227, 241, 231, 0) 62%),
    radial-gradient(56vmax 46vmax at 112% 108%, #e0eafa 0%, rgba(224, 234, 250, 0) 60%),
    radial-gradient(30vmax 26vmax at 88% -10vmax, #fbeedd 0%, rgba(251, 238, 221, 0) 65%);
  background-attachment: fixed;
  overflow-x: clip;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 44px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 6px 8px 10px;
}

.brand-mark {
  display: inline-flex;
  line-height: 0;
  filter: drop-shadow(0 3px 6px rgba(47, 99, 196, 0.16));
}

.app-header h1 {
  font-size: 1.9rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  margin: 4px 0 0;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
  padding: 5px 13px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--green-700);
  background: var(--green-50);
  border: 1px solid var(--green-200);
  border-radius: 999px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #35a86b;
  box-shadow: 0 0 0 3px rgba(53, 168, 107, 0.18);
}

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.uploader {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-left: 4px solid var(--blue-200);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.uploader:hover {
  border-left-color: var(--blue-600);
}

#file-status {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--transition);
}

#file-status.is-loaded {
  color: var(--green-700);
  font-weight: 600;
}

/* ---------- Chat ---------- */

.chat-card {
  display: flex;
  flex-direction: column;
  height: 56vh;
  min-height: 360px;
  overflow: hidden;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, #f4faf5, #ffffff);
  border-radius: var(--radius) var(--radius) 0 0;
}

.chat-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 80%;
  padding: 11px 15px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 0.94rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--blue-100);
  border: 1px solid var(--blue-200);
  color: #1e3a68;
  border-bottom-right-radius: 5px;
}

.message.bot {
  align-self: flex-start;
  background: #f0f5f0;
  border: 1px solid var(--green-200);
  color: var(--ink);
  border-bottom-left-radius: 5px;
}

.message.system {
  align-self: center;
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  color: var(--notice-text);
  font-size: 0.86rem;
  text-align: center;
  border-radius: 12px;
  max-width: 92%;
}

.message.typing {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  background: #f0f5f0;
  border: 1px solid var(--green-200);
  border-bottom-left-radius: 5px;
}

.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--green-200);
  border-top-color: var(--green-600);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Empty state ---------- */

.empty-state {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 28px 20px;
  max-width: 420px;
}

.empty-state svg {
  margin-bottom: 8px;
  opacity: 0.95;
}

.empty-state strong {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.empty-state span {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.55;
}

/* ---------- Buttons & inputs ---------- */

button {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 550;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

button:hover {
  background: #f5f2ea;
  border-color: #d8d0bf;
}

button:active {
  background: #ece6d7;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:focus-visible,
#question-input:focus-visible {
  outline: 2px solid var(--blue-600);
  outline-offset: 2px;
}

#upload-button {
  background: var(--blue-50);
  border-color: var(--blue-200);
  color: var(--blue-700);
}

#upload-button:hover {
  background: var(--blue-100);
  border-color: var(--blue-600);
}

#upload-button:active {
  background: #c9dbf5;
}

#clear-button {
  color: var(--muted);
  font-weight: 450;
  padding: 7px 13px;
  font-size: 0.85rem;
  background: transparent;
}

#clear-button:hover {
  color: var(--ink);
  background: #f5f2ea;
}

#send-button {
  background: var(--green-600);
  border-color: var(--green-600);
  color: #ffffff;
  min-width: 96px;
  border-radius: 14px;
}

#send-button::after {
  content: " \2192";
}

#send-button:hover:not(:disabled) {
  background: var(--green-700);
  border-color: var(--green-700);
  box-shadow: 0 2px 8px rgba(46, 125, 92, 0.28);
}

#send-button:active:not(:disabled) {
  background: #1e5940;
}

#send-button:disabled {
  background: #a9c9b8;
  border-color: #a9c9b8;
  color: #ffffff;
  box-shadow: none;
}

#send-button:disabled::after {
  content: none;
}

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

#question-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.95rem;
  padding: 14px 20px;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition);
}

#question-input::placeholder {
  color: var(--faint);
}

#question-input:hover:not(:disabled) {
  border-color: #d3c9b4;
}

#question-input:focus {
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(46, 125, 92, 0.14), var(--shadow);
}

#question-input:disabled {
  background: #f4f1e9;
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- Footer ---------- */

.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--faint);
  padding-top: 10px;
  letter-spacing: 0.015em;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  .app {
    padding: 32px 18px 26px;
  }

  .app-header h1 {
    font-size: 1.6rem;
  }

  .chat-card {
    height: 58vh;
    min-height: 320px;
  }

  .message {
    max-width: 86%;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 24px 12px 20px;
    gap: 14px;
  }

  .app-header h1 {
    font-size: 1.4rem;
  }

  .app-header p {
    font-size: 0.9rem;
  }

  .uploader {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
    gap: 10px;
  }

  #upload-button {
    width: 100%;
    padding: 12px 16px;
  }

  #file-status {
    text-align: center;
    white-space: normal;
    overflow-wrap: break-word;
  }

  .chat {
    padding: 14px;
  }

  .message {
    max-width: 92%;
    font-size: 0.9rem;
  }

  .ask {
    gap: 8px;
  }

  #question-input {
    padding: 12px 15px;
  }

  #send-button {
    min-width: 74px;
    padding: 12px 10px;
  }

  .empty-state {
    padding: 20px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--green-200);
  }

  button,
  #question-input,
  #file-status,
  .uploader {
    transition: none;
  }
}
