:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --border: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
}

body.has-app-header {
  padding-top: 64px;
}

/* === APP HEADER & MENU (Mobile-First) === */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
}

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 64px;
  gap: 16px;
}

.app-brand {
  text-decoration: none;
  font-weight: 700;
  font-size: 20px;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.app-brand:hover {
  color: var(--primary);
}

/* Hamburger Button (Mobile-First) */
.app-hamburger {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  gap: 5px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.hamburger-line {
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: all 0.3s ease;
}

/* Menu List (Mobile: vertical drawer) */
.app-menu-list {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  max-height: calc(100vh - 64px);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 16px var(--shadow);
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateY(-100%);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  width: 100%;
}

.app-menu-list.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.app-menu-list li {
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.app-menu-list li:last-child {
  border-bottom: none;
}

.app-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
  border-left: 4px solid transparent;
}

.app-link:hover {
  background: #f8fafc;
  color: var(--primary);
  border-left-color: var(--primary);
}

.app-link-primary {
  color: var(--primary);
  font-weight: 600;
}

.app-link-primary:hover {
  background: #eff6ff;
}

/* Account menu items group */
.app-menu-account {
  margin-top: auto;
  padding-top: 8px;
  border-top: 2px solid var(--border);
}

.app-menu-account .app-link {
  border-left: none;
}

.app-menu-account .app-link:first-child {
  border-top: 1px solid var(--border);
}

/* Desktop (≥768px) */
@media (min-width: 768px) {
  .app-hamburger {
    display: none;
  }

  .app-menu-list {
    position: static;
    flex-direction: row;
    max-height: none;
    background: transparent;
    border: none;
    box-shadow: none;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    padding: 0;
    gap: 4px;
    margin-left: auto;
    margin-right: 0;
    overflow: visible;
  }

  .app-menu-list li {
    border: none;
    padding: 0;
    margin: 0;
  }

  .app-link {
    min-height: 44px;
    padding: 6px 14px;
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
  }

  .app-link:hover {
    background: transparent;
    border-bottom-color: var(--primary);
  }

  .app-menu-account {
    margin-top: 0;
    padding-top: 0;
    border: none;
    margin-left: auto;
    display: flex;
    gap: 4px;
  }

  .app-menu-account .app-link {
    border-bottom: 3px solid transparent;
  }

  .app-menu-account .app-link:first-child {
    border-top: none;
  }

  .app-menu-account .app-link-primary {
    background: var(--primary);
    color: white;
    border-radius: 6px;
    border-bottom: none;
    padding: 6px 14px;
  }

  .app-menu-account .app-link-primary:hover {
    background: var(--primary-dark);
  }
}

/* Search Shell */
.search-shell {
  width: 100%;
  max-width: 700px;
  margin: 50px 0 0 0;
}

/* Mobile (até 480px) */
@media (max-width: 480px) {
  .search-shell {
    max-width: 100%;
  }
}

/* Tablets pequenos (481px até 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .search-shell {
    max-width: 85vw;
  }
}

/* Tablets grandes (769px até 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .search-shell {
    max-width: 90vw;
  }
}

/* Desktop (1025px até 1440px) */
@media (min-width: 1025px) and (max-width: 1440px) {
  .search-shell {
    max-width: 900px;
  }
}

/* Desktop grande (acima de 1441px) */
@media (min-width: 1441px) {
  .search-shell {
    max-width: 1100px;
  }
}

/* Header */
.search-header {
  text-align: center;
  margin-bottom: 24px;
}

.header-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.search-header h1 {
  margin: 0 0 8px;
  font-size: 36px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.search-subtitle {
  margin: 0;
  font-size: 17px;
  color: var(--text-secondary);
  font-weight: 400;
}

.auth-links {
  margin-top: 0;
  display: inline-flex;
  gap: 10px;
}

.auth-link {
  text-decoration: none;
  font-size: 14px;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 8px 12px;
  transition: all 0.15s ease;
}

.auth-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.auth-link-primary {
  background: var(--primary);
  color: #fff;
}

.auth-link-primary:hover {
  background: var(--primary-dark);
}

/* Search Container */
.search-container {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 10px 25px var(--shadow);
}

/* Search Field */
.search-field {
  width: 100%;
  height: 56px;
  border: 2px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  font-size: 18px;
  padding: 0 18px;
  outline: none;
  transition: all 0.2s ease;
  color: var(--text);
  font-family: inherit;
}

.search-field:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-field::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Search Examples */
.search-examples {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.search-examples span {
  color: var(--primary);
  font-weight: 500;
}

/* Search Meta */
.search-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.search-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.search-toggle input {
  accent-color: var(--primary);
  cursor: pointer;
}

.search-stats {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* Search Results */
.search-results {
  margin-top: 20px;
  border-radius: 8px;
  background: var(--bg);
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
}

.inline-table-host {
  margin-top: 16px;
}

.inline-table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #eef2ff;
}

.btn-close-inline {
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  background: #ef4444;
  color: #fff;
  cursor: pointer;
}

.inline-table-content {
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: var(--card);
  padding: 10px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 6px;
  background: var(--card);
  transition: all 0.15s ease;
}

.result-item > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.result-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.result-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.result-name {
  font-weight: 600;
  color: var(--primary);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-title {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-open-inline,
.btn-open-newtab {
  border: 0;
  border-radius: 6px;
  padding: 8px 12px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-open-inline {
  background: var(--primary);
  color: white;
}

.btn-open-newtab {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-open-inline:hover,
.btn-open-newtab:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-open-inline:hover {
  background: var(--primary-dark);
}

.btn-open-newtab:hover {
  background: #cbd5e1;
}

/* === TABLE PAGES STYLES === */
.page-container {
  width: min(98vw, 1600px);
  margin: 26px auto 40px;
}

.table-card, .page-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 4px 16px var(--shadow);
  margin-top: 50px;
}

/* Tables - Responsive wrapper */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  margin: 0 -18px;
  padding: 0 18px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: white;
  min-width: 100%;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 7px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: #f8fafc;
  color: var(--text);
  position: sticky;
  top: 0;
  font-weight: 800;
  white-space: nowrap;
}

.field-filter {
  width: 100%;
  margin: 8px 0 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.field-filter:focus {
  outline: none;
  border-color: var(--primary);
}

.link-btn {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--primary-dark);
}

/* Sticky Header */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  margin: -18px -18px 20px;
  padding: 18px;
  border-bottom: 2px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
}

.sticky-title {
  margin-bottom: 16px;
}

.sticky-title h1 {
  margin: 0;
  font-size: 28px;
  color: var(--text);
}

/* Mobile Toggle Button */
.toc-toggle {
  display: none;
  position: absolute;
  top: 18px;
  right: 18px;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  font-size: 22px;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
  transition: all 0.2s ease;
  z-index: 101;
}

.toc-toggle:hover {
  transform: scale(1.05);
  background: var(--primary-dark);
}

.toc-toggle:active {
  transform: scale(0.98);
}

.toc-toggle.active {
  background: #dc2626;
}

/* Table of Contents */
.table-of-contents {
  background: var(--primary);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.25);
}

.toc-title {
  color: white;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 16px;
  opacity: 0.95;
}

.toc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.toc-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.toc-link:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.toc-icon {
  font-size: 18px;
}

.accordion-section {
  scroll-margin-top: 20px;
}

/* SX3 Hint */
.sx3-hint {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  border-left: 4px solid #d97706;
  padding: 12px 16px;
  margin: -2px 0 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #000000;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3);
  font-weight: 600;
}

.sx3-hint strong {
  font-size: 15px;
}

.sx3-hint kbd {
  background: rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  padding: 4px 8px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: 700;
}

/* Accordions */
.accordion {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}

.accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s ease;
}

.accordion > summary:hover {
  background-color: #f8fafc;
}

.accordion > summary::before {
  content: "▶";
  display: inline-block;
  font-size: 12px;
  transition: transform 0.2s ease;
  color: var(--primary);
}

.accordion[open] > summary::before {
  transform: rotate(90deg);
}

.accordion[open] > summary {
  border-bottom: 1px solid var(--border);
}

.accordion > div {
  padding: 10px 12px;
}

/* Chat Flutuante */
.table-chat-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
}

.table-chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(59, 130, 246, 0.35);
  transition: all 0.2s ease;
}

.table-chat-fab:hover {
  background: var(--primary-dark);
  transform: scale(1.1);
}

.table-chat-fab:active {
  transform: scale(0.95);
}

.table-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 90px;
  z-index: 9999;
  width: min(380px, calc(100vw - 24px));
  height: 500px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.table-chat-panel.open {
  display: flex;
}

.table-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 12px 12px 0 0;
  font-weight: 700;
  color: var(--text);
}

