:root {
    --bg-page: #f6f4f0;
    --bg-card: #fefefe;
    --text-primary: #1e1c19;
    --text-secondary: #6b6560;
    --text-muted: #8a8580;
    --border: #e8e4df;
    --accent: #0d5c63;
    --accent-hover: #0a4d52;
    --accent-soft: rgba(13, 92, 99, 0.12);
    --sql-keyword: #0d5c63;
    --sql-function: #b45309;
    --sql-string: #2f6b4f;
    --sql-number: #a63d3a;
    --sql-comment: #8a8580;
    --sql-ident: #4a4580;
    --sql-field: #3d5a80;
    --sql-placeholder: #0d5c63;
    --sql-op: #6b6560;
    --radius: 8px;
    --radius-sm: 6px;
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Instrument Serif', Georgia, serif;
    --error: #a63d3a;
    --error-soft: rgba(166, 61, 58, 0.1);
    --success: #0d5c63;
    --overlay: rgba(30, 28, 25, 0.4);
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.06);
    --shadow-modal: 0 8px 32px rgba(0, 0, 0, 0.12);
    --sidebar-bg: #f3f0ea;
    --sidebar-ink: #2a2622;
    --sidebar-line: #ddd6cc;
    --sidebar-wash: #ebe6dc;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    color: var(--text-primary);
}

h1, h2, .sidebar-header h1, .modal-header h2, .connection-title h2, .welcome h2, .login-box h1 {
    font-family: var(--font-serif);
    font-weight: 400;
}

.app {
    display: flex;
    height: 100vh;
}

/* Sidebar — тёплый ретро / бумага */
.sidebar {
    width: 320px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.35) 0%, transparent 120px),
        var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-line);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    color: var(--sidebar-ink);
}

.sidebar-header {
    padding: 22px 24px 18px;
    border-bottom: 1px solid var(--sidebar-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background: transparent;
}

.sidebar-header h1 {
    font-size: 24px;
    color: var(--sidebar-ink);
    letter-spacing: -0.02em;
}

.section {
    padding: 12px 14px;
    flex: 0 0 auto;
    margin: 8px 10px;
    border-radius: var(--radius);
    background: rgba(255, 252, 247, 0.72);
    border: 1px solid var(--sidebar-line);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55) inset;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    gap: 8px;
    user-select: none;
}

.section-header h2 {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-family: var(--font-sans);
    margin: 0;
    flex: 1;
    font-weight: 600;
}

.section-header-ch {
    margin-bottom: 0;
    padding: 6px 0;
}

.section-chevron {
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform 0.2s ease, border-color 0.15s;
    flex-shrink: 0;
}

.sidebar-section-expanded .section-chevron {
    transform: rotate(45deg);
}

.section-main-toggle:hover .section-chevron {
    border-color: var(--accent);
}

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

.sidebar-section-expanded .sidebar-section-body {
    display: block;
}

.ch-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--sidebar-line);
    padding-bottom: 0;
}

.ch-tab {
    flex: 1;
    padding: 8px 10px;
    font-size: 12px;
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}

.ch-tab:hover {
    color: var(--text-primary);
    background: var(--sidebar-wash);
}

.ch-tab.active {
    color: var(--sidebar-ink);
    background: transparent;
    box-shadow: inset 0 -2px 0 var(--sidebar-ink);
    position: relative;
    z-index: 1;
    margin-bottom: -1px;
    padding-bottom: 9px;
    border: none;
}

.ch-tab-panel {
    min-height: 40px;
}

.ch-history-hint {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.45;
    padding: 8px 4px;
}

.ch-connections-toolbar {
    display: grid;
    grid-template-columns: 28px 28px minmax(0, 1.22fr) minmax(0, 0.78fr);
    gap: 4px;
    align-items: center;
    margin-bottom: 12px;
}

.ch-connections-toolbar .btn-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 17px;
}

.btn-ch-db-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    width: 100%;
    min-width: 0;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: normal;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-ch-db-mini.btn-primary {
    background: var(--accent);
    color: #f7faf9;
}

