:root {
    --ms-blue:        #2b579a;
    --ms-blue-hover:  #3a6abf;
    --ribbon-bg:      #f3f3f3;
    --ribbon-border:  #c8c8c8;
    --btn-hover:      #e5eef6;
    --btn-active:     #cce4f7;
    --btn-border-hover: #b0c9e0;
    --group-label:    #666;
    --sidebar-bg:     #f5f5f5;
    --sidebar-border: #e0e0e0;
    --font: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    overflow: hidden;
    font-family: var(--font);
    font-size: 12px;
    color: #1f1f1f;
    background: #a9a9a9;
}

#app {
    position: relative;
}

/* ─── RIBBON ─────────────────────────────────────────────────────────── */

#top-panel {
    background: var(--ribbon-bg);
    border-bottom: 2px solid var(--ms-blue);
    position: relative;
    user-select: none;
}

#ribbon-tabs {
    background: var(--ms-blue);
    display: flex;
    align-items: flex-end;
    height: 28px;
    padding: 0 8px;
    gap: 2px;
}

.ribbon-tab {
    color: rgba(255,255,255,0.82);
    padding: 5px 14px 4px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 3px 3px 0 0;
    transition: background 0.1s;
}

.ribbon-tab:hover {
    background: rgba(255,255,255,0.18);
    color: white;
}

.ribbon-tab-active {
    background: var(--ribbon-bg) !important;
    color: var(--ms-blue) !important;
    font-weight: 600;
}

#ribbon-body {
    display: flex;
    align-items: stretch;
    padding: 4px 4px 0;
}

/* ─── HELP PAGE (full-screen "Помощь" tab) ─────────────────────────── */

#help-page {
    position: absolute;
    left: 0;
    width: 100%;
    background: #fff;
    overflow-y: auto;
    box-sizing: border-box;
    padding: 28px 40px;
    z-index: 5;
}

.help-page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--ms-blue);
    margin: 0 0 20px;
}

.help-page-grid {
    columns: 340px;
    column-gap: 36px;
}

.help-page-block {
    break-inside: avoid;
    margin-bottom: 22px;
}

.help-page-block h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--ms-blue);
    margin: 0 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--ribbon-border);
}

.help-page-block ul {
    margin: 0;
    padding-left: 18px;
}

.help-page-block li {
    font-size: 13px;
    line-height: 1.6;
    color: #333;
    margin-bottom: 4px;
}

.help-page-block code {
    background: #eef2f8;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 12px;
    color: #1a3a6b;
}

/* ─── RIBBON GROUPS ─────────────────────────────────────────────────── */

.r-group {
    display: flex;
    flex-direction: column;
    padding: 0 4px;
    min-width: max-content;
}

.r-group-body {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 2px;
    padding-bottom: 4px;
}

.r-col {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    justify-content: center;
}

.r-row {
    display: flex;
    align-items: center;
    gap: 1px;
}

.r-group-label {
    font-size: 10px;
    color: var(--group-label);
    padding: 3px 4px 3px;
    border-top: 1px solid var(--ribbon-border);
    width: 100%;
    text-align: center;
    white-space: nowrap;
}

.r-divider {
    width: 1px;
    background: var(--ribbon-border);
    margin: 4px 3px 18px;
    align-self: stretch;
}

.r-sep-v {
    display: inline-block;
    width: 1px;
    height: 18px;
    background: var(--ribbon-border);
    margin: 0 4px;
}

/* ─── RIBBON BUTTONS ────────────────────────────────────────────────── */

#ribbon-body button {
    background: transparent;
    border: 1px solid transparent;
    padding: 3px 6px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 12px;
    color: #1f1f1f;
    border-radius: 2px;
    white-space: nowrap;
    line-height: 1.3;
    transition: background 0.08s, border-color 0.08s;
}

#ribbon-body button:hover {
    background: var(--btn-hover);
    border-color: var(--btn-border-hover);
}

#ribbon-body button:active {
    background: var(--btn-active);
    border-color: #5a9fd4;
}

.r-btn-lg {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center;
    padding: 5px 10px !important;
    height: 54px;
    gap: 3px;
    font-size: 11px !important;
    min-width: 48px;
}

.r-dropdown {
    position: relative;
}

