/* =========================================================
   GLOBAL
========================================================= */
html, body {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* =========================================================
   TOPBAR
========================================================= */
.topbar {
    height: 50px;
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 15px;
    gap: 10px;
    flex-shrink: 0;
}

.btn {
    background: #3b82f6;
    border: none;
    color: #fff;
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

/* =========================================================
   TABS
========================================================= */
.tabs {
    height: 40px;
    background: #0f172a;
    color: white;
    display: flex;
    align-items: center;
    padding: 5px 8px;
    gap: 6px;
    overflow-x: auto;
    flex-shrink: 0;
}

.tab {
    background: #334155;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: 0.2s ease;
}

.tab:hover {
    background: #475569;
}

.tab.active {
    background: #3b82f6;
}

/* =========================================================
   MAIN LAYOUT
========================================================= */
.main {
    display: flex;
    height: calc(100vh - 90px); /* topbar (50) + tabs (40) */
    min-height: 0;
}
/* =========================================================
   FORMAT / CONTROL PANE
========================================================= */
.format {
    width: 360px;
    min-width: 280px;
    max-width: 900px;
    resize: horizontal;
    overflow: auto;
    background: #f8fafc;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 0;
    transition: all 0.25s ease;
}

.format.closed {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    border: none !important;
    overflow: hidden !important;
    resize: none !important;
}

.formatHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 12px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
    font-weight: 600;
    color: #0f172a;
}

.formatHeader button {
    border: none;
    background: #ef4444;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    padding: 5px 10px;
    font-size: 12px;
}

.paneTabs {
    display: flex;
    gap: 6px;
    padding: 10px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.paneTabs button {
    flex: 1;
    min-width: 70px;
    border: none;
    background: #e2e8f0;
    padding: 7px 8px;
    border-radius: 8px;
    cursor: pointer;
    color: #111827;
    font-size: 12px;
    font-weight: 600;
    transition: 0.2s ease;
}

.paneTabs button:hover {
    background: #cbd5e1;
}

.paneTabs button.active {
    background: #3b82f6;
    color: white;
}

.formatBody {
    flex: 1;
    min-height: 0;
    overflow-y: auto;  /* 🔥 critical */
}

#pane {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    padding: 0 10px 10px 10px;
    min-width: 0;
}

/* =========================================================
   DETAILS / COLLAPSIBLE UI
========================================================= */
.details-card,
.sub-details {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.details-card summary,
.sub-details summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 13px;
    color: #0f172a;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    user-select: none;
    transition: background 0.2s ease;
}

.details-card summary:hover,
.sub-details summary:hover {
    background: #f1f5f9;
}

.details-card summary::-webkit-details-marker,
.sub-details summary::-webkit-details-marker {
    display: none;
}

.details-card summary::after,
.sub-details summary::after {
    content: "▾";
    float: right;
    color: #64748b;
    transition: transform 0.2s ease;
}

details:not([open]) summary::after {
    transform: rotate(-90deg);
}

.details-body {
    padding: 12px;
    min-width: 0;
}

.details-body-shelves {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, auto);
    gap: 12px;
}

/* =========================================================
   COMPACT GRID HELPERS
========================================================= */
.compact-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 10px;
}

.compact-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 10px;
}

.compact-grid-4 {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 10px;
}

.compact-grid-query {
    display: grid;
    grid-template-columns: 1fr 100px;
    gap: 10px;
    align-items: end;
}

.full-span {
    grid-column: 1 / -1;
}