.btn-ch-db-mini.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-ch-db-mini.btn-secondary {
    background: var(--sidebar-wash);
    color: var(--sidebar-ink);
    border: 1px solid var(--sidebar-line);
}

.btn-ch-db-mini.btn-secondary:hover:not(:disabled) {
    background: var(--accent-soft);
    color: var(--accent-hover);
    border-color: rgba(13, 92, 99, 0.28);
}

.btn-ch-db-mini:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.history-content {
    max-width: 1200px;
}

.history-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.history-page-heading {
    flex: 1 1 auto;
    min-width: 0;
}

.history-page-header h2 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 400;
    margin-bottom: 6px;
}

.btn-history-stats {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.btn-history-stats.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-history-stats.is-active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.history-stats-view {
    animation: historyStatsFade 0.2s ease;
}

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

.history-stats-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 16px;
    margin-bottom: 20px;
}

.history-stats-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-stats-period-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.history-stats-period-select {
    width: auto;
    min-width: 130px;
    padding: 8px 34px 8px 12px;
    font-size: 13px;
}

.history-stats-date-input {
    width: auto;
    min-width: 150px;
    padding: 8px 12px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.btn-history-stats-apply {
    height: 36px;
    padding: 0 18px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-history-stats-apply:hover {
    background: var(--accent-hover);
}

.history-stats-util {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 16px;
    margin-bottom: 24px;
}

.history-stats-util-load {
    flex: 1 1 420px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    min-width: 0;
}

.history-stats-util-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-soft);
}

.history-stats-inventory {
    flex: 0 1 220px;
    min-width: 188px;
    background: linear-gradient(145deg, var(--bg-page) 0%, var(--bg-card) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
}

.history-stats-inventory-caption {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.45px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.history-stats-inventory-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-stats-inventory-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-left: 10px;
    border-left: 3px solid var(--accent-soft);
}

.inventory-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 10px;
}

.history-stats-inventory-item .inventory-value {
    font-family: var(--font-serif);
    font-size: 32px;
    font-weight: 400;
    line-height: 1;
    color: var(--accent);
}

.inventory-active-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-sans);
    color: var(--accent-hover);
    background: var(--accent-soft);
    border: 1px solid rgba(13, 92, 99, 0.18);
    border-radius: 999px;
    padding: 3px 10px 3px 8px;
    line-height: 1.2;
    white-space: nowrap;
}

.inventory-active-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(13, 92, 99, 0.15);
}

.history-stats-inventory-item .inventory-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.history-stats-util-card .util-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.history-stats-util-card .util-value {
    font-size: 22px;
    font-family: var(--font-serif);
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 4px;
}

.history-stats-util-card .util-value .accent {
    color: var(--accent);
}

.history-stats-util-card .util-sub {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.45;
}

.history-stats-util-card .util-sub.util-range {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
}

.history-stats-util-card .util-sub.util-free-hint {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}

.history-stats-util-bar {
    margin-top: 12px;
    height: 10px;
    background: var(--bg-page);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.history-stats-util-bar-stacked {
    display: flex;
    flex-direction: row;
    align-items: stretch;
}

.history-stats-util-bar-fill {
    height: 100%;
    border-radius: 0;
    transition: width 0.35s ease, background 0.25s ease;
    min-width: 0;
}

.history-stats-util-bar-fill.is-load-busy {
    background: var(--accent);
    min-width: 2px;
}

.history-stats-util-bar-fill.is-free-ok {
    background: #e8e4df;
    min-width: 2px;
}

.history-stats-util-bar-fill.is-free-warn {
    background: #e89550;
    min-width: 2px;
}

.history-stats-util-bar-fill.is-free-critical {
    background: var(--error);
    min-width: 2px;
}

.history-stats-util-bar-stacked .history-stats-util-bar-fill:first-child {
    border-radius: 999px 0 0 999px;
}

.history-stats-util-bar-stacked .history-stats-util-bar-fill:last-child {
    border-radius: 0 999px 999px 0;
}

.history-stats-util-bar-stacked .history-stats-util-bar-fill:only-child {
    border-radius: 999px;
}

.history-stats-summary {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 16px;
}

.history-stats-days-expand {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    box-shadow: var(--shadow-soft);
}

.history-stats-days-expand summary {
    padding: 14px 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    list-style: none;
    user-select: none;
}

.history-stats-days-expand summary::-webkit-details-marker {
    display: none;
}

.history-stats-days-expand summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 8px;
    color: var(--text-muted);
    transition: transform 0.15s;
}