.table-chat-close {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: #64748b;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-chat-close:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.table-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.table-chat-message {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
  max-width: 100%;
}

.table-chat-message.is-user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  max-width: 80%;
}

.table-chat-message.is-assistant {
  background: #f0f4f8;
  color: var(--text);
  align-self: flex-start;
  max-width: 80%;
}

.table-chat-message.is-assistant p {
  margin: 0 0 8px;
}

.table-chat-message.is-assistant p:last-child {
  margin-bottom: 0;
}

.table-chat-message.is-assistant ul,
.table-chat-message.is-assistant ol {
  margin: 6px 0 6px 18px;
}

.table-chat-message.is-assistant blockquote {
  margin: 6px 0;
  padding-left: 8px;
  border-left: 3px solid #cbd5e1;
  color: #334155;
}

.table-chat-message.is-assistant hr {
  border: 0;
  border-top: 1px solid #cbd5e1;
  margin: 8px 0;
}

.table-chat-message.is-assistant pre {
  margin: 8px 0;
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  background: #0f172a;
  color: #e2e8f0;
}

.table-chat-message.is-assistant code {
  background: #e2e8f0;
  color: #0f172a;
  padding: 1px 4px;
  border-radius: 4px;
}

.table-chat-message.is-assistant a {
  color: #1d4ed8;
  text-decoration: underline;
}

