/* ══════════════════════════════════════════════
   TISZA PROGRAM CHATBOT — Editorial Civic Design
   ══════════════════════════════════════════════ */

:root {
  /* ── Brand ── */
  --green: #006B3C;
  --green-bright: #00A651;
  --green-pale: #E6F4ED;
  --green-ghost: rgba(0, 107, 60, 0.06);
  --navy: #0F2B44;
  --navy-light: #1A3A5C;
  --red: #CE2939;
  --red-pale: #FFF0F0;

  /* ── Surface ── */
  --bg-app: #F4F3F1;
  --bg-panel: #FFFFFF;
  --bg-doc: #FAFAF7;
  --bg-elevated: #FFFFFF;
  --bg-sunken: #F0EFED;
  --bg-chat-bot: #F7F7F5;

  /* ── Text ── */
  --text-primary: #111110;
  --text-secondary: #6B6B68;
  --text-tertiary: #9B9B98;
  --text-inverse: #FFFFFF;

  /* ── Border ── */
  --border: #E4E3E0;
  --border-light: #EDECE9;
  --border-focus: var(--green);

  /* ── Typography ── */
  --font-ui: 'Outfit', system-ui, -apple-system, sans-serif;
  --font-doc: 'Source Serif 4', 'Georgia', serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* ── Radii ── */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  /* ── Shadows ── */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-green: 0 4px 14px rgba(0, 107, 60, 0.18);

  /* ── Motion ── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 0.15s;
  --dur-normal: 0.25s;
  --dur-slow: 0.4s;

  /* Layout stack (countdown + header + footer) */
  --header-h: 64px;
  --footer-h: 36px;
  --countdown-h: 48px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ══════ HEADER ══════ */
.app-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--navy);
  color: var(--text-inverse);
  z-index: 100;
  position: relative;
}

/* Subtle tricolor bottom edge */
.app-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--red) 0%, var(--red) 33.33%,
    #fff 33.33%, #fff 66.66%,
    var(--green) 66.66%, var(--green) 100%
  );
}

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

.logo-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--green-bright), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 166, 81, 0.3);
}

.logo-icon {
  font-family: var(--font-doc);
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  line-height: 1;
}

.logo {
  font-family: var(--font-doc);
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.logo-sub {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 400;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-flag {
  display: flex;
  height: 20px;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.hf-red, .hf-white, .hf-green { width: 10px; height: 100%; }
.hf-red { background: var(--red); }
.hf-white { background: #fff; }
.hf-green { background: var(--green-bright); }

/* Mobile tabs */
.mobile-tabs {
  display: none;
  gap: 6px;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--r-sm);
  background: rgba(255,255,255,0.05);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-in-out);
}

.tab-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.tab-btn.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  box-shadow: var(--shadow-green);
}

/* ══════ LAYOUT ══════ */
.split-container {
  display: flex;
  height: calc(100vh - var(--countdown-h) - var(--header-h) - var(--footer-h));
}

.panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ══════ CHAT PANEL ══════ */
.chat-panel {
  width: 42%;
  min-width: 340px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ── Messages ── */
.bot-message, .user-message {
  display: flex;
  gap: 12px;
  max-width: 88%;
  animation: msgIn var(--dur-slow) var(--ease-out) both;
}

.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.bot-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.message-content {
  padding: 14px 18px;
  border-radius: var(--r-md);
  line-height: 1.65;
  font-size: 14.5px;
  font-weight: 400;
}

.bot-message .message-content {
  background: var(--bg-chat-bot);
  border: 1px solid var(--border-light);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
  color: var(--text-primary);
}

.user-message .message-content {
  background: var(--green);
  color: var(--text-inverse);
  border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
  box-shadow: var(--shadow-green);
}

/* ── Welcome ── */
.welcome-message .message-content {
  background: linear-gradient(135deg, var(--green-pale), #F0FAF5) !important;
  border: 1px solid rgba(0, 107, 60, 0.1) !important;
}

.welcome-title {
  font-family: var(--font-doc);
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}

/* ── Chunk pills ── */
.chunk-ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 11px;
  margin: 3px 2px;
  background: var(--green-pale);
  border: 1px solid rgba(0, 107, 60, 0.15);
  border-radius: var(--r-xl);
  font-size: 12px;
  font-weight: 500;
  color: var(--green);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-in-out);
  text-decoration: none;
  white-space: nowrap;
}

.chunk-ref:hover {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  box-shadow: var(--shadow-green);
  transform: translateY(-1px);
}

/* ── Typing dots ── */
.typing-indicator { display: flex; gap: 5px; padding: 6px 2px; }

.typing-indicator span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0.25;
  animation: pulse 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.25; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* ── Quick questions ── */
.quick-questions {
  padding: 4px 0 0;
}

.quick-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-panel);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-in-out);
  text-align: left;
  line-height: 1.4;
}