.r-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1500;
    background: var(--panel-bg, #f3f3f3);
    border: 1px solid var(--btn-border, #adadad);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 180px;
    padding: 4px 0;
}

.r-dropdown-menu.open {
    display: block;
}

.r-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    font-size: 12px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.r-dropdown-item:hover:not(:disabled) {
    background: var(--btn-hover, #e5e5e5);
}

.r-dropdown-item:disabled {
    opacity: 0.4;
    cursor: default;
}

.r-dropdown-item .r-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.context-menu {
    display: none;
    position: fixed;
    z-index: 3000;
    background: var(--panel-bg, #f3f3f3);
    border: 1px solid var(--btn-border, #adadad);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 170px;
    padding: 4px 0;
}

.context-menu.open {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    font-size: 12px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.context-menu-item:hover:not(:disabled) {
    background: var(--btn-hover, #e5e5e5);
}

.context-menu-item:disabled {
    opacity: 0.4;
    cursor: default;
}

.context-menu-item .r-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.context-menu-divider {
    height: 1px;
    background: var(--btn-border, #adadad);
    margin: 4px 0;
}

#ribbon-body button[aria-pressed="true"] {
    background: var(--btn-active);
    border-color: var(--btn-border-hover);
    box-shadow: inset 0 0 0 1px var(--btn-border-hover);
    color: var(--ms-blue);
}

#ribbon-body .r-btn-lg[aria-pressed="true"] {
    font-weight: 600;
}

.r-icon {
    font-size: 22px;
    line-height: 1;
    display: block;
}

.r-icon-text {
    font-size: 24px;
    font-weight: 700;
    font-family: var(--font);
    color: var(--ms-blue);
}

/* ─── RIBBON SELECTS ────────────────────────────────────────────────── */

#ribbon-body select,
#font-size {
    font-family: var(--font);
    font-size: 12px;
    border: 1px solid var(--ribbon-border);
    background: white;
    padding: 3px 4px;
    border-radius: 2px;
    height: 24px;
    transition: border-color 0.1s;
}

#ribbon-body select {
    cursor: pointer;
}

#ribbon-body select:focus,
#font-size:focus {
    outline: none;
    border-color: #5a9fd4;
}

/* Same drawn arrow icon for both the font-family select and the font-size dropdown,
   so their styles match exactly instead of relying on the browser's native select arrow. */
.dropdown-arrow {
    display: inline-block;
    position: relative;
}

.dropdown-arrow::after {
    content: '';
    position: absolute;
    right: 6px;
    top: 50%;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #555;
    transform: translateY(-50%);
    pointer-events: none;
}

#font-family {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 16px;
}

.font-size-menu {
    min-width: 58px;
    max-height: 260px;
    overflow-y: auto;
}

.font-size-menu .r-dropdown-item {
    justify-content: center;
    padding: 5px 8px;
}

#font-family { width: 148px; }
#font-size   { width:  58px; padding-right: 16px; }

/* ─── LEFT PANEL ────────────────────────────────────────────────────── */

#left-panel {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    position: absolute;
    left: 0;
    overflow: hidden;
}

.side-header {
    background: var(--ms-blue);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 8px 14px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.side-tool {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--sidebar-border);
    padding: 10px 14px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 12px;
    color: #1f1f1f;
    text-align: left;
    transition: background 0.1s;
}

.side-tool:hover  { background: #e3e3e3; }
.side-tool:active { background: var(--btn-active); }

.side-icon {
    font-size: 15px;
    width: 20px;
    text-align: center;
    color: #c00000;
}

.side-tool-danger:hover { background: #fde7e7; }
.side-icon-danger       { color: #c00000; }

.page-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--sidebar-border);
}

.page-nav-btn {
    background: transparent;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--ms-blue);
    font-family: var(--font);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

.page-nav-btn:hover  { background: var(--btn-hover); }
.page-nav-btn:active { background: var(--btn-active); }

#page-indicator {
    font-size: 12px;
    color: #333;
    min-width: 36px;
    text-align: center;
    user-select: none;
}

/* ─── REPORT PARAMS ─────────────────────────────────────────────────── */

.report-params {
    padding: 8px 14px;
    border-bottom: 1px solid var(--sidebar-border);
}

.report-params-label {
    display: block;
    font-size: 11px;
    color: #555;
    margin-bottom: 4px;
}

/* ─── VARIABLES ─────────────────────────────────────────────────────── */

#var-list {
    overflow-y: auto;
    max-height: 180px;
}

.var-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 8px;
    font-size: 11px;
    border-bottom: 1px solid var(--sidebar-border);
    cursor: default;
    user-select: none;
}

