* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;

    /* ✅ Let Wix control the background behind the iframe */
    background: transparent !important;
    background-color: transparent !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;

    /* ✅ Remove the app’s own background so Wix shows through */
    background: transparent !important;
    background-color: transparent !important;

    min-height: 100vh;
    padding: 20px;
    color: #e0e0e0;
}

.container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    height: 100%;
    display: flex;
    flex-direction: column;

    /* ✅ Ensure wrapper does not paint its own background */
    background: transparent;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #ffffff;
    font-size: clamp(1.5em, 4vw, 2.5em);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

h2 {
    color: #ffffff;
    margin-bottom: 15px;
    font-size: clamp(1.2em, 2.5vw, 1.5em);
}

/* Main content container - vertical layout (chat on top, table below) */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;

    /* ✅ Ensure no painted background */
    background: transparent;
}

/* Table Container */
.table-container {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: visible;
    position: relative;
    order: 2; /* Table appears below chat */
    min-height: 600px; /* Make table taller */
    height: auto; /* Allow container to expand with content */
}

/* Table header controls */
.table-header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 15px;
}

.clear-all-filters-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #ffffff;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.clear-all-filters-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.clear-all-filters-btn:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .table-header-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .clear-all-filters-btn {
        width: 100%;
    }
}

.table-wrapper {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    min-height: 500px;
    position: relative;
    max-height: calc(100vh - 450px);
}

/* Loading overlay */
.table-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: #b0b0b0;
}

.table-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

table {
    width: auto;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    overflow: hidden;
    font-size: clamp(0.75em, 1.2vw, 1em);
    position: relative;
    table-layout: auto;
}

/* Ensure table body doesn't show through header */
table tbody {
    background: rgba(255, 255, 255, 0.03);
    position: relative;
    z-index: 1;
}

table thead {
    position: sticky;
    top: 0;
    z-index: 100;
    background: transparent !important;
}

table tbody {
    display: table-row-group;
}

table thead tr,
table tbody tr {
    display: table-row;
}

.table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

thead {
    position: sticky;
    top: 0;
    z-index: 100;
    background: transparent !important;
}

thead tr {
    position: sticky;
    top: 0;
    z-index: 100;
    background: transparent !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
}

th {
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    color: #ffffff;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    position: sticky !important;
    top: 0 !important;
    /* Use solid background that matches the theme - slightly transparent */
    background: rgba(45, 45, 68, 0.85) !important;
    background-color: rgba(45, 45, 68, 0.85) !important;
    backdrop-filter: blur(10px) !important;
    z-index: 100 !important;
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.1);
    overflow: visible;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    width: auto;
    min-width: 60px;
    max-width: 200px;
    line-height: 1.4;
    vertical-align: top;
    /* Ensure background stays with sticky element */
    isolation: isolate;
    /* Force hardware acceleration and proper rendering */
    transform: translateZ(0);
    will-change: transform;
    /* Ensure background is painted on the sticky element */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.th-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.th-content span {
    flex: 1;
    min-width: 0;
    word-break: break-word;
    line-height: 1.3;
}

.filter-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
}

.filter-btn.sorted-asc,
.filter-btn.sorted-desc {
    color: #667eea;
    opacity: 1;
}

.filter-btn svg {
    width: 12px;
    height: 12px;
}

