/* KivTools data workbench — local-first data shaping tools. */
.kiv-data-tool {
    --dw-ink: #20352d;
    --dw-muted: #64776f;
    --dw-line: #dce8e2;
    --dw-surface: #ffffff;
    --dw-subtle: #f4f8f6;
    --dw-accent: #0aa36c;
    --dw-accent-strong: #087c54;
    --dw-blue: #2f6fed;
    color: var(--dw-ink);
    padding-bottom: 28px;
}

.kiv-data-tool .tool-intro { margin: 24px 0 16px; }
.kiv-data-tool .tool-intro h1 { margin: 0 0 8px; font-size: clamp(25px, 2.2vw, 34px); line-height: 1.18; letter-spacing: -.025em; }
.kiv-data-tool .tool-intro p { max-width: 920px; margin: 0; color: var(--dw-muted); font-size: 15px; line-height: 1.65; }

.dw-tabs {
    display: flex;
    gap: 4px;
    margin: 18px 0 0;
    padding: 6px;
    overflow-x: auto;
    background: var(--dw-subtle);
    border-radius: 12px;
    scrollbar-width: thin;
}
.dw-tabs > li { float: none; margin: 0; flex: 0 0 auto; }
.dw-tabs > li > a { margin: 0; padding: 9px 13px; border: 0 !important; border-radius: 8px; color: #52675e; font-weight: 600; white-space: nowrap; }
.dw-tabs > li > a:hover { background: rgba(10,163,108,.08); color: var(--dw-accent-strong); }
.dw-tabs > li.active > a,
.dw-tabs > li.active > a:hover,
.dw-tabs > li.active > a:focus { background: var(--dw-surface); color: var(--dw-accent-strong); box-shadow: 0 2px 8px rgba(24,63,46,.09); }

/* SQL Formatter needs a true two-pane workbench. The generic focus layout
 * otherwise narrows this surface to 940px and clips Bootstrap dropdowns. */
body.kiv-tool-layout-focus .kiv-data-tool[data-dw-tool="formatsql"],
body.kiv-tool-layout-focus .kiv-data-tool[data-dw-tool="formatsql"].kiv-contextual-nav-root,
body.kiv-tool-layout-focus .kiv-data-tool[data-dw-tool="formatsql"].kiv-adaptive-primary-surface {
    width: min(100%, 1300px) !important;
    max-width: 1300px;
}

.kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs {
    overflow: visible;
}

.kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs > li.dropdown {
    position: relative;
}

.kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs .dropdown-menu {
    z-index: 1100;
    margin-top: 6px;
    border: 0;
    border-radius: 9px;
    background: var(--dw-surface);
    box-shadow: 0 14px 34px rgba(24, 55, 42, .16), 0 0 0 1px rgba(109, 145, 130, .16);
}

.kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs .dropdown-menu > li > a {
    padding: 8px 12px;
    color: var(--dw-ink);
}

.kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs .dropdown-menu > li > a:hover,
.kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs .dropdown-menu > li > a:focus {
    background: var(--dw-subtle);
    color: var(--dw-accent-strong);
}

.dw-pipeline {
    display: grid;
    grid-template-columns: auto minmax(24px, 1fr) auto minmax(24px, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin: 0 0 18px;
    padding: 10px 14px;
    color: var(--dw-muted);
    background: linear-gradient(90deg, rgba(10,163,108,.07), rgba(47,111,237,.04));
    border-radius: 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.dw-pipeline-node { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.dw-pipeline-node i { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--dw-accent); color: #fff; font-style: normal; font-size: 11px; }
.dw-pipeline-line { height: 1px; background: linear-gradient(90deg, rgba(10,163,108,.55), rgba(47,111,237,.25)); }

.dw-privacy {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -8px 0 18px;
    color: #527066;
    font-size: 12px;
}
.dw-privacy .glyphicon { color: var(--dw-accent); }

.dw-status { display: none; margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.dw-status.is-visible { display: block; }
.dw-status.is-ok { color: #17613f; background: #eaf8f1; }
.dw-status.is-error { color: #912f39; background: #fff0f1; }

.dw-layout { display: grid; gap: 16px; align-items: start; }
.dw-layout--split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.dw-layout--inspector { grid-template-columns: minmax(300px, .78fr) minmax(0, 1.22fr); }
.dw-layout--triple { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dw-stack { display: grid; gap: 16px; }

.dw-card {
    min-width: 0;
    overflow: hidden;
    background: var(--dw-surface);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(30,64,50,.075), 0 0 0 1px rgba(109,145,130,.14);
}
.dw-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    padding: 11px 14px;
    background: var(--dw-subtle);
}
.dw-card-head > span:first-child { font-weight: 700; }
.dw-card-head small { color: var(--dw-muted); font-weight: 500; }
.dw-card-body { padding: 14px; }
.dw-card--accent .dw-card-head { box-shadow: inset 3px 0 0 var(--dw-accent); }

.dw-editor,
.dw-output {
    width: 100%;
    min-height: 330px;
    resize: vertical;
    padding: 13px 14px;
    border: 0;
    border-radius: 8px;
    outline: 0;
    background: #f7faf8;
    color: #24372f;
    box-shadow: inset 0 0 0 1px var(--dw-line);
    font: 13px/1.62 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    tab-size: 2;
}
.dw-editor:focus { box-shadow: inset 0 0 0 2px rgba(10,163,108,.55), 0 0 0 3px rgba(10,163,108,.08); }
.dw-output { display: block; margin: 0; white-space: pre-wrap; overflow: auto; resize: vertical; }
.dw-output.is-empty { color: #89968f; }
.dw-editor--compact { min-height: 205px; }
.dw-editor--merge { min-height: 245px; }

.dw-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.dw-field { display: grid; gap: 5px; min-width: 138px; margin: 0; color: var(--dw-muted); font-size: 12px; font-weight: 600; }
.dw-field--grow { flex: 1 1 220px; }
.dw-field input,
.dw-field select { height: 38px; padding: 7px 10px; border: 0; border-radius: 7px; background: #f7faf8; color: var(--dw-ink); box-shadow: inset 0 0 0 1px var(--dw-line); }
.dw-check { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; margin: 0; color: var(--dw-muted); font-size: 12px; font-weight: 600; }

.dw-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.kiv-data-tool .btn { border-radius: 7px; border-width: 0; box-shadow: inset 0 0 0 1px rgba(98,124,113,.26); font-weight: 650; }
.kiv-data-tool .btn-primary,
.kiv-data-tool .btn-success { background: var(--dw-accent); color: #fff; box-shadow: none; }
.kiv-data-tool .btn-primary:hover,
.kiv-data-tool .btn-success:hover { background: var(--dw-accent-strong); }
.kiv-data-tool .btn-link { box-shadow: none; color: var(--dw-accent-strong); }

.dw-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.dw-metric { min-width: 0; padding: 10px; background: var(--dw-subtle); border-radius: 8px; }
.dw-metric b { display: block; overflow: hidden; color: var(--dw-ink); font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }
.dw-metric span { color: var(--dw-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

.dw-token-list,
.dw-findings { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.dw-token-list li,
.dw-findings li { padding: 8px 10px; border-radius: 7px; background: var(--dw-subtle); color: var(--dw-muted); font-size: 12px; }
.dw-token-list code { color: var(--dw-accent-strong); background: transparent; }

.dw-table-wrap { overflow: auto; max-height: 520px; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--dw-line); }
.dw-table { width: 100%; margin: 0; border-collapse: collapse; font-size: 12px; }
.dw-table th { position: sticky; top: 0; z-index: 1; padding: 10px; background: #edf5f1; color: #3d5c4f; text-align: left; white-space: nowrap; }
.dw-table td { padding: 9px 10px; border-top: 1px solid var(--dw-line); vertical-align: top; }
.dw-table td code { color: #245d48; background: rgba(10,163,108,.06); }
.dw-table-empty { padding: 28px !important; color: var(--dw-muted); text-align: center; }

.dw-file { position: relative; overflow: hidden; }
.dw-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dw-conflict { margin-top: 8px; padding: 10px; border-left: 3px solid #d89025; background: #fff8e9; color: #70501f; border-radius: 0 7px 7px 0; font-size: 12px; }

html.kiv-shell-dark .kiv-data-tool,
html[data-theme="dark"] .kiv-data-tool,
body.dark-mode .kiv-data-tool,
body.kiv-dark .kiv-data-tool {
    --dw-ink: #e6f1ec;
    --dw-muted: #9fb3aa;
    --dw-line: #30483e;
    --dw-surface: #16261f;
    --dw-subtle: #1b3027;
    --dw-accent: #38c98c;
    --dw-accent-strong: #77e0b1;
}
html.kiv-shell-dark .kiv-data-tool .dw-editor,
html.kiv-shell-dark .kiv-data-tool .dw-output,
html.kiv-shell-dark .kiv-data-tool .dw-field input,
html.kiv-shell-dark .kiv-data-tool .dw-field select,
html[data-theme="dark"] .kiv-data-tool .dw-editor,
html[data-theme="dark"] .kiv-data-tool .dw-output,
html[data-theme="dark"] .kiv-data-tool .dw-field input,
html[data-theme="dark"] .kiv-data-tool .dw-field select,
body.dark-mode .kiv-data-tool .dw-editor,
body.dark-mode .kiv-data-tool .dw-output,
body.dark-mode .kiv-data-tool .dw-field input,
body.dark-mode .kiv-data-tool .dw-field select { background: #102019; color: #e6f1ec; }
html.kiv-shell-dark .kiv-data-tool .dw-table th,
html[data-theme="dark"] .kiv-data-tool .dw-table th,
body.dark-mode .kiv-data-tool .dw-table th { background: #203a2f; color: #cbe3d8; }
html.kiv-shell-dark .kiv-data-tool .dw-conflict,
html[data-theme="dark"] .kiv-data-tool .dw-conflict,
body.dark-mode .kiv-data-tool .dw-conflict { background: #3a2d18; color: #f0d79e; }

@media (max-width: 991px) {
    .dw-layout--split,
    .dw-layout--inspector { grid-template-columns: 1fr; }
    .dw-layout--triple { grid-template-columns: 1fr; }
    .dw-editor--merge { min-height: 180px; }
}

@media (max-width: 600px) {
    .kiv-data-tool { padding-left: 10px; padding-right: 10px; }
    .kiv-data-tool .tool-intro { margin-top: 18px; }
    .kiv-data-tool .tool-intro h1 { font-size: 24px; }
    .dw-tabs { margin-left: -4px; margin-right: -4px; padding: 5px; border-radius: 9px; }
    .dw-tabs > li > a { padding: 8px 10px; font-size: 12px; }
    .kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs { flex-wrap: wrap; }
    .kiv-data-tool[data-dw-tool="formatsql"] .dw-tabs .dropdown-menu {
        right: 0;
        left: auto;
        min-width: 170px;
    }
    .dw-pipeline { grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 9px; }
    .dw-pipeline-line { display: none; }
    .dw-pipeline-node { justify-content: center; font-size: 10px; }
    .dw-pipeline-node i { width: 19px; height: 19px; }
    .dw-card-head { align-items: flex-start; padding: 10px 12px; }
    .dw-card-body { padding: 11px; }
    .dw-editor, .dw-output { min-height: 245px; font-size: 12px; }
    .dw-editor--compact, .dw-editor--merge { min-height: 170px; }
    .dw-controls { display: grid; grid-template-columns: 1fr 1fr; }
    .dw-field, .dw-field--grow { min-width: 0; }
    .dw-check { grid-column: 1 / -1; }
    .dw-toolbar .btn { flex: 1 1 auto; }
    .dw-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