.var-item:hover { background: #e3e3e3; }

.var-item-drag  { color: #aaa; margin-right: 4px; cursor: grab; flex-shrink: 0; }
.var-item-drag:active { cursor: grabbing; }
.var-item-name  { font-weight: 600; color: #1a3a6b; flex-shrink: 0; margin-right: 4px; }
.var-item-value { color: #555; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.var-item-del {
    background: transparent;
    border: none;
    color: #c00000;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    flex-shrink: 0;
}
.var-item-del:hover { color: #800000; }

#var-form {
    display: none;
    padding: 6px 8px;
    border-bottom: 1px solid var(--sidebar-border);
}

.var-input {
    width: 100%;
    box-sizing: border-box;
    font-size: 11px;
    padding: 3px 5px;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    margin-bottom: 4px;
    outline: none;
}
.var-input:focus { border-color: var(--ms-blue); }

.var-form-btns { display: flex; gap: 4px; }

.var-btn {
    flex: 1;
    font-size: 11px;
    padding: 3px 0;
    border-radius: 2px;
    border: 1px solid var(--ribbon-border);
    cursor: pointer;
    transition: background 0.1s;
}
.var-btn-ok     { background: var(--ms-blue); color: #fff; border-color: var(--ms-blue); }
.var-btn-ok:hover { background: #1254b5; }
.var-btn-cancel { background: #f0f0f0; }
.var-btn-cancel:hover { background: var(--btn-hover); }

/* ─── RIGHT / FOOTER PANELS ─────────────────────────────────────────── */

#right-panel {
    right: 0;
    position: absolute;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--sidebar-border);
    overflow-y: auto;
}

.props-empty {
    padding: 16px 14px;
    font-size: 11px;
    color: #999;
    text-align: center;
}

.props-type-row {
    padding: 6px 14px;
    border-bottom: 1px solid var(--sidebar-border);
}

.props-type-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--ms-blue);
}

.props-section-label {
    background: #e8edf3;
    color: #555;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 14px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-top: 1px solid var(--sidebar-border);
    border-bottom: 1px solid var(--sidebar-border);
}

.props-grid {
    display: grid;
    grid-template-columns: 68px 1fr;
}

.props-label {
    font-size: 11px;
    color: #555;
    padding: 4px 6px 4px 14px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--sidebar-border);
    white-space: nowrap;
    user-select: none;
}

.prop-input {
    font-family: var(--font);
    font-size: 11px;
    border: none;
    border-bottom: 1px solid var(--sidebar-border);
    border-left: 1px solid var(--sidebar-border);
    padding: 3px 6px;
    outline: none;
    width: 100%;
    background: white;
    transition: background 0.1s, border-color 0.1s;
}
.prop-input:focus {
    background: #f0f5ff;
    border-color: var(--ms-blue);
}

.props-checkbox-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--sidebar-border);
}

.prop-checkbox { cursor: pointer; }

.props-checkbox-label {
    font-size: 11px;
    color: #333;
    user-select: none;
    cursor: pointer;
}


#footer-panel {
    position: fixed;
    bottom: 0;
    width: 100%;
    background: var(--ms-blue);
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 2000;
}

#footer-text {
    color: rgba(255,255,255,0.85);
    font-size: 11px;
}

/* ─── CENTER / EDITOR AREA ──────────────────────────────────────────── */

#center-panel {
    background: #a9a9a9;
    position: absolute;
    overflow-x: auto;
    overflow-y: auto;
}

#editor-main {
    background-color: #a9a9a9;
    position: relative;
    display: flex;
}

#editor {
    position: relative;
    overflow: hidden;
    background-color: #ffffff;
    box-shadow: 0 2px 16px rgba(0,0,0,0.40);
}

/* ─── RULERS ────────────────────────────────────────────────────────── */

#h-line {
    top: 0;
    left: 0;
    right: 0;
    background-color: #ebebeb;
    position: absolute;
    z-index: 1000;
    border-bottom: 1px solid #c0c0c0;
}

#v-line {
    left: 0;
    float: left;
    background: #ebebeb;
    position: absolute;
    z-index: 1000;
    height: 100%;
    border-right: 1px solid #c0c0c0;
}

#h-canvas { position: relative; background-color: white; }
#v-canvas { position: absolute; background-color: white; }

/* ─── DATA BLOCK STRIP ──────────────────────────────────────────────── */

.data-block-strip {
    position: absolute;
    width: 20px;
    background: #2e7d32;
    pointer-events: none;
    z-index: 10;
    display: flex;
    justify-content: center;
}

.data-block-dot {
    position: absolute;
    top: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: white;
    border: 2px solid #2e7d32;
}