/* Filter Dropdown */
.filter-dropdown {
    position: fixed !important;
    background: rgba(30, 30, 46, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 10000;
    display: none;
    min-width: 200px;
    max-width: 300px;
    max-height: 400px;
    height: auto;
    overflow: visible;
    box-sizing: border-box;
    flex-direction: column;
    /* Ensure it's not affected by parent positioning */
    transform: none;
    margin: 0;
}

.filter-dropdown.active {
    display: flex;
    animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.filter-dropdown::-webkit-scrollbar {
    width: 6px;
}

.filter-dropdown::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.filter-dropdown::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

/* Filter Search */
.filter-search {
    margin-bottom: 12px;
}

.filter-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #ffffff;
    font-size: 0.9em;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.filter-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(102, 126, 234, 0.5);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.filter-input::placeholder {
    color: #888;
}

/* Filter Options */
.filter-options {
    max-height: 200px;
    min-height: 50px;
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.filter-option {
    display: flex;
    align-items: center;
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s ease;
    user-select: none;
}

.filter-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

.filter-checkbox {
    margin-right: 8px;
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: #667eea;
}

.filter-option span {
    color: #e0e0e0;
    font-size: 0.9em;
    flex: 1;
}

/* Filter Actions */
.filter-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.sort-btn,
.clear-filter-btn {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.sort-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.4);
    color: #ffffff;
}

.clear-filter-btn {
    background: rgba(255, 100, 100, 0.1);
    border-color: rgba(255, 100, 100, 0.2);
    color: #ffaaaa;
}

.clear-filter-btn:hover {
    background: rgba(255, 100, 100, 0.2);
    border-color: rgba(255, 100, 100, 0.4);
    color: #ffffff;
}

td {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
    transition: background 0.2s ease;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Chat Container */
.chat-container {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-height: 300px;
    max-height: 400px;
    min-width: 0;
    order: 1; /* Chat appears first (on top) */
    min-height: 500px;
}

.chat-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header p {
    color: #b0b0b0;
    font-size: 0.9em;
    margin-top: 5px;
}

.api-key-input {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.api-key-input input {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #ffffff;
    font-size: 0.85em;
    outline: none;
}

.api-key-input input:focus {
    border-color: rgba(102, 126, 234, 0.5);
}

.api-key-input button {
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-size: 0.85em;
    cursor: pointer;
    font-weight: 600;
}

.api-key-input button:hover {
    opacity: 0.9;
}

.api-key-toggle {
    transition: all 0.2s ease;
}

.api-key-toggle:hover {
    background: rgba(255, 255, 255, 0.15) !important;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px 0;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    justify-content: flex-end;
}

.bot-message {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
}

/* Formatting styles for AI responses */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    color: inherit;
}

.message-content h1 {
    font-size: 1.3em;
}

.message-content h2 {
    font-size: 1.2em;
}

.message-content h3 {
    font-size: 1.1em;
}

.message-content p {
    margin: 8px 0;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
    line-height: 1.6;
}

.message-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.bot-message .message-content {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-input-container {
    display: flex;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#chatInput {
    flex: 1;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    color: #ffffff;
    font-size: 1em;
    outline: none;
    transition: all 0.3s ease;
}

#chatInput:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

#chatInput::placeholder {
    color: #888;
}

#sendButton {
    padding: 15px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 25px;
    color: #ffffff;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

#sendButton:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

#sendButton:active {
    transform: translateY(0);
}

#sendButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 1s ease-in-out infinite;
}

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

/* Responsive Design */
@media (max-width: 968px) {
    body {
        padding: 15px;
    }

    .main-content {
        flex-direction: column;
        gap: 15px;
    }

    .table-container {
        min-height: 300px;
    }

    .chat-container {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        margin-bottom: 15px;
    }

    .main-content {
        gap: 15px;
    }

    .table-container,
    .chat-container {
        padding: 15px;
        border-radius: 15px;
    }

    .table-container {
        min-height: 250px;
    }

    .chat-container {
        min-height: 350px;
    }

    .message-content {
        max-width: 85%;
        font-size: 0.9em;
    }

    th, td {
        padding: 8px 10px;
        font-size: 0.85em;
    }

    #chatInput {
        padding: 12px 15px;
        font-size: 0.9em;
    }

    #sendButton {
        padding: 12px 20px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .table-container {
        min-height: 200px;
    }

    .chat-container {
        min-height: 300px;
    }

    th, td {
        padding: 6px 8px;
        font-size: 0.75em;
    }

    h2 {
        font-size: 1.1em;
        margin-bottom: 10px;
    }

    .filter-dropdown {
        min-width: 180px;
        max-height: 250px;
    }

    .th-content {
        gap: 4px;
    }

    .filter-btn {
        padding: 2px;
    }

    .filter-btn svg {
        width: 10px;
        height: 10px;
    }
}
/* ============================================================
   Mobile improvements
   ============================================================ */

/* Let Wix control the page background */
html, body {
  background: transparent !important;
}

/* On small screens, reduce padding + make cards flatter */
@media (max-width: 768px) {
  body { padding: 10px; }

  .table-container,
  .chat-container {
    padding: 12px;
    border-radius: 12px;
  }

  /* Make chat shorter on mobile so table isn't pushed too far down */
  .chat-container {
    max-height: none;
    min-height: 340px;
  }

  /* IMPORTANT: make the table feel like a scrollable "sheet" */
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto !important;
    overflow-y: auto !important;
    max-height: 60vh;
    border-radius: 10px;
  }

  /* Keep the BIG table readable on phones: scroll instead of squish */
  table {
    min-width: 900px;
    table-layout: auto;
  }

  th, td {
    white-space: nowrap !important;
    font-size: 0.85em;
  }

  /* Make filter dropdown fit on phone screens */
  .filter-dropdown {
    max-width: calc(100vw - 24px);
    min-width: min(280px, calc(100vw - 24px));
  }
}

/* Even smaller phones */
@media (max-width: 480px) {
  table { min-width: 1000px; }
  th, td { font-size: 0.8em; }
}

/* ============================================================
   Bot message formatting (Markdown)
   ============================================================ */

/* Keep bubbles from stretching due to wide content */
.message-content {
  max-width: 100%;
  min-width: 0;
}

.bot-message {
  min-width: 0;
}

.bot-message .message-content {
  width: 100%;
  max-width: 100%;
  overflow: hidden;     /* bubble clips; inner wrappers handle scroll */
  white-space: normal;  /* allow markdown HTML to wrap normally */
}

/* Inline code + code blocks */
.bot-message .message-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.bot-message .message-content pre {
  overflow-x: auto;
  padding: 12px;
  border-radius: 8px;
  background: rgba(0,0,0,0.25);
}

/* ============================================================
   Chat tables (Markdown) — scroll inside bubble + aligned header/body
   Requires app.js wrapping tables in: <div class="table-scroll">...</div>
   ============================================================ */

.bot-message .message-content .table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  padding-bottom: 6px; /* space for scrollbar */
}

/* Restore real table behavior so columns align */
.bot-message .message-content .table-scroll table {
  display: table !important;
  width: max-content !important;  /* keep natural width; wrapper scrolls */
  max-width: none;
  border-collapse: collapse;
  table-layout: auto !important;
  font-size: 0.85em;
}

/* Make sure browser uses native table groups (prevents header drift) */
.bot-message .message-content .table-scroll thead { display: table-header-group !important; }
.bot-message .message-content .table-scroll tbody { display: table-row-group !important; }
.bot-message .message-content .table-scroll tr    { display: table-row !important; }

.bot-message .message-content .table-scroll th,
.bot-message .message-content .table-scroll td {
  border: 1px solid rgba(255,255,255,0.15);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

/* Optional: nicer horizontal scrollbar for chat tables */
.bot-message .message-content .table-scroll::-webkit-scrollbar {
  height: 6px;
}
.bot-message .message-content .table-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 6px;
}
.bot-message .message-content .table-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
}