.history-stats-days-expand[open] summary::before {
    transform: rotate(90deg);
}

.history-stats-days-expand summary:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

.history-stats-chart-days {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0 18px 18px;
    border-top: 1px solid var(--border);
}

.history-stats-empty-inline {
    color: var(--text-muted);
    font-size: 13px;
    padding: 12px 0;
}

.history-stats-chart {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.history-stats-day {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-soft);
}

.history-stats-day-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.history-stats-day-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.history-stats-day-total {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.history-stats-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-stats-bar-row {
    display: grid;
    grid-template-columns: minmax(80px, 180px) minmax(0, 1fr) 56px;
    gap: 10px;
    align-items: center;
}

.history-stats-bar-label {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.history-stats-bar-track {
    height: 22px;
    background: var(--bg-page);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
}

.history-stats-bar-fill {
    height: 100%;
    border-radius: calc(var(--radius-sm) - 1px);
    min-width: 2px;
    transition: width 0.4s ease;
}

.history-stats-bar-fill.c0 { background: #0d5c63; }
.history-stats-bar-fill.c1 { background: #2a757c; }
.history-stats-bar-fill.c2 { background: #3d8b92; }
.history-stats-bar-fill.c3 { background: #5a9ea4; }
.history-stats-bar-fill.c4 { background: #78b0b5; }
.history-stats-bar-fill.c5 { background: #96c2c6; }

.history-stats-bar-value {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    text-align: right;
    white-space: nowrap;
}

.history-stats-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.history-stats-loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 32px;
    font-size: 14px;
}

.history-page-note {
    color: var(--text-secondary);
    font-size: 14px;
}

.history-table-scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    box-shadow: var(--shadow-soft);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.history-table th,
.history-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.history-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: var(--bg-page);
    white-space: nowrap;
}

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

.history-table tbody tr:hover td {
    background: var(--accent-soft);
}

.history-load-err {
    padding: 20px;
    text-align: center;
    color: var(--error);
}

.history-status-running {
    color: var(--accent);
    font-weight: 500;
}

.history-status-success {
    color: var(--success);
    font-weight: 500;
}

.history-status-failed {
    color: var(--error);
    font-weight: 500;
}

.history-progress-wrap {
    min-width: 100px;
}

.history-progress-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--border);
    overflow: hidden;
}

.history-progress-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--accent);
    transition: width 0.25s ease;
}

.history-progress-fill.is-complete {
    width: 100% !important;
    background: var(--accent);
}

.history-progress-fill.is-failed {
    width: 100% !important;
    background: var(--error);
}

.history-progress-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-run-stats {
    margin-top: 8px;
    font-size: 12px;
}

.history-run-stats summary {
    cursor: pointer;
    color: var(--accent);
    user-select: none;
}

.history-run-stats-list {
    margin: 6px 0 0;
    padding-left: 18px;
    color: var(--text-muted);
}

.btn-icon {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-secondary);
}

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

.sidebar .btn-icon {
    background: var(--sidebar-wash);
    border-color: var(--sidebar-line);
    color: var(--sidebar-ink);
}

.sidebar .btn-icon:hover {
    background: #e2dcd2;
    border-color: #cfc6ba;
    color: var(--sidebar-ink);
}

.sidebar .btn-icon:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.connections {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.connection-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}

.connection-item:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow-soft);
}

.connection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 12px 4px 12px;
}

