:root {
    --bg: #f6f5f2;
    --panel: #ffffff;
    --panel-soft: #fbfaf7;
    --line: #d7d3ca;
    --line-strong: #bdb7ab;
    --text: #211f1a;
    --text-soft: #68645b;
    --text-faint: #8e887c;
    --accent: #5b5448;
    --accent-soft: #eeebe4;
    --warn-bg: #f6f1e6;
    --warn-line: #d8c8a3;
    --error-bg: #f7ecea;
    --error-line: #d9b8b4;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    font-family: "Work Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    overflow: auto;
}

button,
input,
select {
    font: inherit;
}

#app {
    min-height: 100vh;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 0 1 220px;
}

.brand-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
}

.brand-subtitle {
    font-size: 9px;
    line-height: 1.3;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.topbar-controls {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
    flex-wrap: wrap;
    min-width: 0;
}

.control-stack {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.control-stack.search-stack {
    flex: 1 1 340px;
    max-width: 520px;
}

.control-label {
    font-size: 9px;
    line-height: 1.2;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.text-input,
.select-input,
.number-input {
    height: 32px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    padding: 0 10px;
    outline: none;
    min-width: 0;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.text-input:focus,
.select-input:focus,
.number-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(91, 84, 72, 0.1);
}

.text-input {
    width: 100%;
}

.number-input {
    width: 84px;
}

.file-input-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.file-name {
    font-size: 11px;
    line-height: 1.35;
    color: var(--text-soft);
    word-break: break-word;
    max-width: min(420px, 36vw);
}

.file-name.is-placeholder {
    color: var(--text-faint);
    font-style: italic;
}

.btn {
    height: 32px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--panel);
    color: var(--accent);
    padding: 0 12px;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.btn:disabled,
.text-input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: #4d463c;
    border-color: #4d463c;
}

.btn-small {
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.message {
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.45;
    background: var(--panel);
}

.message.warning {
    background: var(--warn-bg);
    border-color: var(--warn-line);
    color: #6c5d38;
}

.message.error {
    background: var(--error-bg);
    border-color: var(--error-line);
    color: #7d433f;
}

.section-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    overflow: hidden;
}

.section-toggle {
    width: 100%;
    border: none;
    border-bottom: 1px solid transparent;
    background: var(--panel);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    cursor: pointer;
    color: inherit;
}

.section-panel.is-open .section-toggle {
    border-bottom-color: var(--line);
    background: var(--panel-soft);
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

.section-inline {
    flex: 1;
    min-width: 0;
    font-size: 10px;
    line-height: 1.35;
    color: var(--text-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-icon {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-faint);
    width: 12px;
    text-align: center;
}

.section-body {
    display: none;
    padding: 10px;
}

.section-panel.is-open .section-body {
    display: block;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px 12px;
}

.summary-item {
    min-width: 0;
}

.summary-key {
    display: block;
    margin-bottom: 2px;
    font-size: 9px;
    line-height: 1.3;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.summary-value {
    display: block;
    font-size: 11px;
    line-height: 1.45;
    color: var(--text);
    word-break: break-word;
}

.metadata-wrap {
    max-height: 220px;
    overflow: auto;
    padding-right: 2px;
}

.metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px 12px;
}

.metadata-item {
    min-width: 0;
}

.metadata-key {
    display: block;
    margin-bottom: 2px;
    font-size: 9px;
    line-height: 1.3;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.metadata-value {
    display: block;
    font-size: 11px;
    line-height: 1.45;
    color: var(--text);
    word-break: break-word;
}

.content-shell {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.datasets-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.json-tree-wrap {
    padding: 2px 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas,
        monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
}

.json-tree-node {
    padding-left: 12px;
}

.json-tree-node details {
    margin: 0;
}

.json-tree-node summary {
    cursor: pointer;
    list-style: none;
    padding: 2px 10px 2px 0;
}

.json-tree-node summary::-webkit-details-marker {
    display: none;
}

.json-tree-node summary::before {
    content: "+";
    display: inline-block;
    width: 12px;
    margin-right: 6px;
    color: var(--text-faint);
}

.json-tree-node details[open] > summary::before {
    content: "-";
}

.json-tree-children {
    border-left: 1px solid #ece8df;
    margin-left: 5px;
    padding-left: 10px;
}

.json-tree-leaf {
    padding: 2px 10px 2px 18px;
    word-break: break-word;
}

.json-tree-key {
    color: var(--accent);
}

.json-tree-meta {
    color: var(--text-faint);
    font-size: 11px;
}

.json-tree-value {
    color: var(--text);
}

.json-tree-value.string {
    color: #5d4a2f;
}

.json-tree-value.number {
    color: #2f5c4d;
}

.json-tree-value.boolean,
.json-tree-value.null {
    color: #6c4a61;
}

.dataset-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    overflow: hidden;
}

.dataset-panel-header {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-soft);
}

.dataset-panel-title {
    margin: 0 0 2px;
    font-size: 13px;
    line-height: 1.3;
    font-weight: 600;
    color: var(--text);
}

.dataset-panel-subtitle {
    margin: 0;
    font-size: 11px;
    line-height: 1.35;
    color: var(--text-soft);
}

.dataset-table-wrap {
    position: relative;
}

.dataset-empty {
    padding: 16px 10px;
    font-size: 11px;
    line-height: 1.45;
    color: var(--text-soft);
}

.empty-state {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-soft);
    background: rgba(255, 255, 255, 0.72);
}

.empty-state.hidden {
    display: none;
}

.empty-state-hub {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.empty-state-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 28px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--panel);
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
    min-width: 180px;
    font: inherit;
    color: inherit;
}

.empty-state-card:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.empty-state-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.empty-state-card-desc {
    font-size: 11px;
    color: var(--text-soft);
    line-height: 1.4;
}

.empty-state-divider {
    font-size: 11px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.paste-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.paste-panel[hidden] {
    display: none;
}

.paste-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.paste-panel-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text);
}

.paste-textarea {
    width: 100%;
    min-height: 120px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    padding: 8px 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.45;
    resize: vertical;
    outline: none;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.paste-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(91, 84, 72, 0.1);
}

.paste-panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.topbar-divider {
    font-size: 10px;
    color: var(--text-faint);
}

.footer {
    margin-top: auto;
    border-top: 1px solid var(--line);
    padding: 8px 2px 2px;
}

.footer-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-soft);
}

