/* === Sivulayout === */
.estimate-root {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height));
    overflow: hidden;
    width: 100%;
}
.estimate-header {
    padding: 24px 24px 0 24px;
    flex-shrink: 0;
}
/* Pääsisältö + oikea sivupalkki rinnakkain */
.estimate-main-row {
    flex: 1;
    display: flex;
    min-height: 0;
    padding: 0 24px 0 24px;
    gap: 0;
}
.estimate-main-col {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.estimate-body {
    flex: 1;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 4px;
}
/* === Oikea sivupalkki === */
.right-sidebar {
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    min-height: 0;
    max-height: 100%;
    position: relative;
}
.right-sidebar-inner {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 4px;
    background: var(--color-surface);
}
/* Sidebar header & tabs */
.sb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.sb-header h3 { margin: 0; font-size: 13px; font-weight: 600; }
.sb-tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.sb-tab {
    flex: 1;
    padding: 6px 8px;
    font-size: 11px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    text-align: center;
    white-space: nowrap;
}
.sb-tab:last-child { flex: 0; padding: 6px 10px; }
.sb-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.sb-tab:hover:not(.active) { color: var(--color-text); }
.sb-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
/* Sidebar taulukko */
.sb-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
}
.sb-tbl th {
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 2;
    padding: 4px 6px;
    font-weight: 500;
    font-size: 10.5px;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    text-align: right;
    white-space: nowrap;
}
.sb-tbl th.t-left { text-align: left; }
.sb-tbl td {
    padding: 3px 6px;
    border-bottom: 1px solid var(--color-border-light);
    text-align: right;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.sb-tbl td.t-left { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.sb-tbl tr:hover td { background: var(--color-bg); }
.sb-tbl tr.sb-total td { font-weight: 600; border-top: 2px solid var(--color-border); background: var(--color-surface); }
.sb-tbl tr.sb-total td.sb-total-primary { color: var(--color-primary); font-weight: 700; }
.sb-expand-btn {
    background: none; border: 1px solid var(--color-border); border-radius: 4px;
    cursor: pointer; color: var(--color-text-muted); font-size: 12px; padding: 2px 6px;
    transition: background .12s;
}
.sb-expand-btn:hover { background: var(--color-border-light); color: var(--color-text); }
/* Panoshinnasto inline edit */
.sb-inline-input {
    width: 70px; padding: 1px 4px; font-size: 11px; border: 1px solid var(--color-primary);
    border-radius: 3px; text-align: right; outline: none; background: var(--color-bg);
    color: var(--color-text); font-family: inherit; font-variant-numeric: tabular-nums;
}
.sb-btn-sm {
    padding: 1px 6px; font-size: 10px; border: 1px solid var(--color-border); border-radius: 3px;
    background: var(--color-surface); color: var(--color-text-muted); cursor: pointer;
}
.sb-btn-sm:hover { background: var(--color-border-light); color: var(--color-text); }
/* Laajuustiedot */
.scope-section { padding: 8px 10px; }
.scope-section h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .5px; }
.scope-field { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.scope-label { flex: 0 0 130px; font-size: 11.5px; color: var(--color-text); }
.scope-input { flex: 1; min-width: 0; padding: 3px 6px; font-size: 11.5px; border: 1px solid var(--color-border); border-radius: 4px; background: var(--color-bg); color: var(--color-text); font-family: inherit; font-variant-numeric: tabular-nums; text-align: right; }
.scope-input:focus { outline: none; border-color: var(--color-primary); }
.scope-unit { flex: 0 0 30px; font-size: 10.5px; color: var(--color-text-muted); }
.scope-save-btn { width: 100%; margin-top: 8px; padding: 5px 0; font-size: 12px; border: none; border-radius: 5px; background: var(--color-primary); color: #fff; cursor: pointer; font-weight: 500; }
.scope-save-btn:hover { opacity: .9; }
.scope-save-btn:disabled { opacity: .5; cursor: default; }
.scope-divider { border: none; border-top: 1px solid var(--color-border); margin: 10px 0; }
.scope-metric { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-size: 11.5px; }
.scope-metric-label { color: var(--color-text-muted); }
.scope-metric-value { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--color-text); }
.scope-custom-row { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.scope-custom-row .scope-label { flex: 0 0 auto; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-remove-btn { background: none; border: none; cursor: pointer; color: var(--color-text-muted); font-size: 14px; padding: 0 2px; line-height: 1; }
.scope-remove-btn:hover { color: var(--color-danger, #e53e3e); }
.scope-add-btn { background: none; border: 1px dashed var(--color-border); border-radius: 4px; padding: 4px 8px; font-size: 11px; color: var(--color-text-muted); cursor: pointer; width: 100%; margin-top: 4px; }
.scope-add-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.scope-dialog-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.scope-dialog { background: var(--color-surface); border-radius: 8px; padding: 16px; width: 300px; box-shadow: 0 4px 20px rgba(0,0,0,.2); }
.scope-dialog h4 { margin: 0 0 12px; font-size: 13px; }
.scope-dialog label { display: block; font-size: 11px; color: var(--color-text-muted); margin-bottom: 2px; }
.scope-dialog input { width: 100%; padding: 4px 6px; font-size: 12px; border: 1px solid var(--color-border); border-radius: 4px; margin-bottom: 8px; background: var(--color-bg); color: var(--color-text); }
.scope-dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.scope-dialog-actions button { padding: 4px 14px; font-size: 12px; border-radius: 4px; cursor: pointer; border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); }
.scope-dialog-actions button.primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
/* Litteratulokset puurakenne */
.sb-tbl tr.sb-group td { background: var(--color-bg); font-weight: 600; font-size: 11px; }
.sb-tbl tr.sb-group:hover td { background: var(--color-border-light); }
.sb-group-toggle {
    background: none; border: none; cursor: pointer; color: var(--color-text-muted);
    font-size: 10px; padding: 0 4px 0 0; vertical-align: middle; line-height: 1;
}
.sb-group-toggle:hover { color: var(--color-text); }
.sb-tbl tr.sb-child td { padding-left: 18px; }
.sb-tbl tr.sb-child td:first-child { padding-left: 18px; }
/* Sidebar splitter */
.sidebar-splitter {
    width: 7px;
    flex-shrink: 0;
    cursor: col-resize;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
    transition: background .15s;
    border-radius: 3px;
}
.sidebar-splitter:hover { background: var(--color-border-light); }
.sidebar-splitter.dragging { background: var(--color-primary); opacity: 0.3; }
.estimate-grid-pane {
    flex: 1;
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    scroll-padding-top: 66px;
    min-height: 80px;
    min-width: 0;
}
.split-divider {
    height: 7px;
    flex-shrink: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    letter-spacing: 3px;
    color: var(--color-text-muted);
    user-select: none;
}
.split-divider:hover { background: var(--color-border-light); }
.estimate-split-pane {
    flex: 1;
    overflow-y: auto;
    min-height: 100px;
    border-top: 2px solid var(--color-primary);
}

/* === Näkymävaihto === */
.view-toggle { display: inline-flex; border: 1px solid var(--color-border); border-radius: 5px; overflow: hidden; margin-right: 4px; }
.view-toggle button {
    padding: 4px 12px; font-size: 11px; font-weight: 500; cursor: pointer;
    background: transparent; border: none; color: var(--color-text-muted);
    border-right: 1px solid var(--color-border); transition: background .1s;
}
.view-toggle button:last-child { border-right: none; }
.view-toggle button:hover { background: var(--color-surface); }
.view-toggle button.active { background: var(--color-primary); color: white; }

/* === Toolbar === */
.estimate-toolbar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 2px;
    flex-shrink: 0;
}
.toolbar-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
/* === Hakukenttä + tyyppinapit yhtenä widgettinä === */
.search-widget {
    display: flex; align-items: center; position: relative;
    border: 1px solid var(--color-border); border-radius: 8px;
    background: var(--color-bg); height: 30px; width: 300px;
    overflow: hidden; transition: border-color .15s;
    container-type: inline-size;
    container-name: search-widget;
}
.search-widget:focus-within { border-color: var(--color-primary); }
.search-widget .search-icon {
    display: flex; align-items: center; justify-content: center;
    padding: 0 6px 0 8px; color: var(--color-text-muted); flex-shrink: 0;
}
.search-widget .search-main {
    border: none !important; outline: none !important; background: transparent !important;
    flex: 1; min-width: 0; font-size: 12px; padding: 0 4px; height: 100%;
    color: var(--color-text);
}
.search-tabs {
    display: flex; align-items: center; gap: 2px;
    padding: 0 4px; flex-shrink: 0;
}
.search-tab {
    padding: 2px 6px; text-align: center;
    font-size: 10px; font-weight: 500; cursor: pointer;
    background: transparent; color: var(--color-text-muted);
    border: 1px solid var(--color-border-light); border-radius: 10px;
    transition: background .1s, color .1s;
    line-height: 1.4;
}
.search-tab:last-child { border-right: none; }
.search-tab.active { background: var(--color-primary); color: #fff; }
.search-tab:hover:not(.active) { background: var(--color-border-light); color: var(--color-text); }
.search-tab__mid, .search-tab__abbr { display: none; }
.search-tab__full { display: inline; }
@@container search-widget (max-width: 300px) {
    .search-tab__full { display: none; }
    .search-tab__mid { display: inline; }
}
@@container search-widget (max-width: 205px) {
    .search-tab__mid { display: none; }
    .search-tab__abbr { display: inline; }
    .search-tab { padding: 2px 5px; font-size: 9px; }
    .search-tabs { gap: 2px; }
    .search-main { min-width: 52px; }
}

/* === Suodatin-dropdown === */
.toolbar-dropdown-wrap { position: relative; }
.toolbar-dropdown {
    display: none; position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 210px; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); z-index: 500; padding: 6px;
}
.toolbar-dropdown-wrap.open .toolbar-dropdown { display: block; }
.dropdown-section-label {
    font-size: 10px; color: var(--color-text-muted); padding: 5px 8px 2px;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.dropdown-item {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px;
    border-radius: 5px; cursor: pointer; font-size: 12px;
    color: var(--color-text); user-select: none;
}
.dropdown-item:hover { background: var(--color-border-light); }
.dropdown-item.item-alert { color: var(--color-danger); }
.dropdown-check {
    width: 14px; height: 14px; border-radius: 3px;
    border: 1px solid var(--color-border); display: flex;
    align-items: center; justify-content: center; flex-shrink: 0;
}
.dropdown-check.checked::after { content: '\2713'; font-size: 10px; }
.dropdown-check.checked { background: var(--color-primary); border-color: transparent; color: #fff; }
.dropdown-separator { height: 1px; background: var(--color-border); margin: 4px 0; }
.dropdown-badge-alert {
    margin-left: auto; font-size: 10px; padding: 1px 6px;
    border-radius: 3px; background: var(--color-danger-light); color: var(--color-danger);
}
.filter-count {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--color-primary); color: #fff; font-size: 9px;
    font-weight: 600; margin-left: 4px;
}
.sidebar-toggle-btn { margin-left: auto; }
/* === Three-dot more menu === */
.more-menu-wrap { position: relative; }
.more-menu-btn {
    padding: 4px 8px; border-radius: 5px; font-size: 16px; cursor: pointer;
    border: 1.5px solid var(--color-border); background: transparent; color: var(--color-text-muted);
    transition: background .12s, color .12s; line-height: 1; font-weight: 700;
}
.more-menu-btn:hover { background: var(--color-border-light); color: var(--color-text); }
.more-menu {
    display: none; position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 220px; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); z-index: 500; padding: 4px;
}
.more-menu-wrap.open .more-menu { display: block; }
.more-menu-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 10px; width: 100%;
    border-radius: 5px; cursor: pointer; font-size: 12px;
    color: var(--color-text); border: none; background: none; text-align: left;
}
.more-menu-item:hover { background: var(--color-border-light); }
.more-menu-shortcut { margin-left: auto; font-size: 10px; color: var(--color-text-muted); }
/* === Lisää suorite -nappi totals-rivillä === */
.totals-add-btn {
    padding: 2px 8px; font-size: 10.5px; font-weight: 500; cursor: pointer;
    border: 1px solid var(--color-border); border-radius: 4px;
    background: transparent; color: var(--color-text-muted);
    transition: background .12s, color .12s; margin-left: 12px; white-space: nowrap;
}
.totals-add-btn:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.toggle-btn.review-alert { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.toggle-btn.review-alert:hover { background: #fecaca; }

/* === Tuontimodaalin vaiheet === */
.import-step {
    display: flex; align-items: center; gap: 6px; padding: 6px 14px;
    border-radius: 20px; font-size: 13px; font-weight: 500;
    background: var(--color-border-light); color: var(--color-text-muted);
}
.import-step.active { background: var(--color-primary); color: #fff; }
.import-step.done { background: rgba(16,185,129,.15); color: #059669; }
.import-step .step-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%; font-size: 11px; font-weight: 700;
    background: rgba(255,255,255,.2);
}
.import-step.active .step-num { background: rgba(255,255,255,.3); }
.import-step.done .step-num { background: rgba(0,0,0,.1); }
.drop-zone {
    border: 2px dashed var(--color-border); border-radius: var(--border-radius);
    padding: 16px; text-align: center;
    transition: border-color .2s, background .2s;
}
.drop-zone.drag-over { border-color: var(--color-primary); background: var(--color-primary-light, rgba(37,99,235,.05)); }

/* Näppäimistöfokus välilehdille ja hakupainikkeille */
.split-panel-tab:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
/* Fokus (ei aktiivinen): sininen reunus, ei taustaväriä */
.search-tab:focus-visible,
.toggle-btn:focus-visible { outline: 2px solid #2563eb; outline-offset: -2px; }
/* Fokus + aktiivinen: sininen tausta + valkoinen reunus erottuvuudelle */
.search-tab.active:focus-visible,
.toggle-btn.active:focus-visible { outline: 2px solid white; outline-offset: -2px; }

/* === Versio & tila === */
.version-select { padding: 4px 8px; border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-surface); color: var(--color-text); font-size: 13px; cursor: pointer; }
.status-dropdown-wrapper { position: relative; display: inline-block; }
.status-dropdown-menu { position: absolute; top: calc(100% + 4px); left: 0; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 100; min-width: 140px; overflow: hidden; }
.status-dropdown-item { display: block; width: 100%; padding: 8px 14px; background: none; border: none; text-align: left; font-size: 13px; cursor: pointer; color: var(--color-text); }
.status-dropdown-item:hover { background: var(--color-border-light); }

/* === Toggle-napit === */
.toggle-btn {
    padding: 4px 11px; border-radius: 5px; font-size: 12.5px; cursor: pointer;
    border: 1.5px solid var(--color-border); background: transparent; color: var(--color-text-muted);
    transition: background .12s, color .12s, border-color .12s;
}
.toggle-btn.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* === Undo/Redo === */
.undo-redo-group { display: inline-flex; gap: 2px; margin-right: 4px; }
.undo-btn { padding: 4px 7px !important; min-width: 28px; }
.undo-btn.undo-disabled { opacity: .35; cursor: default; pointer-events: auto; }
.undo-btn.undo-disabled:hover { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
@@keyframes undo-flash {
    0%   { background-color: rgba(59,130,246,.25); }
    100% { background-color: transparent; }
}
.undo-highlight {
    animation: undo-flash 1.2s ease-out;
}

/* === Compact header === */
.estimate-hdr-compact { padding: 12px 20px 8px; }
.hdr-row-1 { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.hdr-title-group { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.hdr-title { font-size: 17px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--color-text); }
.hdr-row-2 { margin-top: 2px; }
.hdr-subtitle { font-size: 12.5px; color: var(--color-text-muted); }
.hdr-actions-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.hdr-icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--color-border);
    background: transparent; color: var(--color-text-muted); cursor: pointer; transition: background .12s, color .12s;
}
.hdr-icon-btn:hover { background: var(--color-border-light); color: var(--color-text); }
.hdr-bookmark-wrap { position: relative; }
.hdr-bookmark-dropdown {
    position: absolute; top: calc(100% + 4px); right: 0; min-width: 190px;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 200; overflow: hidden;
}
.hdr-more-wrap-always { position: relative; }
.hdr-more-dropdown {
    position: absolute; top: calc(100% + 4px); right: 0; min-width: 260px;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 200;
    overflow-y: auto; overflow-x: hidden; max-height: calc(100vh - 120px);
}
.hdr-more-item {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px;
    background: none; border: none; text-align: left; font-size: 13px; cursor: pointer; color: var(--color-text);
    white-space: nowrap;
}
.hdr-more-item:hover { background: var(--color-border-light); }
.hdr-more-item:disabled { opacity: .45; cursor: default; }
.hdr-more-item.hdr-more-danger { color: #dc2626; }
.hdr-more-item.hdr-more-danger:hover { background: #fef2f2; }
.hdr-shortcut { margin-left: auto; font-size: 10px; color: var(--color-text-muted); font-weight: 400; }
.hdr-menu-divider { height: 1px; background: var(--color-border); margin: 4px 0; }

/* Status badge värikoodit */
.badge.badge-draft     { background: #e5e7eb; color: #4b5563; }
.badge.badge-submitted { background: #ffedd5; color: #c2410c; }
.badge.badge-active    { background: #dbeafe; color: #1d4ed8; }
.badge.badge-completed { background: #dcfce7; color: #15803d; }
.badge.badge-archived  { background: #fef3c7; color: #92400e; }

/* === Otsikkorivi (IsHeader) === */
.estimate-grid tr.row-header td { background: #e8f0fe !important; font-weight: 600; }

/* === Checkbox-sarakkeet === */
.estimate-grid .col-check input[type=checkbox] { cursor: pointer; accent-color: var(--color-primary); }

/* === Laskelman muistio === */
.estimate-memo {
    padding: 6px 10px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.estimate-memo textarea {
    width: 100%; resize: vertical; min-height: 44px; max-height: 160px;
    font-size: 12.5px; border: 1px solid var(--color-border); border-radius: 4px;
    padding: 4px 6px; background: var(--color-bg); color: var(--color-text);
    font-family: inherit; outline: none;
}
.estimate-memo textarea:focus { border-color: var(--color-primary); }
/* === Muutoshistoria (toolbar-dropdown) === */
.history-dropdown-wrap { position: relative; }
.history-dropdown-wrap .history-dd {
    display: none; position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 340px; max-width: 400px; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.10); z-index: 500; padding: 0;
    max-height: 380px; overflow-y: auto;
}
.history-dropdown-wrap.open .history-dd { display: block; }
.history-dd-header {
    padding: 8px 12px 6px; font-size: 11px; font-weight: 600; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--color-border-light);
}
.history-dd-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 12px;
    cursor: pointer; border: none; background: none; width: 100%; text-align: left;
    font-size: 12px; color: var(--color-text); border-bottom: 1px solid var(--color-border-light);
    transition: background .1s;
}
.history-dd-item:last-child { border-bottom: none; }
.history-dd-item:hover { background: var(--color-surface); }
.history-dd-icon {
    width: 22px; height: 22px; border-radius: 5px; display: flex; align-items: center; justify-content: center;
    font-size: 11px; flex-shrink: 0; background: var(--color-bg); border: 1px solid var(--color-border-light);
}
.history-dd-body { flex: 1; min-width: 0; }
.history-dd-title { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-dd-meta { font-size: 10.5px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-dd-initials {
    font-size: 9px; font-weight: 700; background: var(--color-primary);
    color: #fff; border-radius: 50%; width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.history-dd-showall {
    display: block; width: 100%; padding: 8px 12px; text-align: center; font-size: 11px;
    color: var(--color-primary); background: none; border: none; border-top: 1px solid var(--color-border-light);
    cursor: pointer; font-weight: 500;
}
.history-dd-showall:hover { background: var(--color-surface);
}
.history-badge {
    font-size: 9px; font-weight: 600; background: var(--color-primary); color: #fff;
    border-radius: 8px; padding: 0 5px; min-width: 14px; text-align: center; line-height: 16px;
}
/* Korostusanimaatio */
.highlight-fade {
    background: #fee2e2 !important;
    transition: background 2s ease-out;
}
.highlight-fade-out {
    background: transparent !important;
    transition: background 2s ease-out;
}
/* === Alapaneeli === */
.split-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: var(--color-surface); border-bottom: 1px solid var(--color-border); flex-shrink: 0; }
.split-panel-title  { font-size: 13px; font-weight: 600; }
.split-panel-tabs   { display: flex; border-bottom: 1px solid var(--color-border); background: var(--color-surface); flex-shrink: 0; }
.split-panel-tab    { padding: 7px 16px; font-size: 12.5px; border: none; background: none; cursor: pointer; color: var(--color-text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.split-panel-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.split-panel-content { padding: 16px; }
.split-memo-ta:focus { border-color: var(--color-primary) !important; }
.review-toggle { display: flex; align-items: center; gap: 6px; padding: 4px 0; font-size: 12px; color: var(--color-text-muted); cursor: pointer; }
.review-toggle input { margin: 0; }
.review-toggle.active { color: #d97706; font-weight: 600; }
/* === Toast === */
.toast-notification {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    z-index: 9999; padding: 8px 20px; border-radius: 6px;
    background: var(--color-text, #1e293b); color: #fff;
    font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.2);
    animation: toast-in .25s ease-out;
}
@@keyframes toast-in { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }
.shortcut-table { width:100%; border-collapse:collapse; margin-bottom:4px; }
.shortcut-table td { padding:3px 6px; border-bottom:1px solid var(--color-border-light); }
.shortcut-table .key-col { white-space:nowrap; width:200px; }
.shortcut-table kbd {
    display:inline-block; padding:1px 5px; font-size:11px; font-family:inherit;
    background:var(--color-surface); border:1px solid var(--color-border);
    border-radius:3px; color:var(--color-text); box-shadow:0 1px 0 var(--color-border);
}
/* === Sivupalkin pikanäppäimet === */
.sb-shortcuts { padding: 8px 10px; }
.sb-sc-group { margin-bottom: 10px; }
.sb-sc-hdr {
    margin: 0 0 4px; font-size: 10.5px; text-transform: uppercase;
    letter-spacing: .4px; color: var(--color-text-muted); font-weight: 700;
    border-bottom: 1px solid var(--color-border-light); padding-bottom: 3px;
}
.sb-sc-tbl { width: 100%; border-collapse: collapse; }
.sb-sc-tbl td { padding: 2px 4px; font-size: 11.5px; border-bottom: 1px solid var(--color-border-light); vertical-align: top; }
.sb-sc-tbl tr:last-child td { border-bottom: none; }
.sb-sc-key { white-space: nowrap; color: var(--color-text-muted); }
.sb-sc-tbl kbd {
    display: inline-block; padding: 0 4px; font-size: 10px; font-family: inherit;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 3px; color: var(--color-text); box-shadow: 0 1px 0 var(--color-border);
    line-height: 1.5;
}
/* === Kaavat-ohje === */
.sb-formulas { padding: 8px 10px; }
.sb-formulas .sb-sc-hdr { margin: 0 0 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--color-text-muted); font-weight: 700; border-bottom: 1px solid var(--color-border-light); padding-bottom: 3px; }
.sb-formulas .sb-sc-group { margin-bottom: 10px; }
.sb-formulas table { width: 100%; border-collapse: collapse; }
.sb-formulas td, .sb-formulas th { padding: 2px 4px; font-size: 11px; border-bottom: 1px solid var(--color-border-light); vertical-align: top; }
.sb-formulas th { font-size: 10px; font-weight: 600; color: var(--color-text-muted); text-align: left; border-bottom: 1px solid var(--color-border); }
.sb-formulas tr:last-child td { border-bottom: none; }
.sb-formulas code { font-family: 'Consolas', 'Monaco', monospace; font-size: 11px; background: var(--color-bg); padding: 0 3px; border-radius: 2px; color: var(--color-primary); }
.sb-formulas .formula-example { background: var(--color-bg); border-radius: 4px; padding: 6px 8px; font-family: 'Consolas', 'Monaco', monospace; font-size: 11px; line-height: 1.6; color: var(--color-text); white-space: pre-wrap; margin-top: 4px; }
/* === Validointipalkki (toolbar dropdown) === */
.validation-dropdown-wrap { position: relative; }
.validation-bar .vb-errors { color: #dc2626; font-weight: 600; }
.validation-bar .vb-warnings { color: #d97706; font-weight: 600; }
.validation-bar .vb-ok { color: #16a34a; }
.validation-dropdown {
    display: none; position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 340px; max-width: 420px; z-index: 500;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    max-height: 340px; overflow-y: auto; padding: 0;
}
.validation-dropdown-wrap.open .validation-dropdown { display: block; }
.validation-dd-header {
    padding: 8px 12px 6px; font-size: 11px; font-weight: 600; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--color-border-light);
}
.validation-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 12px;
    border-bottom: 1px solid var(--color-border-light); cursor: pointer;
    font-size: 12px; border: none; background: none; width: 100%; text-align: left;
    transition: background .1s;
}
.validation-item:last-child { border-bottom: none; }
.validation-item:hover { background: var(--color-surface); }
.validation-item .vi-icon { flex-shrink: 0; font-size: 13px; }
.validation-item .vi-desc { flex: 1; color: var(--color-text); }
.validation-item .vi-loc { color: var(--color-text-muted); font-size: 11px; white-space: nowrap; }
.validation-filter-btn {
    font-size: 11px; padding: 2px 8px; border-radius: 4px; cursor: pointer;
    border: 1px solid var(--color-border); background: var(--color-surface);
    color: var(--color-text-muted);
}
.validation-filter-btn:hover { background: var(--color-border-light); }
.validation-filter-btn.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
/* === Custom tooltip === */
.has-tooltip {
    position: relative;
}
.has-tooltip .custom-tooltip {
    visibility: hidden; opacity: 0;
    position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: #1e293b; color: #fff; font-size: 11px; font-weight: 400;
    padding: 4px 8px; border-radius: 4px; white-space: nowrap; z-index: 100;
    pointer-events: none; transition: opacity .15s ease, visibility .15s ease;
    transition-delay: 0s;
}
.has-tooltip .custom-tooltip::after {
    content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    border: 4px solid transparent; border-top-color: #1e293b;
}
.has-tooltip:hover .custom-tooltip {
    visibility: visible; opacity: 1; transition-delay: 500ms;
}
/* === "..." Lisää-valikko (kapea näyttö) === */
.toolbar-more-wrap { position: relative; display: none; }
.toolbar-more-wrap > .toggle-btn { font-size: 16px; letter-spacing: 2px; padding: 2px 8px; }
.toolbar-more-dropdown {
    display: none; position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 160px; background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); z-index: 500; padding: 4px;
}
.toolbar-more-wrap.open .toolbar-more-dropdown { display: block; }
.toolbar-more-item {
    display: flex; align-items: center; gap: 4px; width: 100%;
    padding: 7px 10px; border: none; background: none; cursor: pointer;
    font-size: 12px; color: var(--color-text); border-radius: 5px; text-align: left;
}
.toolbar-more-item:hover { background: var(--color-border-light); }
.toolbar-more-item.active { color: var(--color-primary); }

/* === Responsive: oletuksena kaikki näkyvät, "..." piilossa === */
.toolbar-narrow-only { display: none; }
/* toolbar-wide-only: näkyvissä oletuksena, piilotetaan kapealla */
.dropdown-search-type-section { display: none; }

@@media (max-width: 900px) {
    .toolbar-wide-only { display: none !important; }
    .toolbar-narrow-only { display: inline-flex !important; }
    .toolbar-more-wrap.toolbar-narrow-only { display: inline-flex !important; }
    .dropdown-search-type-section.toolbar-narrow-only { display: block !important; }
    .search-widget { width: 180px; }
}

@@media (max-width: 600px) {
    .search-widget { width: 140px; }
    .toolbar-row { gap: 4px; }
}

/* === Lisää suorite -nappi taulukon yläkulmassa === */
.add-item-btn-wrap {
    position: sticky; top: 0; z-index: 3;
    display: flex; justify-content: flex-end; padding: 4px 8px 2px;
    background: var(--color-bg);
}
/* === Rakennusosat 3-panel layout === */
.ro-layout { display: flex; flex-direction: column; height: 100%; }
.ro-structure-list { flex: 0 0 35%; overflow-y: auto; scroll-padding-top: 66px; }
.ro-structure-list table { width: 100%; table-layout: auto; border-collapse: collapse; font-size: 12.5px; }
.ro-structure-list th {
    position: sticky; z-index: 2;
    background: var(--color-bg); padding: 5px 8px; font-size: 11px; font-weight: 500;
    color: var(--color-text-muted); border-bottom: 1px solid var(--color-border);
    text-align: left; white-space: nowrap; box-sizing: border-box;
}
.ro-structure-list thead tr:first-child th { top: 0; height: 32px; }
.ro-structure-list thead tr:last-child th  { top: 32px; border-bottom: 2px solid var(--color-border); }
.ro-structure-list th.r { text-align: right; }
.ro-structure-list td { padding: 3px 8px; border-bottom: 1px solid var(--color-border-light); vertical-align: middle; text-align: right; }
.ro-structure-list td.col-text { text-align: left; }
.ro-structure-list td.r { text-align: right; font-variant-numeric: tabular-nums; }
.ro-structure-list td.num { font-variant-numeric: tabular-nums; }
.ro-structure-list tr { cursor: pointer; }
.ro-structure-list tr:hover td { background: var(--color-surface); }
.ro-structure-list tr.ro-row-selected td { background: rgba(37,99,235,0.07); }
.ro-structure-list th.col-bulk, .ro-structure-list td.col-bulk { width: 28px; max-width: 28px; text-align: center; padding: 2px; box-sizing: border-box; }
.ro-structure-list td.col-bulk input[type="checkbox"] { margin: 0; vertical-align: middle; }
.ro-structure-list tbody tr:focus-within td { background: rgba(37,99,235,0.07); }
.ro-structure-list tr.ro-row-header td { background: #e8f0fe !important; font-weight: 600; }
.ro-structure-list tr.ro-row-excluded td { opacity: 0.45; }
.ro-structure-list td.col-check { width: 24px; text-align: center; padding: 3px 2px; }
.ro-structure-list th.col-check { width: 24px; text-align: center; padding: 5px 2px; }
.ro-structure-list .col-indicator { width: 18px; max-width: 18px; text-align: center; overflow: hidden; padding: 0 1px; font-size: 11px; }
.ro-grid td[data-col]:focus, .ro-grid td[data-selectable]:focus {
    outline: 2px solid var(--color-primary, #2563eb); outline-offset: -2px; border-radius: 2px;
}
.ro-structure-list .ro-totals-row th {
    height: 32px; box-sizing: border-box;
    background: var(--color-surface); font-size: 12px; border-bottom: 1px solid var(--color-border);
}
.ro-structure-list .ro-totals-row .totals-label { font-weight: 600; color: var(--color-text); text-align: left; padding-left: 10px; }
.ro-structure-list .ro-totals-row .totals-val   { color: var(--color-text-muted); font-weight: 500; }
.ro-structure-list .ro-totals-row .totals-total  { color: var(--color-primary); font-weight: 700; font-size: 13px; }
/* Autocomplete dropdown for suorite selection */
.ro-suorite-autocomplete { position: relative; padding: 6px 8px; }
.ro-suorite-autocomplete input {
    width: 100%; padding: 4px 8px; font-size: 12px; border: 1px solid var(--color-border);
    border-radius: 4px; background: var(--color-bg); color: var(--color-text);
    font-family: inherit; outline: none; box-sizing: border-box;
}
.ro-suorite-autocomplete input:focus { border-color: var(--color-primary); }
.ro-suorite-autocomplete input::placeholder { color: var(--color-text-muted); }
.ro-suorite-dd {
    position: absolute; left: 8px; right: 8px; top: 100%; z-index: 500;
    max-height: 220px; overflow-y: auto;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.10);
}
.ro-suorite-dd-item {
    display: block; width: 100%; padding: 6px 10px; border: none; background: none;
    text-align: left; font-size: 12px; color: var(--color-text); cursor: pointer;
    border-bottom: 1px solid var(--color-border-light);
}
.ro-suorite-dd-item:last-child { border-bottom: none; }
.ro-suorite-dd-item:hover { background: var(--color-border-light); }
.ro-suorite-dd-item .dd-littera { font-size: 10.5px; color: var(--color-text-muted); margin-right: 4px; }
.ro-suorite-dd-item .dd-unit { font-size: 10.5px; color: var(--color-text-muted); margin-left: 4px; }
.ro-suorite-grid { flex: 1; overflow: hidden; min-height: 80px; display: flex; min-width: 0; }
.ro-suorite-grid .ro-empty-msg {
    padding: 16px; text-align: center; color: var(--color-text-muted); font-size: 12px; width: 100%;
}
/* Linjassa wwwroot/css/app.css .app-splitter-h (tummempi raita kuin pelkkä surface) */
.ro-splitter {
    height: 7px; flex-shrink: 0; background: var(--color-bg);
    border-top: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
    cursor: row-resize; display: flex; align-items: center; justify-content: center;
    font-size: 11px; letter-spacing: 3px; color: var(--color-text-muted); user-select: none;
}
.ro-splitter:hover, .ro-splitter.dragging { background: var(--color-border-light); }
/* Pystysplitter: yhteinen .app-splitter-v → wwwroot/css/app.css */
/* Left panel: Suoritteet (panokset-tyylinen) */
.ro-items-panel { flex: 0 0 45%; min-width: 200px; overflow-y: auto; overflow-x: hidden; }
.ro-items-panel .ro-delete-btn {
    background: none; border: none; cursor: pointer; color: var(--color-text-muted); font-size: 14px; padding: 0 4px; line-height: 1;
}
.ro-items-panel .ro-delete-btn:hover { color: var(--color-danger, #e53e3e); }
.ro-suorite-tbl .autocomplete-wrap { position: relative; }
.ro-suorite-tbl { overflow: visible !important; }
.ro-suorite-dd-portal {
    position: fixed; z-index: 9999;
    background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15); max-height: 200px; overflow-y: auto; min-width: 300px;
}
.ro-suorite-dd-portal .autocomplete-dd-item {
    display: block; width: 100%; text-align: left; padding: 5px 10px; border: none;
    background: none; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--color-border-light);
}
.ro-suorite-dd-portal .autocomplete-dd-item:hover { background: var(--color-surface); }
.ro-suorite-tbl tr.row-selected td { background: rgba(37,99,235,0.07); }
.ro-suorite-tbl tr:hover td { background: var(--color-surface); }
.ro-suorite-tbl tr:focus-within td { background: rgba(37,99,235,0.07); }
.ro-suorite-tbl th {
    position: sticky; top: 0; z-index: 2;
    background: var(--color-bg); padding: 4px 6px; font-size: 10px; font-weight: 600;
    color: var(--color-text-muted); border-bottom: 2px solid var(--color-border);
    text-align: left; white-space: nowrap; letter-spacing: .3px; text-transform: uppercase;
}
.ro-suorite-tbl td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ro-suorite-tbl td[data-col]:focus { outline: 2px solid var(--color-primary); outline-offset: -2px; border-radius: 2px; }
.ro-suorite-tbl .r-in { border: none; outline: none; background: transparent; }
.ro-suorite-tbl .r-in:focus { outline: none; background: transparent; }
.ro-suorite-tbl select.r-in { border: none; outline: none; background: transparent; appearance: none; -webkit-appearance: none; padding-right: 14px; }
.ro-suorite-tbl select.r-in:focus { outline: none; }
.ro-suorite-tbl .autocomplete-dd-item {
    display: block; width: 100%; text-align: left; padding: 5px 10px; border: none;
    background: none; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--color-border-light);
}
.ro-suorite-tbl .autocomplete-dd-item:hover { background: var(--color-surface); }
/* Right panel: Tabs + content — täyttää splitterin oikean puolen */
.ro-detail-panel { flex: 1; min-width: 200px; overflow: hidden; background: var(--color-surface); border-left: 1px solid var(--color-border); display: flex; flex-direction: column; }
.ro-detail-tabs {
    display: flex; gap: 0; border-bottom: 2px solid var(--color-border);
    background: var(--color-bg); flex-shrink: 0;
}
.ro-detail-tab {
    padding: 6px 14px; font-size: 11px; font-weight: 500; border: none; background: none;
    cursor: pointer; color: var(--color-text-muted); border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.ro-detail-tab:hover { color: var(--color-text); }
.ro-detail-tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }
.ro-detail-section { flex: 1; overflow-y: auto; }
.ro-detail-content-row { display: flex; flex: 1; overflow: hidden; }
.ro-detail-left { flex: 1; overflow-y: auto; min-width: 0; }
.ro-detail-right { flex: 0 0 160px; overflow-y: auto; border-left: 1px solid var(--color-border); background: var(--color-bg); }
.ro-detail-section .ro-panel-header, .ro-detail-left .ro-panel-header, .ro-detail-right .ro-panel-header {
    padding: 4px 8px; font-size: 10px; font-weight: 600; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--color-border);
    background: var(--color-bg); display: flex; align-items: center; justify-content: space-between;
}
/* Mittasuureet (oikea paneeli) */
.ro-detail-right .ro-vars-section-label {
    padding: 4px 8px 1px; font-size: 9px; font-weight: 600; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: .4px;
}
.ro-detail-right .ro-var-row {
    display: flex; align-items: center; gap: 3px; padding: 2px 8px;
    border-bottom: 1px solid var(--color-border-light); font-size: 11px;
}
.ro-detail-right .ro-var-key { flex: 0 0 24px; font-family: monospace; font-weight: 600; color: var(--color-primary); font-size: 10px; }
.ro-detail-right .ro-var-name { flex: 1; font-size: 9px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ro-detail-right .ro-var-value { flex: 0 0 auto; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; min-width: 30px; }
.ro-detail-right .ro-var-input {
    flex: 1; padding: 1px 4px; font-size: 11px; border: 1px solid var(--color-border);
    border-radius: 3px; text-align: right; background: var(--color-surface); color: var(--color-text);
    font-variant-numeric: tabular-nums; max-width: 60px;
}
.ro-detail-right .ro-var-input:focus { outline: none; border-color: var(--color-primary); }
.ro-detail-right .ro-var-unit { flex: 0 0 18px; font-size: 9px; color: var(--color-text-muted); text-align: left; }
/* Meas list in detail panel */
.ro-detail-left .ro-meas-list { list-style: none; margin: 0; padding: 0; }
.ro-detail-left .ro-meas-item {
    display: flex; align-items: center; gap: 5px; padding: 3px 8px;
    border-bottom: 1px solid var(--color-border-light); cursor: pointer; font-size: 11px;
    user-select: none;
}
.ro-detail-left .ro-meas-item:hover { background: var(--color-surface); }
.ro-detail-left .ro-meas-item.selected { background: rgba(37,99,235,0.08); }
.ro-detail-left .ro-meas-cb { width: 13px; height: 13px; accent-color: var(--color-primary); pointer-events: none; flex-shrink: 0; }
.ro-detail-left .ro-meas-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ro-detail-left .ro-meas-link { color: var(--color-text-muted); font-size: 13px; flex-shrink: 0; }
.ro-detail-left .ro-meas-link:hover { color: var(--color-primary); }
/* Empty msg */
.ro-empty-msg { padding: 12px; text-align: center; color: var(--color-text-muted); font-size: 11px; }

/* Globaalit taulukko/input tyylit (myos PanoksetPanel kayttaa naita) */
.resources-tbl { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.resources-tbl th {
    padding: 4px 6px; font-size: 10px; font-weight: 600; letter-spacing: .3px;
    color: var(--color-text-muted); border-bottom: 1px solid var(--color-border); text-align: right;
}
.resources-tbl th.tl { text-align: left; }
.resources-tbl td {
    padding: 2px 4px; border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle; text-align: right;
}
.resources-tbl td.tl { text-align: left; }
.resources-tbl tr:hover td { background: var(--color-surface); }
.r-in {
    width: 100%; background: transparent; border: none; outline: none;
    font-size: 12px; color: inherit; font-family: inherit; padding: 1px 2px;
    min-width: 0; text-align: right;
}
.r-in.l { text-align: left; }
.r-in:focus { background: var(--color-bg); border-radius: 2px; outline: 1px solid var(--color-primary); }
.r-ro { color: var(--color-text-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