.connection-name {
    font-weight: 600;
    cursor: pointer;
    flex-grow: 1;
    color: var(--text-primary);
}

.delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.delete-btn:hover {
    color: var(--error);
    background: var(--error-soft);
}

.connection-info {
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 12px 12px 12px;
}

.empty-state {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 2px dashed var(--border);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    background: var(--bg-page);
}

.welcome {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    padding: 60px 40px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border);
}

.welcome h2 {
    font-size: 28px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.welcome p {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.welcome .note {
    font-size: 14px;
    color: var(--text-muted);
    background: var(--bg-page);
    padding: 12px;
    border-radius: var(--radius-sm);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

#addMartSourceModal,
#addChColumnModal {
    z-index: 1100;
}

#confirmActionModal {
    z-index: 1200;
}

/* Затемнение не перехватывает клики: можно переключить подключение в сайдбаре, пока открыто окно */
#pipelineRunModal.active,
#resultModal.active,
#addToPipelineModal.active {
    pointer-events: none;
}

#pipelineRunModal.active .modal-content,
#resultModal.active .modal-content,
#addToPipelineModal.active .modal-content {
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 500px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-modal);
    border: 1px solid var(--border);
}

.modal-lg {
    width: 700px;
    max-width: 95%;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 1;
}

.modal-header h2 {
    font-size: 22px;
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.close:hover {
    background: var(--accent-soft);
    color: var(--text-primary);
}

/* Form */
form {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

input, textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text-primary);
}

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b6560' d='M1 1.5 6 6.5 11 1.5' stroke='%236b6560' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    background-size: 12px 8px;
}

select:hover {
    border-color: #d4cfc8;
    background-color: var(--bg-page);
}

input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 17px;
    height: 17px;
    min-width: 17px;
    padding: 0;
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    cursor: pointer;
    vertical-align: middle;
    position: relative;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

input[type="checkbox"]:hover {
    border-color: var(--text-muted);
    background: var(--bg-page);
}

input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="number"],
input[type="datetime-local"] {
    font-variant-numeric: tabular-nums;
}

textarea {
    font-family: 'Monaco', 'Menlo', monospace;
    resize: vertical;
    line-height: 1.5;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background-color: var(--bg-card);
}

.readonly-input {
    background: var(--bg-page);
    cursor: not-allowed;
}

small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}

.modal-footer {
    padding: 20px 0 0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.modal-footer-inset {
    padding: 16px 20px 20px;
    margin-top: 0;
}

.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-page);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
    color: var(--text-primary);
}

.btn-danger {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    font-family: var(--font-sans);
    background: var(--error);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #8f3330;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 24px;
    background: var(--success);
    color: white;
    border-radius: var(--radius);
    display: none;
    box-shadow: var(--shadow-modal);
    z-index: 2000;
    font-size: 14px;
    max-width: 400px;
    word-break: break-word;
}

.toast.show {
    display: block;
    animation: slideIn 0.3s;
}

.toast.error {
    background: var(--error);
}

.toast.info {
    background: var(--accent);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Connection Content */
.connection-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border);
}

.connection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.connection-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.connection-title h2 {
    font-size: 24px;
    color: var(--text-primary);
}

