/* Navbar brand logo (top left): dark vs light theme */
.navbar-brand-logo {
  height: 32px;
  width: auto;
  display: block;
}
[data-bs-theme="dark"] .navbar-brand-logo-light { display: none !important; }
[data-bs-theme="dark"] .navbar-brand-logo-dark { display: block !important; }
[data-bs-theme="light"] .navbar-brand-logo-dark { display: none !important; }
[data-bs-theme="light"] .navbar-brand-logo-light { display: block !important; }
/* Login page: slightly larger logo next to title */
.page-content .navbar-brand-logo {
  height: 40px;
}
/* Login page: title text matches logo size (logo is 40px) */
body.login-page .login-brand-title {
  font-size: 2.25rem;
  font-weight: 600;
  line-height: 1.2;
}
/* Full viewport: chat fills the whole browser window */
html {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
body {
  height: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0 !important;
  overflow: hidden;
}
body.d-flex.flex-column {
  min-height: 100vh;
}
/* Chat page and its container use full viewport */
.chatbot-page {
  min-height: 100vh;
  height: 100%;
  width: 100%;
}
.chatbot-page > .container-xl {
  max-width: none;
  width: 100%;
  margin: 0;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

/* Top navbar: use Tabler navbar; ensure it doesn’t grow and page fills below */
body > header.navbar {
  flex: 0 0 auto;
}
body > header.navbar .container-xl {
  max-width: none;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}
/* Chat nav: larger icon, tighter spacing, aligned with "Chat" text */
.navbar .nav-link {
  display: inline-flex;
  align-items: baseline;
}
.navbar .nav-link .nav-link-icon {
  font-size: 1.05rem;
  margin-right: 0.25rem;
  line-height: 1;
  /* Nudge icon up so it aligns with text cap height, not tab */
  transform: translateY(-0.08em);
}
.navbar .nav-link .nav-link-icon .ti {
  font-size: inherit;
  line-height: inherit;
}
.navbar .nav-link .nav-link-title {
  font-size: 1.1rem;
  line-height: 1;
}
.navbar .nav-link.active .nav-link-title {
  position: relative;
}

.navbar .nav-link.active .nav-link-title::after {
  content: "";
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: -0.35rem;
  height: 2px;
  background-color: var(--tblr-primary);
  border-radius: 2px;
}

/* Code styling for assistant Markdown */
.chat-code pre, .chat-code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
}
.chat-code pre {
  background: rgba(0,0,0,0.04);
  padding: .75rem;
  border-radius: .5rem;
  overflow: auto;
}
[data-bs-theme='dark'] .chat-code pre {
  background: rgba(255,255,255,0.06);
}
.chat-code blockquote {
  margin: .5rem 0;
  padding-left: .75rem;
  border-left: 3px solid rgba(0,0,0,0.1);
}
[data-bs-theme='dark'] .chat-code blockquote {
  border-left-color: rgba(255,255,255,0.15);
}
/* Chat bubbles */
.chat-bubble { border-radius: .5rem; }
.chat-bubble.asst { background: #f2f4f7; color: #212529; border: 1px solid rgba(0,0,0,0.06); }
[data-bs-theme='dark'] .chat-bubble.asst { background: rgba(255,255,255,0.06); color: #e9ecef; border: 1px solid rgba(255,255,255,0.08); }
/* Rating controls */
.rating-bar { display:flex; align-items:center; gap:.25rem; margin-top:.25rem; }
.rating-bar .btn { padding: .125rem .25rem; }
.rating-bar .btn.active { color: var(--tblr-primary); }

/* Per-page layout: fill viewport and keep only inner panels scrollable */
.chatbot-page { min-height: 0; overflow: hidden; flex: 1 1 auto; display: flex; flex-direction: column; }
.chatbot-page > .container-xl { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.chatbot-h { flex: 1 1 auto; min-height: 0; }
.chatbot-row { flex: 1 1 auto; min-height: 0; align-content: stretch; align-items: stretch; flex-wrap: nowrap; }
.chatbot-col { display:flex; flex-direction:column; overflow: hidden; min-height: 0; min-width: 0; flex: 1 1 auto; }
.chatbot-card { display:flex; flex-direction:column; min-height: 0; flex: 1 1 auto; }
.chatbot-card > .card-header,
.chatbot-card > .card-footer { flex: 0 0 auto; }
.chatbot-scroll { overflow: auto; min-height: 0; flex: 1 1 0%; height: 0; -webkit-overflow-scrolling: touch; }

/* Hide header completely on welcome screen */
#chat-header[style*="display: none"] {
  display: none !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  height: 0 !important;
}

/* Style the threads search input with inline plus button */
#thread-search {
  border: 1px solid #e9ecef;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#thread-search:focus {
  border-color: var(--tblr-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--tblr-primary-rgb), 0.25);
}

#new-thread {
  border: none;
  background: none;
  opacity: 0.6;
  transition: opacity 0.2s ease, color 0.2s ease;
}

