/* =====================================================================
   Prinia RAG Chatbot — style.css
   Palette inspired by the SDG Prinia property site
   ===================================================================== */

/* ── Custom Properties ─────────────────────────────────────────────── */
:root {
  --bg-sage: #eef7e4;
  --bg-sage-dark: #dff0cd;
  --bg-card: #ffffff;
  --text-dark: #2d3e1d;
  --text-mid: #4a5e38;
  --text-light: #7a9266;
  --accent-green: #6a9a2e;
  --accent-green-h: #558020;
  --accent-gold: #c8a030;
  --accent-gold-h: #a8861f;
  --user-bubble: #d4ebb0;
  --bot-bubble: #ffffff;
  --border: #c8deb0;
  --shadow-sm: 0 2px 8px rgba(45, 62, 29, .08);
  --shadow-md: 0 6px 24px rgba(45, 62, 29, .12);
  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --sidebar-w: 320px;
  --header-h: 68px;
  --transition: 0.22s ease;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'Inter', system-ui, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-sage);
  color: var(--text-dark);
  min-height: 100vh;
  overflow-x: hidden;
  /* Subtle botanical leaf overlay */
  background-image:
    radial-gradient(ellipse 60% 40% at 95% 5%, rgba(200, 160, 48, .08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 5% 95%, rgba(106, 154, 46, .07) 0%, transparent 55%);
}

/* ── Header ─────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

/* Real logo image */
.logo-img {
  height: 52px;
  width: auto;
  max-width: 240px;
  object-fit: contain;
  display: block;
}

.header-tagline {
  font-size: 13px;
  color: var(--text-light);
  flex: 1;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  transition: background var(--transition);
}

.status-dot.online {
  background: #5cb85c;
  box-shadow: 0 0 0 2px rgba(92, 184, 92, .25);
}

.status-dot.offline {
  background: #d9534f;
}

.status-dot.loading {
  background: var(--accent-gold);
  animation: pulse 1s infinite;
}

.status-label {
  font-size: 12px;
  color: var(--text-light);
}

/* ── Main Layout ────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  max-width: 1400px;
  margin: 0 auto;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), width var(--transition);
  position: relative;
}

.sidebar-toggle {
  display: none;
  position: absolute;
  top: 14px;
  right: -44px;
  width: 36px;
  height: 36px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle span {
  width: 18px;
  height: 2px;
  background: var(--text-dark);
  border-radius: 2px;
  transition: var(--transition);
}

.sidebar-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar-section {}

.sidebar-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 6px;
}

.sidebar-hint {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 14px;
}

/* Upload area */
.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  min-height: 130px;
  background: var(--bg-sage);
}

.upload-area:hover,
.upload-area.dragging {
  border-color: var(--accent-green);
  background: #e4f3d3;
}

.upload-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
}

.upload-subtext {
  font-size: 11px;
  color: var(--text-light);
}

/* File list */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  min-height: 0;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-sage);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-mid);
}

.file-item svg {
  flex-shrink: 0;
}

.file-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 2px;
  line-height: 1;
  border-radius: 4px;
  transition: color var(--transition);
}

.file-remove:hover {
  color: #c0392b;
}

/* Ingest status */
.ingest-status {
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
  color: var(--text-mid);
}

.ingest-status.success {
  color: var(--accent-green);
}

.ingest-status.error {
  color: #c0392b;
}

.sidebar-info {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.how-it-works {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.how-it-works li {
  font-size: 12px;
  color: var(--text-mid);
}

.powered-by {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 14px;
}

.contextinit-link {
  color: inherit;
  text-decoration: none;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform .1s;
  border-radius: var(--radius-sm);
}

.btn:active {
  transform: scale(.98);
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn-primary {
  width: 100%;
  padding: 11px 16px;
  font-size: 13px;
  background: var(--accent-green);
  color: #fff;
  border-radius: var(--radius-sm);
}

.btn-primary:not(:disabled):hover {
  background: var(--accent-green-h);
}

.btn-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--accent-green);
  color: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}

.btn-send:not(:disabled):hover {
  background: var(--accent-green-h);
}

/* ── Chat Panel ─────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.chat-window::-webkit-scrollbar {
  width: 5px;
}

.chat-window::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Chat bubbles */
.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: fadeSlideUp .25s ease both;
}

.chat-row.user {
  flex-direction: row-reverse;
}

.chat-row.bot {
  flex-direction: row;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.avatar.user-av {
  background: var(--accent-gold);
  color: #fff;
}

.avatar.bot-av {
  background: var(--accent-green);
  color: #fff;
}

.bubble {
  max-width: min(520px, 75%);
  padding: 13px 17px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.65;
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-row.user .bubble {
  background: var(--user-bubble);
  color: var(--text-dark);
  border-bottom-right-radius: 4px;
}

.chat-row.bot .bubble {
  background: var(--bot-bubble);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

/* Source pills */
.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.source-pill {
  font-size: 10px;
  padding: 3px 8px;
  background: var(--bg-sage);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: 20px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 17px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-light);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: .2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: .4s;
}

/* Welcome card */
.welcome-card {
  text-align: center;
  padding: 40px 20px;
  max-width: 460px;
  margin: auto;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.welcome-card h2 {
  font-family: var(--font-serif);
  font-size: 26px;
  color: var(--text-dark);
  margin-bottom: 10px;
}

.welcome-card p {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.7;
}

/* ── Chat Input ─────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 16px 32px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-sage);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  transition: border-color var(--transition);
}

.input-row:focus-within {
  border-color: var(--accent-green);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-dark);
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
}

.chat-textarea::placeholder {
  color: var(--text-light);
}

.input-hint {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 7px;
  text-align: right;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--bg-sage-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--font-sans);
}

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--accent-green);
}

.toast.error {
  background: #c0392b;
}

.toast.info {
  background: var(--accent-gold);
}

/* ── Animations ─────────────────────────────────────────────────────── */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {

  0%,
  80%,
  100% {
    opacity: .2;
    transform: scale(.85);
  }

  40% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: .4;
  }
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 100%;
    --header-h: 58px;
  }

  .app-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    max-height: 0;
    transition: max-height .3s ease;
  }

  .sidebar.open {
    max-height: 800px;
  }

  .sidebar-toggle {
    display: flex;
    position: fixed;
    top: 14px;
    left: 12px;
  }

  .chat-panel {
    height: calc(100svh - var(--header-h));
    position: sticky;
    top: var(--header-h);
  }

  .chat-window {
    padding: 16px;
  }

  .chat-input-area {
    padding: 12px 16px 16px;
  }

  .bubble {
    max-width: 85%;
  }

  .header-tagline {
    display: none;
  }

  .header-inner {
    padding-left: 60px;
  }
}

@media (max-width: 400px) {
  .logo-name {
    font-size: 18px;
  }
}