.connection-status {
    display: inline-block;
    padding: 4px 12px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.connection-info-mini {
    background: var(--bg-page);
    padding: 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.connection-info-mini p {
    margin: 4px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.finmodule-page-title {
    margin-bottom: 4px;
}

.connection-actions {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: stretch;
}

.btn-ch-db-main {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.15s;
    white-space: nowrap;
    flex: 0 0 auto;
}

.btn-ch-db-main.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-ch-db-main.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-ch-db-main.btn-secondary {
    background: var(--bg-page);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ch-db-main.btn-secondary:hover:not(:disabled) {
    background: var(--border);
    color: var(--text-primary);
}

.connection-actions .btn-create-query {
    flex: 1 1 160px;
    min-width: 140px;
    height: 36px;
    padding: 0 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.connection-actions .btn-create-query:hover {
    background: var(--accent-hover);
}

/* Results */
.result-stats {
    background: var(--accent-soft);
    padding: 16px;
    border-radius: var(--radius);
    margin-top: 20px;
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid var(--border);
}

.result-stats strong {
    color: var(--accent);
    font-size: 16px;
}

.result-error {
    background: var(--error-soft);
    color: var(--error);
    padding: 16px;
    border-radius: var(--radius);
    margin-top: 20px;
    font-size: 14px;
    border-left: 4px solid var(--error);
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 16px;
}

.result-table th {
    background: var(--bg-page);
    padding: 8px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    color: var(--text-primary);
}

.result-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.result-table tr:hover {
    background: var(--accent-soft);
}

.result-table-container {
    max-height: 300px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.column-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.column-tag {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

/* Saved Queries */
.saved-queries {
    margin-top: 24px;
}

.saved-queries-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.saved-queries-head h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin: 0;
    font-family: var(--font-sans);
}

.saved-queries-head .btn-sm {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    color: var(--text-secondary);
    white-space: nowrap;
}

.saved-queries-head .btn-sm:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.saved-queries h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 12px;
    font-family: var(--font-sans);
}

.queries-search {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    width: 100%;
}

.queries-search input {
    flex: 1 1 auto;
    min-width: 0;
    width: 0;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.queries-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.queries-search input::placeholder {
    color: var(--text-muted);
}

.queries-search .btn-icon {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.queries-search .btn-icon:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.queries-empty-filter {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.pipelines-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.pipelines-toolbar .btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    color: var(--text-primary);
}

.pipelines-toolbar .btn-sm:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.pipeline-section-search-hit {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(13, 92, 99, 0.2);
}

.pipeline-section-search-hit .pipeline-toolbar {
    background: var(--accent-soft);
}

.pipeline-section-search-hit .pipeline-title {
    color: var(--accent);
    font-weight: 600;
}

.history-search {
    margin-bottom: 14px;
    max-width: 420px;
}

.history-search-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
}

.history-search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.pipeline-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
    background: var(--bg-card);
}

.history-table-empty-filter {
    text-align: center;
    color: var(--text-muted);
    padding: 24px 12px;
    font-size: 14px;
}

.pipeline-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border);
}

.pipeline-toggle {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    margin: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-family: var(--font-sans);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
}

.pipeline-toggle:hover {
    background: var(--accent-soft);
}

.pipeline-chevron {
    font-size: 11px;
    color: var(--text-muted);
    width: 14px;
    flex-shrink: 0;
    line-height: 1;
    text-align: center;
}

.pipeline-title {
    font-size: 14px;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.25;
}

.pipeline-count {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.25;
}

.pipeline-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    justify-self: end;
}

.pipeline-actions .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
    line-height: 1.2;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    color: var(--text-secondary);
    white-space: nowrap;
}

.pipeline-actions .btn-sm:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pipeline-actions .btn-danger-text:hover {
    border-color: var(--error);
    color: var(--error);
    background: var(--error-soft);
}

.pipeline-queries-collapsed {
    display: none;
}

.pipeline-queries-open {
    display: block;
    padding: 8px 12px 12px;
}

.pipeline-queries-open .query-item:last-child {
    margin-bottom: 0;
}

.query-pos {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    margin-right: 2px;
}

.query-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pipeline-empty {
    padding: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

#addToPipelineModalBody {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 60vh;
    overflow-y: auto;
}

#addToPipelineModalBody .btn-add-candidate {
    text-align: left;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

#addToPipelineModalBody .btn-add-candidate:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.query-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
}

.query-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.query-header strong {
    color: var(--accent);
    font-size: 14px;
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.3;
}

.query-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
}

.query-title-wrap strong {
    flex: 0 1 auto;
}

.query-kind-badge {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 7px;
    line-height: 1.4;
}

.sql-editor-plain .sql-editor-highlight {
    display: none;
}

.sql-editor-plain .sql-editor-input {
    color: var(--text-primary);
    background: var(--bg-card);
}