.quick-icon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1.2;
}

.quick-btn:hover {
  border-color: var(--green);
  background: var(--green-ghost);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.quick-btn:active { transform: translateY(0); }

/* ── Input ── */
.chat-input-area {
  padding: 16px 22px 14px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-sunken);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px 10px 16px;
  transition: all var(--dur-fast) var(--ease-in-out);
}

.input-wrapper:focus-within {
  border-color: var(--green);
  background: var(--bg-panel);
  box-shadow: 0 0 0 3px rgba(0, 107, 60, 0.08);
}

#userInput {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.55;
  resize: none;
  outline: none;
  max-height: 120px;
  color: var(--text-primary);
}

#userInput::placeholder { color: var(--text-tertiary); }

#sendBtn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--green);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease-in-out);
  box-shadow: var(--shadow-green);
}

#sendBtn:hover {
  background: var(--green-bright);
  transform: scale(1.04);
  box-shadow: 0 6px 20px rgba(0, 107, 60, 0.25);
}

#sendBtn:active { transform: scale(0.96); }

#sendBtn:disabled {
  background: var(--border);
  color: var(--text-tertiary);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.rate-limit-info {
  font-size: 11px;
  color: var(--text-tertiary);
  padding-top: 6px;
  text-align: center;
  min-height: 16px;
}

/* ══════ DIVIDER ══════ */
.divider {
  width: 1px;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

.divider::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -4px; right: -4px;
  z-index: 1;
}

.divider:hover, .divider.active { background: var(--green); }

.divider-handle {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 40px;
  border-radius: 2px;
  background: var(--border);
  transition: all var(--dur-fast) var(--ease-in-out);
  z-index: 2;
}

.divider:hover .divider-handle {
  background: var(--green);
  height: 56px;
  width: 4px;
  box-shadow: 0 0 8px rgba(0, 107, 60, 0.2);
}

/* ══════ DOCUMENT PANEL ══════ */
.doc-panel {
  flex: 1;
  display: flex;
  flex-direction: row;
  background: var(--bg-doc);
  overflow: hidden;
}

/* ── TOC Sidebar ── */
.doc-sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
}

.toc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 20px 14px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.toc-header svg { opacity: 0.5; }

.doc-toc {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.toc-item {
  display: block;
  padding: 9px 20px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all var(--dur-fast) var(--ease-in-out);
  line-height: 1.4;
  cursor: pointer;
}

.toc-item:hover {
  background: var(--green-ghost);
  color: var(--green);
}

.toc-item.active {
  border-left-color: var(--green);
  color: var(--green);
  font-weight: 600;
  background: var(--green-pale);
}

.toc-item.level-2 {
  padding-left: 32px;
  font-size: 12.5px;
}

.toc-group.collapsed .toc-item.level-2 { display: none; }

/* ── Doc Content ── */
.doc-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  background: var(--bg-doc);
}

.doc-loading {
  padding: 48px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 15px;
}

/* Skeleton */
.doc-skeleton {
  padding: 48px 40px;
  max-width: 720px;
  margin: 0 auto;
}