#new-thread:hover,
#new-thread:focus {
  opacity: 1;
  color: var(--tblr-primary) !important;
  background: none;
  box-shadow: none;
}

[data-bs-theme='dark'] #thread-search {
  border-color: rgba(255,255,255,0.15);
  background-color: rgba(255,255,255,0.05);
}

[data-bs-theme='dark'] #thread-search:focus {
  border-color: var(--tblr-primary);
}

/* Empty state styling for ChatGPT-like interface */
#empty-state {
  min-height: 100%;
}

#empty-state h4 {
  font-weight: 600;
  font-size: 1.5rem;
}

#empty-state p {
  font-size: 0.95rem;
  opacity: 0.8;
}

/* Ensure the messages container takes full height when empty state is hidden */
#messages-container {
  min-height: 100%;
}

/* Style the centered input form */
#chat-form-centered textarea,
#chat-form textarea {
  min-height: 60px;
  border-radius: 12px;
  border: 2px solid #e9ecef;
  transition: border-color 0.2s ease;
  padding-right: 50px !important;
}

#chat-form-centered textarea:focus,
#chat-form textarea:focus {
  border-color: var(--tblr-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--tblr-primary-rgb), 0.25);
}

#chat-form-centered .btn,
#chat-form .btn {
  border: none;
  box-shadow: none;
  z-index: 10;
  opacity: 0.7;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

#chat-form-centered .btn:hover,
#chat-form .btn:hover,
#chat-form-centered .btn:focus,
#chat-form .btn:focus {
  opacity: 1;
  box-shadow: none;
}

/* Disable send button when textarea is empty */
#chat-form-centered .btn:disabled,
#chat-form .btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

[data-bs-theme='dark'] #chat-form-centered textarea,
[data-bs-theme='dark'] #chat-form textarea {
  border-color: rgba(255,255,255,0.15);
  background-color: rgba(255,255,255,0.05);
}

[data-bs-theme='dark'] #chat-form-centered textarea:focus,
[data-bs-theme='dark'] #chat-form textarea:focus {
  border-color: var(--tblr-primary);
}

/* Context Window Button (disabled for now) */
#toggle-context-window:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#toggle-context-window:disabled:hover {
  opacity: 0.5;
}