.sql-editor-plain .sql-editor-input::selection {
    color: var(--text-primary);
}

.query-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

.query-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

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

.query-btn.delete:hover {
    background: var(--error-soft);
    border-color: var(--error);
    color: var(--error);
}

.query-preview {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-page);
    padding: 8px;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    border-left: 3px solid var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sql-editor {
    position: relative;
    width: 100%;
}

.sql-editor-highlight,
.sql-editor-input {
    font-family: 'Monaco', 'Menlo', ui-monospace, monospace;
    font-size: 13px;
    line-height: 1.55;
    letter-spacing: 0;
    tab-size: 4;
    padding: 10px 12px 2.5em;
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

.sql-editor-highlight {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    background: var(--bg-card);
}

.sql-editor-input {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    min-height: 160px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: transparent;
    caret-color: var(--text-primary);
    resize: vertical;
    overscroll-behavior: contain;
}

.sql-editor-input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.sql-editor-input::selection {
    background: var(--accent-soft);
    color: transparent;
}

.sql-editor:focus-within .sql-editor-highlight {
    border-color: var(--accent);
}

.sql-editor-input:focus {
    background: transparent;
    background-color: transparent;
    border-color: var(--accent);
}

.sql-keyword {
    color: var(--sql-keyword);
    font-weight: 600;
}

.sql-function {
    color: var(--sql-function);
}

.sql-string {
    color: var(--sql-string);
}

.sql-number {
    color: var(--sql-number);
}

.sql-comment {
    color: var(--sql-comment);
    font-style: italic;
}

.sql-ident {
    color: var(--sql-ident);
}

.sql-field {
    color: var(--sql-field);
}

.sql-placeholder {
    color: var(--sql-placeholder);
    background: var(--accent-soft);
    border-radius: 3px;
}

.sql-op {
    color: var(--sql-op);
}

.fin-sum-columns {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-page);
    max-height: 160px;
    overflow-y: auto;
}

.fin-sum-col-choice {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.query-sum-note {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.query-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.query-btn.delete-table:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: white;
}

.step-action-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-right: 2px;
}

.step-action-opt {
    padding: 0 8px;
    height: 28px;
    border: none;
    background: var(--bg-page);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-sans);
}

.step-action-opt:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.step-action-opt.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* Экран входа */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-page);
}

.login-box {
    background: var(--bg-card);
    padding: 36px 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-modal);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    font-size: 26px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.45;
}

.login-box .form-group {
    margin-bottom: 16px;
}

.login-box .form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text-primary);
}

.login-box input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-card);
}

.login-box input:-webkit-autofill,
.login-box input:-webkit-autofill:hover,
.login-box input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--bg-card) inset;
    box-shadow: 0 0 0 1000px var(--bg-card) inset;
    -webkit-text-fill-color: var(--text-primary);
    caret-color: var(--text-primary);
    transition: background-color 99999s ease-out 0s;
}

.login-error {
    color: var(--error);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 20px;
}

.btn-block {
    width: 100%;
    margin-top: 8px;
}