.data-block-dot.data-block-dot-active {
    background: #e53935;
    border-color: #b71c1c;
}

/* ─── DATA BLOCK LABEL ──────────────────────────────────────────────── */

.data-block-label {
    position: absolute;
    background: #ffe600;
    color: #1a1a1a;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 11;
    transform: translateX(-100%) translateY(-100%);
}

/* ─── HEADER BLOCK STRIP ─────────────────────────────────────────────── */

.header-block-strip {
    background: #6a1b9a !important;
}

.header-block-dot {
    border-color: #6a1b9a !important;
}

/* ─── DATA BLOCK ────────────────────────────────────────────────────── */

.editable.data-block {
    background-color: rgba(100, 149, 237, 0.1);
    border-color: #4a90d9;
    border-style: dashed;
}

/* ─── HEADER / FOOTER BLOCK ──────────────────────────────────────────── */

.editable.header-block,
.editable.footer-block {
    background-color: rgba(106, 27, 154, 0.08);
    border-color: #6a1b9a;
    border-style: dashed;
}

.editable.header-block.active,
.editable.footer-block.active {
    border-color: #4a148c;
}

/* ─── PAGE HEADER / FOOTER BLOCK (orange) ───────────────────────────── */

.page-block-strip {
    background: #e65100 !important;
}

.page-block-dot {
    border-color: #e65100 !important;
}

.editable.page-header-block,
.editable.page-footer-block {
    background-color: rgba(230, 81, 0, 0.08);
    border-color: #e65100;
    border-style: dashed;
}

.editable.page-header-block.active,
.editable.page-footer-block.active {
    border-color: #bf360c;
}

/* ─── DATA BLOCK HEADER / FOOTER (teal) ─────────────────────────────── */

.data-block-hf-strip {
    background: #00695c !important;
}

.data-block-hf-dot {
    border-color: #00695c !important;
}

.editable.data-block-header,
.editable.data-block-footer {
    background-color: rgba(0, 105, 92, 0.08);
    border-color: #00695c;
    border-style: dashed;
}

.editable.data-block-header.active,
.editable.data-block-footer.active {
    border-color: #004d40;
}

.editable.data-block.active {
    border-color: var(--ms-blue);
}

.editable.magnet-target {
    outline: 2px solid #d32f2f;
    outline-offset: 1px;
}

/* ─── EDITABLE BLOCKS ───────────────────────────────────────────────── */

.editable {
    border-color: #babbbc;
    border-style: solid;
    border-width: 1px;
    height: 50px;
    width: 50px;
    position: absolute;
    pointer-events: auto;
    background-color: rgba(255,255,255,0.74);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.editable.active {
    cursor: move;
    border-color: var(--ms-blue);
    border-style: dashed;
    outline: 1px solid rgba(43,87,154,0.25);
    outline-offset: 1px;
}

.editable.locked.active {
    cursor: default;
}

.editable-inner {
    overflow: hidden;
    height: auto;
    max-height: 100%;
    width: 100%;
    position: relative;
    pointer-events: none;
    user-select: none;
    background-color: rgba(255,255,255,0.74);
}

/* ─── RESIZE MARKERS ────────────────────────────────────────────────── */

.marker {
    position: absolute;
    height: 8px;
    width: 8px;
    background: white;
    border: 1px solid var(--ms-blue);
    border-radius: 1px;
}

.left         { left:  -5px; }
.right        { right: -5px; }
.top          { top:   -5px; }
.bottom       { bottom:-5px; }

.middle-h { left: 50%; transform: translateX(-50%); cursor: n-resize; }
.middle-v { top:  50%; transform: translateY(-50%); cursor: e-resize; }

.left.top,    .right.bottom { cursor: nw-resize; }
.left.bottom, .right.top    { cursor: ne-resize; }

.editable.locked .marker {
    background: #ccc;
    border-color: #999;
    cursor: default;
}

/* ─── DIALOGS ───────────────────────────────────────────────────────── */

dialog {
    border: none;
    border-radius: 4px;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0,0,0,0.28);
    min-width: 340px;
    font-family: var(--font);
}

dialog::backdrop {
    background: rgba(0,0,0,0.45);
}

.dialog-title {
    background: var(--ms-blue);
    color: white;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
}

dialog form {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
}

dialog textarea {
    font-family: var(--font);
    font-size: 13px;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    padding: 8px;
    resize: vertical;
    width: 100%;
    transition: border-color 0.1s;
}