.copyright {
    color: var(--text-soft);
}

.footer-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.footer-link {
    color: inherit;
    text-decoration: none;
}

.footer-link.is-disabled {
    pointer-events: none;
}

.footer-separator {
    color: var(--text-faint);
}

.footer code {
    font-family:
        ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 2px 6px;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(33, 31, 26, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.drawer-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(620px, 52vw);
    height: 100vh;
    background: var(--panel);
    border-left: 1px solid var(--line);
    transform: translateX(100%);
    transition: transform 0.18s ease;
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.settings-drawer.is-open {
    transform: translateX(0);
}

.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(246, 245, 242, 0.72);
    backdrop-filter: blur(1.5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.14s ease;
    z-index: 40;
}

.loading-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.loading-panel {
    min-width: 240px;
    max-width: 320px;
    padding: 14px 16px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 24px rgba(33, 31, 26, 0.08);
}

.loading-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #d7d3ca;
    border-top-color: var(--accent);
    border-radius: 999px;
    flex-shrink: 0;
    animation: spinner-rotate 0.8s linear infinite;
}

.loading-title {
    margin: 0 0 2px;
    font-size: 11px;
    line-height: 1.3;
    font-weight: 600;
    color: var(--text);
}

.loading-detail {
    margin: 0;
    font-size: 10px;
    line-height: 1.4;
    color: var(--text-soft);
}

@keyframes spinner-rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.drawer-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--panel-soft);
}

.drawer-title-group {
    min-width: 0;
}

.drawer-title {
    margin: 0 0 2px;
    font-size: 13px;
    line-height: 1.3;
    font-weight: 600;
}