.btn-logout {
    margin-top: 8px;
    padding: 6px 12px;
    font-size: 12px;
    background: var(--sidebar-wash);
    border: 1px solid var(--sidebar-line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-family: var(--font-sans);
}

.btn-logout:hover {
    background: var(--accent-soft);
    color: var(--accent-hover);
    border-color: rgba(13, 92, 99, 0.28);
}

.login-step {
    width: 100%;
}

.grid-10x10 {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    margin-bottom: 12px;
    max-width: 100%;
}

.login-step .grid-10x10 {
    padding: 14px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-left: 0;
    margin-right: 0;
}

.grid-cell {
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    background: var(--bg-card);
    transition: background 0.15s, border-color 0.15s;
    min-width: 0;
}

.grid-cell:hover {
    background: var(--accent-soft);
    border-color: var(--text-muted);
}

.grid-cell.selected {
    background: var(--accent);
    border-color: var(--accent-hover);
}

.login-step2-actions {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.login-step2-actions .btn-secondary,
.login-step2-actions .btn-primary {
    flex: 1;
    max-width: none;
}

.sidebar-utils {
    padding: 10px 20px;
    border-bottom: 1px solid var(--sidebar-line);
    background: transparent;
}

.btn-grid-settings {
    width: 100%;
    padding: 7px 10px;
    font-size: 11px;
    background: var(--sidebar-wash);
    border: 1px solid var(--sidebar-line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-family: var(--font-sans);
}

.btn-grid-settings:hover {
    background: var(--accent-soft);
    border-color: rgba(13, 92, 99, 0.28);
    color: var(--accent-hover);
}

.modal-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.4;
}

.grid-settings {
    max-width: 340px;
    margin: 0 auto 12px;
    padding: 14px;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    gap: 4px;
}

#gridSettingsModal .modal-description {
    padding: 16px 20px 0;
    margin-bottom: 12px;
}

#gridSettingsModal .login-error {
    padding: 0 20px;
    margin-bottom: 0;
}

#gridSettingsModal .modal-footer {
    padding: 16px 20px 20px;
    margin-top: 0;
}

.pipeline-schedule {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-page);
    font-size: 13px;
}

.pipeline-schedule-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
}

.pipeline-schedule-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    color: var(--text-primary);
    font-size: 13px;
}

.pipeline-schedule-check input[type="checkbox"] {
    flex-shrink: 0;
}

.pipeline-schedule-interval input,
.pipeline-schedule-interval select,
.pipeline-schedule-start input {
    margin-left: 6px;
    min-width: 5rem;
    width: auto;
    display: inline-block;
    vertical-align: middle;
    padding: 7px 10px;
    font-size: 13px;
}

.pipeline-schedule-interval select {
    padding-right: 30px;
    min-width: 7rem;
}

.pipeline-schedule-meta {
    margin-top: 10px;
    color: var(--text-muted);
    font-size: 12px;
}

.pipeline-run-status {
    margin-bottom: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.pipeline-run-progress {
    width: 100%;
    height: 12px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
}

.pipeline-run-log {
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
    padding: 0;
}

.pipeline-run-log li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.pipeline-run-log-err {
    color: var(--error);
}

.query-cancel-hint {
    margin: 0 24px 20px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.pipeline-run-activity {
    position: fixed;
    bottom: 88px;
    right: 20px;
    z-index: 1990;
    max-width: min(360px, calc(100vw - 40px));
}

.pipeline-run-activity-btn {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.35;
    cursor: pointer;
    box-shadow: var(--shadow-modal);
}

.pipeline-run-activity-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.pipeline-run-activity-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--accent);
    animation: pipelineActivityPulse 1.2s ease-in-out infinite;
}

@keyframes pipelineActivityPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.pipeline-run-activity-text {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.query-run-activity {
    right: 20px;
    left: auto;
    bottom: 160px;
}

.query-run-activity-panel {
    cursor: default;
    pointer-events: none;
}

/* Переключение разделов сайдбара */
.sidebar-section-active {
    box-shadow: inset 3px 0 0 var(--sidebar-ink);
    background: #faf8f4;
    border-color: #cfc6ba;
}

.sidebar-section-active .section-header h2 {
    color: var(--sidebar-ink);
}

.section-main-toggle {
    cursor: pointer;
}

.section-main-toggle:hover h2 {
    color: var(--sidebar-ink);
}

.mart-tables-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 360px;
    overflow: auto;
}

.mart-table-pick {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
}

.mart-table-pick.is-hidden {
    display: none;
}

.mart-trigger-check {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.mart-trigger-badge {
    font-size: 11px;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 6px;
}

.mart-sources-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mart-source-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-page);
}

.mart-source-row code {
    flex: 1 1 auto;
    min-width: 0;
}

.mart-source-row .btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    padding: 4px 10px;
    font-size: 14px;
    line-height: 1.2;
    border-radius: var(--radius-sm);
    border: 1px solid var(--error);
    background: var(--error-soft);
    color: var(--error);
    cursor: pointer;
}