.table-chat-message.is-assistant .chat-md-table-wrap {
  overflow-x: auto;
  margin: 8px 0;
}

.table-chat-message.is-assistant table {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 12px;
  background: #ffffff;
}

.table-chat-message.is-assistant th,
.table-chat-message.is-assistant td {
  border: 1px solid #cbd5e1;
  padding: 6px;
  text-align: left;
}

.table-chat-message.is-assistant th {
  background: #e2e8f0;
}

.table-chat-message.is-assistant pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.table-chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 12px 12px;
}

.table-chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.table-chat-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.table-chat-send {
  border: 0;
  border-radius: 6px;
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.table-chat-send:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.table-chat-send:active {
  transform: translateY(0);
}

/* Hidden */
.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 20px 16px;
  }

  .search-header h1 {
    font-size: 28px;
  }

  .search-subtitle {
    font-size: 15px;
  }

  .search-container {
    padding: 24px;
  }

  .search-field {
    height: 52px;
    font-size: 16px;
  }

  .search-meta {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  /* Mobile table styles */
  .page-container {
    width: 100%;
    margin: 12px 0 20px;
    padding: 0;
  }

  .table-card, .page-card {
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
  }

  main.page-card.tabelas {
    min-width: 600px;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 6px 8px;
  }

  .data-table th {
    font-size: 12px;
    white-space: nowrap;
  }

  .sticky-header {
    padding-top: 70px;
  }

  .sticky-title h1 {
    font-size: 22px;
    padding-right: 50px;
  }

  .toc-toggle {
    display: block;
  }

  .table-of-contents {
    display: none;
    position: fixed;
    top: 80px;
    right: 10px;
    left: 10px;
    max-width: 400px;
    margin: 0 auto;
    animation: slideDown 0.3s ease;
  }

  .table-of-contents.toc-open {
    display: block;
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .toc-links {
    flex-direction: column;
  }

  .toc-link {
    width: 100%;
  }

  .accordion-section {
    scroll-margin-top: 120px;
  }

  .table-chat-fab {
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
  }

  .table-chat-panel {
    width: calc(100vw - 24px);
    height: 400px;
  }

  .sx3-hint {
    display: none;
  }
}