.skeleton-line {
  height: 13px;
  background: linear-gradient(90deg, var(--border-light) 25%, var(--bg-doc) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.8s ease infinite;
  border-radius: 4px;
  margin-bottom: 14px;
}

.skeleton-line.short { width: 55%; }
.skeleton-line.medium { width: 75%; }
.skeleton-line.heading { height: 24px; width: 40%; margin-bottom: 22px; margin-top: 36px; border-radius: 6px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Document typography ── */
.doc-content .doc-inner {
  font-family: var(--font-doc);
  font-size: 17.5px;
  line-height: 1.85;
  color: var(--text-primary);
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 44px 80px;
  font-feature-settings: 'onum' 1, 'liga' 1;
}

.doc-content .doc-inner h1 {
  font-family: var(--font-doc);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.3px;
  border-left: 4px solid var(--green);
  padding: 8px 0 8px 18px;
  margin: 48px 0 22px;
  line-height: 1.35;
  color: var(--navy);
  background: var(--green-ghost);
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
}

.doc-content .doc-inner h2 {
  font-family: var(--font-doc);
  font-size: 19px;
  font-weight: 600;
  margin: 36px 0 14px;
  color: var(--navy-light);
  line-height: 1.45;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.doc-content .doc-inner p {
  margin: 10px 0;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.doc-content .doc-inner ul {
  list-style: none;
  margin: 12px 0;
  padding-left: 4px;
}

.doc-content .doc-inner .bullet-item {
  margin: 6px 0;
  padding-left: 22px;
  position: relative;
}

.doc-content .doc-inner .bullet-item::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.doc-content .doc-inner .page-num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
  display: block;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.doc-content .doc-inner .doc-title {
  font-family: var(--font-doc);
  font-size: 28px;
  font-weight: 700;
  color: var(--navy);
  text-align: center;
  margin: 0 0 32px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--green);
  line-height: 1.3;
}

.doc-content .doc-inner a {
  color: var(--green);
  text-decoration: underline;
  text-decoration-color: rgba(0, 107, 60, 0.3);
  text-underline-offset: 3px;
  transition: all var(--dur-fast) var(--ease-in-out);
}

.doc-content .doc-inner a:hover {
  color: var(--green-bright);
  text-decoration-color: var(--green-bright);
}

/* ══════ DOC QUOTES IN CHAT ══════ */
.doc-quote {
  display: block;
  margin: 8px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--green, #006B3C);
  background: rgba(0, 107, 60, 0.06);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  line-height: 1.6;
  cursor: pointer;
  transition: background 0.2s ease;
}

.doc-quote:hover {
  background: rgba(0, 107, 60, 0.12);
}

.source-badge {
  display: inline-block;
  padding: 2px 10px;
  margin: 2px 0;
  font-size: 11px;
  font-weight: 500;
  font-style: normal;
  color: var(--green);
  background: var(--green-pale);
  border: 1px solid rgba(0, 107, 60, 0.15);
  border-radius: var(--r-xl);
  white-space: nowrap;
  letter-spacing: 0.2px;
}

/* Chunk highlight */
.chunk-highlight {
  background: linear-gradient(90deg, #FFF8DC, #FFEEB0) !important;
  border-radius: var(--r-xs);
  transition: background 2s ease, box-shadow 2s ease;
  box-shadow: inset 0 0 0 1px rgba(210, 170, 30, 0.2);
}

.chunk-highlight.fade {
  background: transparent !important;
  box-shadow: none !important;
}

/* Text highlight (exact quote match in document) */
mark.text-highlight {
  background: linear-gradient(135deg, #FFF3B0, #FFE066);
  color: var(--text-primary);
  padding: 2px 4px;
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(210, 170, 30, 0.25);
  transition: background 0.6s ease, box-shadow 0.6s ease;
}

mark.text-highlight.fading {
  background: transparent;
  box-shadow: none;
}

/* ══════ FOOTER ══════ */
.app-footer {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sunken);
  border-top: 1px solid var(--border-light);
  padding: 0 16px;
  flex-shrink: 0;
}

.footer-disclaimer {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: center;
}

.footer-disclaimer strong {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ══════ FOCUS & A11Y ══════ */
:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ══════ MOBILE ══════ */
@media (max-width: 768px) {
  :root {
    --header-h: 56px;
    --countdown-h: 44px;
  }

  .mobile-tabs { display: flex; }
  .header-flag { display: none; }

  .app-header { height: 56px; padding: 0 14px; }
  .logo { font-size: 17px; }
  .logo-sub { display: none; }
  .logo-mark { width: 34px; height: 34px; }
  .logo-icon { font-size: 17px; }

  .app-footer { display: none; }

  .split-container {
    position: relative;
    height: calc(100dvh - var(--countdown-h) - var(--header-h));
    height: calc(100vh - var(--countdown-h) - var(--header-h)); /* fallback */
  }

  @supports (height: 100dvh) {
    .split-container {
      height: calc(100dvh - var(--countdown-h) - var(--header-h));
    }
  }

  .divider { display: none; }

  .panel {
    position: absolute;
    top: 0; left: 0;
    width: 100% !important;
    height: 100%;
    min-width: 0 !important;
    overflow: hidden;
    transition: opacity var(--dur-normal) ease, visibility var(--dur-normal) ease;
  }

  .panel:not(.active-tab) {
    opacity: 0; visibility: hidden; pointer-events: none;
  }

  .panel.active-tab {
    opacity: 1; visibility: visible; pointer-events: auto;
  }

  .doc-sidebar { display: none; }
  .chat-panel { border-right: none; }

  .chat-input-area {
    flex-shrink: 0;
    z-index: 10;
  }

  .chat-messages { padding: 20px 16px; }

  .message-content,
  .doc-loading { font-size: 15px; }

  /* 16px prevents iOS auto-zoom on input focus */
  #userInput { font-size: 16px; }

  .quick-grid { grid-template-columns: 1fr; }

  .quick-btn {
    padding: 14px 16px;
    font-size: 14px;
  }

  .doc-content .doc-inner {
    font-size: 17px;
    padding: 24px 18px 60px;
  }

  .doc-content .doc-inner h1 {
    font-size: 20px;
    margin: 32px 0 16px;
  }

  .doc-content .doc-inner h2 {
    font-size: 17px;
    margin: 24px 0 10px;
  }
}

/* ══════ SCROLLBARS ══════ */
::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.18); }

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}