/* Context Window Sidebar Styles */
.context-sidebar {
  position: fixed;
  right: 20px;
  top: 80px;
  width: 350px;
  max-height: calc(100vh - 100px);
  transition: all 0.3s ease;
  opacity: 0;
  transform: translateX(calc(100% + 40px));
  z-index: 1040;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

.context-sidebar > .card {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border-radius: 0.5rem;
}

.context-sidebar.show {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

[data-bs-theme='dark'] .context-sidebar > .card {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

@media (max-width: 768px) {
  .context-sidebar {
    right: 10px;
    left: 10px;
    top: 60px;
    width: auto;
    max-height: calc(100vh - 80px);
  }
}

/* Purple button for reconciliation */
.btn-purple {
  color: #fff;
  background-color: #8b5cf6;
  border-color: #8b5cf6;
}
.btn-purple:hover,
.btn-purple:focus {
  color: #fff;
  background-color: #7c3aed;
  border-color: #7c3aed;
}
.btn-purple:disabled {
  color: #fff;
  background-color: #8b5cf6;
  border-color: #8b5cf6;
  opacity: 0.65;
}

/* Demo mode toggle in navbar */
.demo-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}
.demo-toggle .form-check-label {
  font-size: 0.85rem;
  opacity: 0.7;
}
.demo-toggle .form-check-input:checked + .form-check-label {
  opacity: 1;
  color: var(--tblr-primary);
}

/* Invoice Assistant page */
.invoice-page {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.invoice-page .container-xl {
  max-width: none;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.invoice-page .sortable:hover {
  background-color: rgba(0, 0, 0, 0.04);
}
[data-bs-theme='dark'] .invoice-page .sortable:hover {
  background-color: rgba(255, 255, 255, 0.06);
}

/* Exception status badge colors */
.badge-exception-OPEN { background-color: #d63939; color: #fff; }
.badge-exception-IN_PROGRESS { background-color: #206bc4; color: #fff; }
.badge-exception-WAITING_VENDOR { background-color: #f76707; color: #fff; }
.badge-exception-WAITING_INTERNAL { background-color: #f59f00; color: #fff; }
.badge-exception-RESOLVED { background-color: #2fb344; color: #fff; }
.badge-exception-DISMISSED { background-color: #667382; color: #fff; }

/* Exception badge as clickable button */
.btn-exception {
  cursor: pointer;
  border: none;
  font-size: 0.75rem;
  padding: 0.2em 0.6em;
  transition: opacity 0.15s;
}
.btn-exception:hover { opacity: 0.85; }

/* Timeline */
.exception-timeline {
  position: relative;
  padding-left: 2.5rem;
  margin: 1rem 0 0;
}
.exception-timeline::before {
  content: '';
  position: absolute;
  left: 0.9375rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  background: var(--tblr-border-color);
}
.timeline-event {
  position: relative;
  padding-bottom: 1.5rem;
}
.timeline-event:last-child {
  padding-bottom: 0;
}
.timeline-event-icon {
  position: absolute;
  left: -2.5rem;
  top: 0.125rem;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  z-index: 1;
  border: 2px solid var(--tblr-card-bg, #fff);
}
.timeline-event-content {
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  background: rgba(0,0,0,0.02);
  border: 1px solid var(--tblr-border-color);
}
[data-bs-theme='dark'] .timeline-event-content {
  background: rgba(255,255,255,0.03);
}
.timeline-event-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.timeline-event-payload {
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: var(--tblr-secondary);
  line-height: 1.5;
  cursor: default;
}
.timeline-event-payload.truncated {
  max-height: 6.4em;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.timeline-event-payload.truncated::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.2em;
  background: linear-gradient(transparent, rgba(0,0,0,0.02));
  pointer-events: none;
}
[data-bs-theme='dark'] .timeline-event-payload.truncated::after {
  background: linear-gradient(transparent, rgba(255,255,255,0.03));
}
.timeline-event-payload.expanded {
  max-height: none;
  overflow: visible;
  cursor: pointer;
}

/* Payload field layout */
.payload-field {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.125rem;
  font-size: 0.8125rem;
}
.payload-label {
  font-weight: 600;
  color: var(--tblr-body-color);
  min-width: 4rem;
  flex-shrink: 0;
}
.payload-label::after {
  content: ':';
}
.payload-body {
  margin-top: 0.375rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--tblr-border-color);
  white-space: pre-line;
  font-size: 0.8125rem;
  line-height: 1.6;
}
.payload-status-change {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.125rem;
}
.payload-snapshot {
  white-space: pre-line;
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* SAP Snapshot sections */
.payload-snapshot-detail {
  margin-top: 0.25rem;
}
.snapshot-section {
  border: 1px solid var(--tblr-border-color);
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.snapshot-section:last-child {
  margin-bottom: 0;
}
.snapshot-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--tblr-body-color);
  background: rgba(0,0,0,0.03);
  cursor: pointer;
  user-select: none;
}
[data-bs-theme='dark'] .snapshot-section-header {
  background: rgba(255,255,255,0.04);
}
.snapshot-section-header:hover {
  background: rgba(0,0,0,0.06);
}
[data-bs-theme='dark'] .snapshot-section-header:hover {
  background: rgba(255,255,255,0.07);
}
.snapshot-chevron {
  font-size: 0.7rem;
  transition: transform 0.15s;
}
.snapshot-section.collapsed .snapshot-chevron {
  transform: rotate(-90deg);
}
.snapshot-section.collapsed .snapshot-section-body {
  display: none;
}
.snapshot-section-body {
  padding: 0.5rem 0.625rem;
  font-size: 0.8125rem;
  overflow-x: auto;
}
.snapshot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1rem;
}
.snapshot-kv {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}
.snapshot-kv-wide {
  grid-column: 1 / -1;
}
.snapshot-k {
  font-weight: 600;
  color: var(--tblr-secondary);
  font-size: 0.75rem;
  min-width: 5.5rem;
  flex-shrink: 0;
}
.snapshot-v {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.snapshot-table {
  width: 100%;
  font-size: 0.75rem;
  border-collapse: collapse;
}
.snapshot-table th {
  font-weight: 600;
  color: var(--tblr-secondary);
  border-bottom: 1px solid var(--tblr-border-color);
  padding: 0.25rem 0.5rem;
  white-space: nowrap;
}
.snapshot-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  white-space: nowrap;
}
[data-bs-theme='dark'] .snapshot-table td {
  border-bottom-color: rgba(255,255,255,0.04);
}
.snapshot-table tr:last-child td {
  border-bottom: none;
}
.snapshot-po-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}
.snapshot-po-list code {
  padding: 0.15em 0.4em;
  background: rgba(0,0,0,0.04);
  border-radius: 0.25rem;
}
[data-bs-theme='dark'] .snapshot-po-list code {
  background: rgba(255,255,255,0.06);
}

/* Event type icon colors */
.event-icon-SAP_SNAPSHOT { background-color: rgba(32, 107, 196, 0.15); color: #206bc4; }
.event-icon-EMAIL_SENT { background-color: rgba(47, 179, 68, 0.15); color: #2fb344; }
.event-icon-EMAIL_RECEIVED { background-color: rgba(0, 184, 212, 0.15); color: #00b8d4; }
.event-icon-STATUS_CHANGE { background-color: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.event-icon-SUPPORTING_DOCUMENT_REQUESTED { background-color: rgba(245, 159, 0, 0.15); color: #f59f00; }
.event-icon-SUPPORTING_DOCUMENT_RECEIVED { background-color: rgba(12, 166, 120, 0.15); color: #0ca678; }

/* Compact table for wide column layout */
.invoice-table th, .invoice-table td {
  white-space: nowrap;
  font-size: 0.8125rem;
  padding: 0.5rem 0.625rem;
}
.invoice-table td.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
}
.invoice-table th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Exception modal status header */
.exception-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.exception-header .badge { font-size: 0.85rem; padding: 0.4em 0.8em; }

/* Reconciliation result markdown formatting */
.recon-markdown { line-height: 1.6; }
.recon-markdown p { margin-bottom: 0.75rem; }
.recon-markdown p:last-child { margin-bottom: 0; }
.recon-markdown h1, .recon-markdown h2, .recon-markdown h3 {
  margin-top: 1rem; margin-bottom: 0.5rem; font-weight: 600;
}
.recon-markdown h1 { font-size: 1.25rem; }
.recon-markdown h2 { font-size: 1.1rem; }
.recon-markdown h3 { font-size: 1rem; }
.recon-markdown ul, .recon-markdown ol {
  margin-bottom: 0.75rem; padding-left: 1.5rem;
}
.recon-markdown li { margin-bottom: 0.25rem; }
.recon-markdown strong { font-weight: 600; }
.recon-markdown code {
  background: rgba(0,0,0,0.08);
  padding: 0.15em 0.4em;
  border-radius: 0.25rem;
  font-size: 0.9em;
}
[data-bs-theme='dark'] .recon-markdown code {
  background: rgba(255,255,255,0.1);
}
.recon-markdown blockquote {
  border-left: 3px solid #0d6efd;
  padding-left: 1rem;
  margin-left: 0;
  margin-bottom: 0.75rem;
  color: #666;
  font-style: italic;
}
[data-bs-theme='dark'] .recon-markdown blockquote {
  color: #aaa;
}
.recon-markdown table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
}
.recon-markdown table th,
.recon-markdown table td {
  border: 1px solid #dee2e6;
  padding: 0.5rem;
  text-align: left;
}
.recon-markdown table th {
  background-color: #f8f9fa;
  font-weight: 600;
}
[data-bs-theme='dark'] .recon-markdown table th,
[data-bs-theme='dark'] .recon-markdown table td {
  border-color: #444;
}
[data-bs-theme='dark'] .recon-markdown table th {
  background-color: #2d3139;
}
.recon-markdown a {
  color: #0d6efd;
  text-decoration: none;
}
.recon-markdown a:hover {
  text-decoration: underline;
}

/* Searchable dropdown filter */
.searchable-dropdown { position: relative; }
.searchable-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  max-height: 220px;
  overflow-y: auto;
  background: var(--tblr-bg-surface);
  border: 1px solid var(--tblr-border-color);
  border-radius: 0.375rem;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,.15);
  margin-top: 2px;
}
.searchable-dropdown-menu.show { display: block; }
.searchable-dropdown-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  line-height: 1.4;
}
.searchable-dropdown-item:hover,
.searchable-dropdown-item.active {
  background: var(--tblr-active-bg);
}
.searchable-dropdown-item .item-name { font-weight: 500; }
.searchable-dropdown-item .item-code {
  font-size: 0.8em;
  opacity: 0.6;
}
.searchable-dropdown-item.clear-item {
  border-bottom: 1px solid var(--tblr-border-color);
  color: var(--tblr-secondary);
  font-style: italic;
}