dialog textarea:focus {
    outline: none;
    border-color: #5a9fd4;
    box-shadow: 0 0 0 2px rgba(90,159,212,0.2);
}

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

/* ─── EDIT TEXT DIALOG (textarea + function list) ──────────────────────── */

#editText {
    min-width: 640px;
    max-width: 90vw;
}

.edit-text-body {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.edit-text-body textarea {
    width: auto;
    flex: 1;
    min-width: 0;
}

.func-panel {
    width: 230px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    font-size: 12px;
}

.func-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px;
}

.func-group-title {
    font-weight: 600;
    color: #1a3a6b;
    margin: 10px 0 4px;
    font-size: 11px;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
}

.func-group-arrow {
    display: inline-block;
    width: 12px;
    font-size: 9px;
}

.func-group-items {
    padding-left: 12px;
}

.func-group-title:first-child {
    margin-top: 0;
}

.func-item {
    padding: 4px 6px;
    border-radius: 2px;
    cursor: pointer;
    color: #333;
    font-family: monospace;
}

.func-item:hover {
    background: #e3e3e3;
}

.func-item-selected,
.func-item-selected:hover {
    background: #d6e4f5;
}

.func-desc {
    border-top: 1px solid var(--ribbon-border);
    padding: 8px;
    min-height: 64px;
    font-size: 11px;
    color: #555;
}

.func-desc-sig {
    font-family: monospace;
    font-weight: 600;
    color: #1a3a6b;
    margin-bottom: 4px;
}

.func-desc-hint {
    line-height: 1.4;
}

.func-desc-note {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed var(--ribbon-border);
    font-style: italic;
    color: #888;
    line-height: 1.4;
}

.dialog-actions button {
    font-family: var(--font);
    font-size: 12px;
    padding: 6px 22px;
    border-radius: 2px;
    cursor: pointer;
    border: 1px solid var(--ribbon-border);
    background: #f3f3f3;
    color: #1f1f1f;
    transition: background 0.1s, border-color 0.1s;
}

.dialog-actions button:hover {
    background: var(--btn-hover);
    border-color: var(--btn-border-hover);
}

.btn-primary {
    background: var(--ms-blue) !important;
    color: white !important;
    border-color: var(--ms-blue) !important;
}

.btn-primary:hover {
    background: var(--ms-blue-hover) !important;
    border-color: var(--ms-blue-hover) !important;
}

/* ─── OPEN DIALOG ────────────────────────────────────────────────────── */

#openDialog {
    min-width: 340px;
    max-width: 480px;
    width: 100%;
}

.open-dialog-head {
    background: var(--ms-blue);
    color: white;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.open-dialog-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
}
.open-dialog-close:hover { opacity: 0.75; }

#open-file-list {
    padding: 8px 0;
    max-height: 400px;
    overflow-y: auto;
}