.btn-group-bottom {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* =========================================================
   FORM UI
========================================================= */
.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.form-group label {
    font-size: 12px;
    color: #475569;
    font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea,
textarea {
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    background: #fff;
    outline: none;
    transition: 0.18s ease;
    width: 100%;
    min-width: 0;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.inline-inputs {
    display: flex;
    gap: 8px;
}

.inline-inputs input {
    flex: 1;
}

.inline-inputs select {
    width: 72px;
    flex-shrink: 0;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #334155;
    font-weight: 500;
    margin-top: 2px;
}

.checkbox-row input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px;
}

.primary-btn {
    background: #2563eb;
    color: white;
    border: none;
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.18s ease;
}

.primary-btn:hover {
    background: #1d4ed8;
}

.sql-box {
    width: 100%;
    min-height: 160px;
    resize: vertical;
    font-family: Consolas, monospace;
}

/* =========================================================
   WORKSPACE
========================================================= */
.workspace {
    flex: 1;
    min-height: 0;
    overflow: auto;   /* THIS enables scroll */
}

/* =========================================================
   DASHBOARD
========================================================= */
.dashboard {
    display: none;
    background: white;
    padding: 15px;
    border-radius: 10px;
    border: 2px solid #94a3b8;
    width: max-content;
    min-width: 100%;
    min-height: 100%;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 12px;
    overflow: visible;
}

.dashboard.active {
    display: flex;
}

/* =========================================================
   FIELDS / SHELVES
========================================================= */
.field-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.field {
    padding: 6px 10px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    cursor: grab;
    font-size: 12px;
    font-weight: 600;
    user-select: none;
    transition: 0.18s ease;
}

.field:hover {
    background: #dbeafe;
}

.shelf {
    min-width: 0;
}

.shelf-title {
    font-size: 12px;
    color: #334155;
    margin-bottom: 6px;
    font-weight: 700;
}

.shelf-drop {
    min-height: 90px;
    max-height: 90px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px dashed #94a3b8;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-radius: 10px;
    background: #fff;
    align-content: flex-start;
    transition: 0.18s ease;
}

.shelf-drop:hover {
    background: #f8fafc;
    border-color: #64748b;
}

.field-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 9px;
    background: #dbeafe;
    border-radius: 999px;
    cursor: grab;
    font-size: 12px;
    white-space: nowrap;
    border: 1px solid #93c5fd;
    user-select: none;
    color: #1e3a8a;
    font-weight: 600;
}

.pill-label {
    cursor: pointer;
}

.pill-close {
    font-size: 11px;
    color: #ef4444;
    cursor: pointer;
    font-weight: bold;
    line-height: 1;
}

.pill-close:hover {
    transform: scale(1.1);
}

/* ============= Data source fields list ======== */
#fieldsPanel {
    min-height:0px;
    max-height: 200px;
    overflow-y: auto;
}
/* =========================================================
   SHEETS
========================================================= */
.sheet {
    background: white;
    display: flex;
    flex-direction: column;
    min-width: 320px;
    min-height: 260px;
    border-radius: 0px;
    overflow: hidden;
    flex-shrink: 0;
    transition: 0.18s ease;
}

.sheet.selected {
    border: 1px solid red;
}

.sheet-header {
    padding: 0px 0px 0px 0px;
    border-bottom: 1px solid #eee;
    font-weight: bold;
    flex-shrink: 0;
    background: #e6e6e6;
    white-space: pre-line;
}

.sheet-body {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0px 0px 0px 0px;
}

.sheet-scroll-area,
.chart-scroll-area {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: auto;
}

.sheet-legend {
    margin-top: 0px;
    padding: 8px 0px 8px 0px;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    background: #ffffff;
    flex-shrink: 0;
    border-radius: 0px 0px 0 0;
}

/* =========================================================
   TABLE
========================================================= */
.bi-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    background: #ffffff;
}

.bi-table th {
    background: #f3f4f6;
    color: #111827;
    font-weight: 600;
    text-align: center;
    border: 1px solid #e5e7eb;
    padding: 8px;
    white-space: nowrap;
}

.bi-table td {
    border: 1px solid #e5e7eb;
    padding: 8px;
    color: #374151;
    white-space: nowrap;
}

.bi-table tr:nth-child(even) {
    background: #fafafa;
}

.bi-table tr:hover {
    background: #f1f5f9;
}

.bi-table td:first-child {
    font-weight: 500;
    color: #111827;
}

.bi-table tr:first-child th {
    background: #e5e7eb;
    font-weight: 600;
}

/* =========================================================
   LEGEND / PREVIEW / FORMAT HELPERS
========================================================= */
.legend-preview-box {
    margin-top: 2px;
    padding: 10px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
}

.legend-preview-inline {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.legend-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #334155;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid #ccc;
}

.legend-editor-grid input[type="text"],
.legend-editor-grid input[type="number"],
.legend-editor-grid input[type="color"] {
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12px;
    background: #fff;
}