.mart-sources-toolbar .btn-sm {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
}

.mart-detail-card {
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
}

#martsDetailPanel .mart-detail-card {
    padding: 0;
}

.marts-list-panel {
    margin-bottom: 16px;
}

.marts-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.marts-section-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.marts-section-heading-row .marts-section-heading {
    margin: 0;
}

.mart-section-edit-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.mart-section-edit-row input {
    flex: 1 1 200px;
    min-width: 0;
}

.marts-section-group {
    margin-bottom: 18px;
}

.marts-section-heading {
    margin: 0 0 8px;
    padding: 0 2px;
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 400;
    color: var(--sidebar-ink, var(--text-primary));
    letter-spacing: -0.01em;
}

.mart-list-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border: 1px solid var(--sidebar-line, var(--border));
    border-radius: var(--radius);
    background: #faf8f4;
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.mart-list-item:hover {
    background: var(--sidebar-wash, #ebe6dc);
    border-color: #cfc6ba;
}

.mart-list-item.is-active {
    background: #faf8f4;
    border-color: #cfc6ba;
    box-shadow: inset 3px 0 0 var(--sidebar-ink, #2a2622);
}

.mart-list-item-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--sidebar-ink, var(--text-primary));
}

.mart-list-item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.mart-detail-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.mart-detail-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.mart-detail-actions .btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    line-height: 1.2;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    white-space: nowrap;
}

.mart-detail-actions .btn-sm.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.mart-detail-actions .btn-sm.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
}

.mart-detail-actions .btn-sm.btn-danger {
    background: var(--error-soft, #fde8e8);
    border-color: var(--error);
    color: var(--error);
}

.mart-locked-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.embedded-script-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-soft);
}

.embedded-script-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.embedded-script-head h3 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 22px;
}

.embedded-script-id {
    font-size: 12px;
    color: var(--text-muted);
}

.embedded-script-desc {
    color: var(--text-secondary);
    margin: 8px 0 12px;
    font-size: 14px;
    line-height: 1.45;
}

.embedded-script-meta {
    font-size: 13px;
    margin-bottom: 12px;
}

.embedded-script-source-text {
    margin: 4px 0 0;
    font-size: 14px;
}

.embedded-script-hint {
    margin: 8px 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.embedded-script-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.scripts-main-panel {
    overflow-y: auto;
}

.sidebar-select-group {
    margin-bottom: 0;
}

.sidebar-select-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}

.sidebar-select-row label {
    margin-bottom: 0;
}

.sidebar-select-row .sidebar-connection-select {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
}

.sidebar-select-row .btn-icon {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-select-group label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.sidebar-connection-select {
    width: 100%;
    padding: 9px 34px 9px 11px;
    font-size: 13px;
    background: #faf8f4;
    color: var(--sidebar-ink);
    border: 1px solid var(--sidebar-line);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
}

.sidebar-connection-select:focus {
    outline: none;
    border-color: #cfc6ba;
    box-shadow: 0 0 0 2px rgba(42, 38, 34, 0.06);
}

.sidebar-connection-select option {
    background: #faf8f4;
    color: var(--sidebar-ink);
}

.script-conn-select {
    width: 100%;
    max-width: 420px;
}

.finmodule-run-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.finmodule-run-bar .btn-primary {
    height: 36px;
}

.section-manager .section-header {
    cursor: default;
}

.manager-stalled-content {
    max-width: 720px;
}

.manager-stalled-content .history-page-note {
    margin-bottom: 20px;
}

.manager-stalled-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.manager-stalled-label-row label {
    margin-bottom: 0;
}

.manager-stalled-count {
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.manager-stalled-count.has-orders {
    color: var(--accent);
    font-weight: 500;
}

.manager-stalled-content #stalledOrdersText {
    min-height: 320px;
}

.manager-stalled-success {
    color: var(--success);
    font-size: 14px;
    margin: 0 0 12px;
    min-height: 1.2em;
}