.open-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--sidebar-border);
}
.open-file-item:last-child { border-bottom: none; }
.open-file-item:hover { background: #e8f0fc; }

.open-file-group-header {
    padding: 6px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #888;
}

.open-file-icon { font-size: 16px; flex-shrink: 0; }
.open-file-name { flex: 1; }
.open-file-owner { color: #888; font-size: 11px; }

.open-file-delete {
    flex-shrink: 0;
    color: #999;
    font-size: 13px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 2px;
}
.open-file-delete:hover {
    color: #fff;
    background: #d9534f;
}

.open-file-empty {
    padding: 20px 16px;
    font-size: 12px;
    color: #888;
    text-align: center;
}

/* ─── DATASOURCE DIALOG ──────────────────────────────────────────────── */

#dsDialog {
    width: 420px;
}

.ds-fields {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 8px 12px;
    align-items: center;
    padding: 14px 16px 10px;
}

.ds-fields label {
    font-size: 12px;
    color: #444;
    text-align: right;
    white-space: nowrap;
    user-select: none;
}

.ds-fields input,
.ds-fields select {
    font-family: var(--font);
    font-size: 12px;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    padding: 4px 7px;
    height: 26px;
    outline: none;
    transition: border-color 0.1s;
    width: 100%;
    box-sizing: border-box;
}

.ds-fields input:focus,
.ds-fields select:focus {
    border-color: #5a9fd4;
    box-shadow: 0 0 0 2px rgba(90,159,212,0.2);
}

.ds-item-icon {
    font-size: 13px;
    margin-right: 4px;
    flex-shrink: 0;
}

.ds-connect-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 10px;
    padding: 0 4px 0 0;
    flex-shrink: 0;
    line-height: 1;
    transition: opacity 0.1s;
}
.ds-connect-btn:hover { opacity: 0.7; }
.ds-connect-none    { color: #bbb; }
.ds-connect-pending { color: #bbb; animation: ds-blink 0.8s step-start infinite; }
.ds-connect-ok      { color: #1a6b1a; }
.ds-connect-err     { color: #c00000; }

@keyframes ds-blink { 50% { opacity: 0.2; } }

.ds-db-group {
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.ds-db-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #555;
    font-size: 11px;
    flex-shrink: 1;
    min-width: 0;
}

.ds-query-add-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    color: #1a6b1a;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
    font-weight: 700;
}
.ds-query-add-btn:hover { background: #d6f0d6; border-color: #aad4aa; }

/* ─── QUERY ROWS ─────────────────────────────────────────────────────── */

.ds-query-item {
    display: flex;
    align-items: center;
    padding: 3px 8px 3px 28px;
    font-size: 11px;
    border-bottom: 1px solid var(--sidebar-border);
    background: #fafafa;
    user-select: none;
}
.ds-query-item:hover { background: #eef4ff; }

.ds-query-icon {
    color: #888;
    font-size: 10px;
    margin-right: 5px;
    flex-shrink: 0;
}

.ds-query-name-group {
    flex: 1;
    display: flex;
    align-items: center;
    overflow: hidden;
    min-width: 0;
}

.ds-query-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #1a3a6b;
    flex-shrink: 1;
    min-width: 0;
}

.ds-query-indicator {
    font-size: 8px;
    margin: 0 4px;
    flex-shrink: 0;
}
.ds-qi-err     { color: #c00000; }
.ds-qi-ok      { color: #1a6b1a; }
.ds-qi-pending { color: #bbb; animation: ds-blink 0.8s step-start infinite; }
.ds-qi-count   { color: #888; font-size: 10px; }

.ds-query-toggle {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 11px;
    padding: 0 3px;
    flex-shrink: 0;
    line-height: 1;
}
.ds-query-toggle:hover { color: var(--ms-blue); }

.ds-query-toggle-placeholder {
    display: inline-block;
    width: 16px;
    flex-shrink: 0;
}

.ds-field-item {
    display: flex;
    align-items: center;
    padding: 2px 8px 2px 48px;
    font-size: 11px;
    color: #444;
    border-bottom: 1px solid var(--sidebar-border);
    background: #f4f7ff;
    user-select: none;
}

.ds-field-drag {
    color: #aaa;
    margin-right: 4px;
    cursor: grab;
    flex-shrink: 0;
}
.ds-field-drag:active { cursor: grabbing; }

.ds-field-icon {
    color: #aaa;
    font-size: 10px;
    margin-right: 5px;
    flex-shrink: 0;
}

.ds-field-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'Courier New', Courier, monospace;
}

.ds-query-btn {
    background: transparent;
    border: none;
    color: #555;
    cursor: pointer;
    font-size: 12px;
    padding: 0 3px;
    flex-shrink: 0;
}
.ds-query-btn:hover { color: var(--ms-blue); }

/* ─── QUERY DIALOG ───────────────────────────────────────────────────── */

#queryDialog { width: 520px; }

.query-fields {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 8px 12px;
    align-items: start;
    padding: 14px 16px 10px;
}

.query-fields label {
    font-size: 12px;
    color: #444;
    text-align: right;
    padding-top: 5px;
    user-select: none;
}

.query-fields input {
    font-family: var(--font);
    font-size: 12px;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    padding: 4px 7px;
    height: 26px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.1s;
}

.query-fields textarea {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    padding: 6px 7px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    transition: border-color 0.1s;
    line-height: 1.5;
}

.query-fields input:focus,
.query-fields textarea:focus {
    border-color: #5a9fd4;
    box-shadow: 0 0 0 2px rgba(90,159,212,0.2);
}

.ds-test-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px 10px;
    border-top: 1px solid var(--ribbon-border);
}

.ds-test-btn {
    font-family: var(--font);
    font-size: 12px;
    padding: 4px 12px;
    border: 1px solid var(--ribbon-border);
    border-radius: 2px;
    background: #f3f3f3;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s;
}
.ds-test-btn:hover { background: var(--btn-hover); border-color: var(--btn-border-hover); }

#ds-test-result {
    font-size: 12px;
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: default;
    min-width: 0;
}
.ds-test-pending { color: #888; }
.ds-test-ok      { color: #1a6b1a; font-weight: 600; }
.ds-test-err     { color: #c00000; }