.legend-edit-row {
    display: grid;
    grid-template-columns: 1fr 48px 100px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.diverging-grid {
    display: grid;
    grid-template-columns: 1fr 56px 90px;
    gap: 8px;
    align-items: center;
}

.format-block {
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}

.format-block h4 {
    margin: 0 0 10px;
}

/* =========================================================
   SHEETS TAB
========================================================= */
.sheetRow {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.sheetRow input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
}

/* =========================================================
   GENERIC BUTTONS
========================================================= */
button {
    cursor: pointer;
    border: none;
    border-radius: 6px;
    padding: 7px 12px;
    background: #3b82f6;
    color: white;
    transition: 0.18s ease;
}

button:hover {
    opacity: 0.95;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 12px 0;
}

/* =========================================================
   SCROLLBARS
========================================================= */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

::-webkit-scrollbar-track {
    background: #f8fafc;
}
/* =========================================================
   CELL SIZE TABLE
========================================================= */
.bi-table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}

.bi-table th,
.bi-table td {
    border: 1px solid #e2e8f0;
    padding: 8px 10px;
    vertical-align: top;
}

/* =========================================================
   STICKY FIELDS SECTION
========================================================= */
.sticky-fields-card {
    position: sticky;
    top: 0;
    z-index: 30;
    background: #f8fafc;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    margin-top: 0;
}

.sticky-fields-card summary {
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 31;
}

.sticky-fields-card .details-body {
    max-height: 180px;
    overflow-y: auto;
    overflow-x: hidden;
}
/* =========================================================
   PARAMETER MODAL
========================================================= */
.parameter-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.parameter-modal.hidden {
    display: none;
}

.parameter-modal-content {
    width: 520px;
    max-width: 90vw;
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}

.param-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.param-table th,
.param-table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

.param-table th {
    background: #f6f6f6;
    font-weight: 600;
}

.param-value-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    outline: none;
    box-sizing: border-box;
}

.param-delete-row {
    width: 100%;
    padding: 8px;
    border: none;
    background: #f3f3f3;
    border-radius: 6px;
    cursor: pointer;
}

.param-delete-row:hover {
    background: #e5e5e5;
}
/* ========================================================
  ===============Popup checkbox alignment=============== */
#filterValuesContainer label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    padding: 2px 0;
    cursor: pointer;
}

#filterValuesContainer input[type="checkbox"],
#filterValuesContainer input[type="radio"] {
    width: 16px;
    height: 16px;
    margin: 0;
}

/* Better dropdown */
#filterValuesContainer select {
    width: 100%;
    padding: 6px;
    border-radius: 6px;
}

.popup-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 2px;
    cursor: pointer;
}

.popup-row:hover {
    background: #f1f5f9;
    border-radius: 6px;
}


#filterValuesContainer {
    max-height: 220px;
    overflow-y: auto;
}

.multi-dropdown {
    position: relative;
    width: 100%;
}

.dropdown-display {
    border: 1px solid #cbd5e1;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
}

.dropdown-panel {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 220px;
    overflow-y: auto;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    margin-top: 4px;
    padding: 8px;
    z-index: 1000;
}

.hidden {
    display: none;
}
.filter-summary-popup {
    font-size: 12px;
    color: #475569;
    margin-bottom: 6px;
    font-weight: 600;
}
/* =============== Filters UI ============== */
.dashboard-filters {
    display: flex;
    gap: 8px;
    margin-left: 20px;
    flex-wrap: wrap;
}

.dashboard-filter-pill {
    background: #f1f3f5;
    border: 1px solid #ccc;
    padding: 4px 10px;
    border-radius: 14px;
    cursor: pointer;
    font-size: 13px;
}

.dashboard-filter-pill:hover {
    background: #e2e6ea;
}

/* ==================== Objects ===================== */
.objects-panel {
    display: flex;
    flex-direction: column;
    max-height:300px;
    overflow-y:auto;
}

/* Tableau-like blocks */
.object-item {
    display: flex;
    align-items: center;

    border: 1px solid #e6e6e6;
    height: 30px;
    cursor: pointer;

    background: #f8fafc;
    transition: all 0.2s ease;
}

/* Hover feel */
.object-item:hover {
    border-color: #2563eb;
    background: #eef2ff;
}

/* Icon */
.object-icon {
    font-size: 16px;
    width: 24px;
    text-align: left;
}

/* Label */
.object-label {
    font-size: 13px;
    color: #000000;
}

/* =========================================================
   RESPONSIVE
========================================================= */
@media (max-width: 1200px) {
    .details-body-shelves {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .compact-grid-4 {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }
}

@media (max-width: 760px) {
    .details-body-shelves,
    .compact-grid,
    .compact-grid-2,
    .compact-grid-4,
    .compact-grid-query {
        grid-template-columns: 1fr;
    }
}