.drawer-subtitle {
    margin: 0;
    font-size: 9px;
    line-height: 1.35;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.drawer-body {
    padding: 10px 12px 14px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.drawer-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.drawer-section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.drawer-section-title {
    margin: 0;
    font-size: 11px;
    line-height: 1.35;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.drawer-note {
    font-size: 9px;
    line-height: 1.35;
    color: var(--text-faint);
}

.global-settings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    background: var(--panel-soft);
    font-size: 11px;
    line-height: 1.4;
}

.settings-select-inline {
    width: 82px;
    height: 28px;
    padding: 0 6px;
    font-size: 10px;
}

.settings-dataset {
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    background: var(--panel);
}

.settings-dataset-head {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-soft);
}

.settings-dataset-title {
    margin: 0 0 2px;
    font-size: 11px;
    line-height: 1.35;
    font-weight: 600;
}

.settings-dataset-meta {
    margin: 0;
    font-size: 10px;
    line-height: 1.35;
    color: var(--text-soft);
}

.settings-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.settings-table th,
.settings-table td {
    border-bottom: 1px solid var(--line);
    padding: 6px 8px;
    vertical-align: middle;
}

.settings-table tr:last-child td {
    border-bottom: none;
}

.settings-table th {
    font-size: 9px;
    line-height: 1.3;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    text-align: left;
    background: #fcfbf8;
}

.settings-col-name {
    width: 52%;
}

.settings-col-visibility {
    width: 12%;
    text-align: center;
}

.settings-col-type {
    width: 12%;
    text-align: center;
}

.settings-col-aggregation {
    width: 24%;
}

.settings-path {
    display: block;
    font-size: 10px;
    line-height: 1.35;
    color: var(--text);
    word-break: break-word;
}

.settings-type {
    display: inline-block;
    font-size: 9px;
    line-height: 1.2;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.settings-checkbox {
    accent-color: var(--accent);
}

.settings-select {
    width: 100%;
    height: 28px;
    font-size: 10px;
    padding: 0 6px;
}

.tabulator {
    border: none;
    font-family: "Work Sans", sans-serif;
    font-size: 13px;
    background: transparent;
}

.tabulator .tabulator-header {
    background: #3f392f;
    border-bottom: 1px solid #2f2a23;
}

.tabulator .tabulator-col {
    background: #3f392f;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.tabulator .tabulator-col-content {
    overflow: hidden;
}

.tabulator .tabulator-col-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fffdf9;
    font-size: 12px;
    font-weight: 700;
}

.tabulator .tabulator-col.tabulator-sortable:hover {
    background: #4c453a;
}

.tabulator .tabulator-header-filter input {
    height: 24px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
    font-size: 11px;
    padding: 0 6px;
}

.tabulator-row {
    background: #ffffff;
}

.tabulator-row.tabulator-row-even {
    background: #fbfaf8;
}

.tabulator-row:hover {
    background: #f2efe9 !important;
}

.tabulator-cell {
    border-right: 1px solid #f0eee9;
    padding: 7px 8px;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
}

.tabulator-footer {
    border-top: 1px solid var(--line);
    background: var(--panel-soft);
}

.tabulator-footer .tabulator-row {
    background: var(--panel-soft);
}

.tabulator-footer .tabulator-cell {
    color: var(--accent);
    font-weight: 600;
    border-right: 1px solid var(--line);
}

@media (max-width: 1100px) {
    .settings-drawer {
        width: min(680px, 78vw);
    }
}

@media (max-width: 900px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-controls {
        justify-content: flex-start;
    }

    .control-stack.search-stack {
        max-width: none;
    }

    .settings-drawer {
        width: 100%;
    }
}

@media (max-width: 640px) {
    #app {
        padding: 10px;
    }

    .section-inline {
        white-space: normal;
    }

    .metadata-grid,
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .file-name {
        max-width: 100%;
    }

    .empty-state-hub {
        flex-direction: column;
        gap: 12px;
    }

    .empty-state-card {
        min-width: 0;
        width: 100%;
    }
}
