#mud_log_app, #mud_log_app input, #mud_log_app select, #mud_log_app button, #mud_log_app table {
    font-family: Arial, Helvetica, sans-serif !important;
}

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none !important; margin: 0 !important; }
input[type=number] { -moz-appearance: textfield !important; }

.ml-sub-tabs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #0d6efd;
    margin-bottom: 15px;
    background: #f8fbff;
    padding: 6px 6px 0 6px;
    border-radius: 4px 4px 0 0;
}
.ml-sub-tabs-left {
    display: flex;
    align-items: flex-end;
}
.ml-sub-tab-item {
    padding: 6px 18px;
    text-decoration: none;
    color: #495057;
    background: #e9ecef;
    border: 1px solid #dee2e6;
    border-bottom: none;
    margin-right: 5px;
    border-radius: 4px 4px 0 0;
    font-weight: bold;
    font-size: 13px;
    transition: all 0.2s;
    cursor: pointer;
}
.ml-sub-tab-item:hover {
    background: #dde2e6;
    color: #0d6efd;
}
.ml-sub-tab-item.active {
    background: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

.btn-export-backup {
    background: #198754;
    color: #fff;
    border: none;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 4px;
    transition: background 0.2s;
}
.btn-export-backup:hover { background: #157347; }

.btn-import-backup {
    background: #0d6efd;
    color: #fff;
    border: none;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 4px;
    transition: background 0.2s;
}
.btn-import-backup:hover { background: #0b5ed7; }

/* ================================================================
   NÚT RESTORE SCOPED (Basin/Field/Well) — MỚI
   ================================================================ */
.btn-restore-scoped {
    background: #0dcaf0;
    color: #fff;
    border: none;
    padding: 4px 12px;
    font-size: 11px;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
}
.btn-restore-scoped:hover { background: #0aa2c0; }

.btn-export-img {
    background: #6f42c1;
    color: #fff;
    border: none;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
}
.btn-export-img:hover { background: #59359a; }

.setup-card {
    background: #ffffff;
    border: 1px solid #b6d4fe;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
    margin-bottom: 20px;
}
.setup-card-header {
    background: #f0f7ff;
    border-bottom: 1px solid #c8daf8;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    cursor: pointer;
}
.setup-card-body {
    padding: 20px;
}

.ml-upload-box { background: #f8fbff; border: 2px dashed #a0c4ff; padding: 20px; text-align: left; border-radius: 6px; margin-bottom: 20px; }
.ml-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 14px; }
.ml-table th, .ml-table td { border: 1px solid #ddd; padding: 8px 12px; text-align: left; }
.ml-table th { background-color: #e2edff; color: #0d6efd; }
.ml-btn-upload { background: #0d6efd; color: white; border: none; padding: 8px 18px; border-radius: 4px; cursor: pointer; font-weight: bold; transition: background 0.2s; }
.ml-btn-upload:hover { background: #0b5ed7; }
.ml-btn-del { color: #dc3545; text-decoration: none; font-weight: bold; cursor: pointer; }
.ml-btn-del:hover { text-decoration: underline; }
.check-label { cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
.check-label input[type="checkbox"] { cursor: pointer; transform: scale(1.2); accent-color: #0d6efd; }

.preview-container { margin-top: 20px; border: 1px solid #c8daf8; border-radius: 4px; background: #fff; overflow: hidden; }
.preview-header { background: #e2edff; padding: 8px 12px; border-bottom: 1px solid #c8daf8; font-weight: bold; color: #2b579a; font-size: 14px; cursor: pointer; user-select: none; }
.preview-body-scroll { max-height: 160px; overflow: auto; position: relative; }
.preview-table { width: 100%; border-collapse: collapse; font-family: Consolas, monospace; font-size: 13px; white-space: pre; }
.preview-table td { padding: 4px 8px; border-bottom: 1px dashed #eee; border-right: 1px solid #f0f0f0; }
.preview-line-num { position: sticky; left: 0; background: #f8f9fa; color: #888; text-align: right; width: 45px; min-width: 45px; user-select: none; border-right: 2px solid #ccc !important; }
.preview-content-cell { color: #333; }
.preview-table tr:hover .preview-content-cell { background-color: #f1f6fc; }
.preview-table tr:hover .preview-line-num { background-color: #e2edff; color: #0d6efd; font-weight: bold; }

.curve-select-table {
    width: 100%;
    max-width: 980px;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
    margin-top: 5px;
}
.curve-select-table th {
    background-color: #e8f2fe;
    color: #2b579a;
    font-weight: bold;
    border: 1px solid #c8daf8;
    padding: 6px 10px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
}
.curve-select-table td {
    border: 1px solid #dee2e6;
    padding: 4px 8px;
    vertical-align: middle;
}
.curve-select-table tr:hover {
    background-color: #f8fbff;
}
.col-group-search-input {
    width: 100% !important;
    padding: 4px 8px !important; border: 1px solid #0d6efd !important; border-radius: 3px !important; 
    font-weight: bold !important; color: #0d6efd !important; font-size: 13px !important; 
    background: #fff !important; margin: 0 !important; box-sizing: border-box !important;
    height: 28px !important; cursor: pointer;
}
.col-group-search-input:read-only {
    background-color: #f1f3f5 !important;
    color: #495057 !important;
    border-color: #ced4da !important;
    cursor: not-allowed !important;
}
.col-name-input {
    width: 100% !important;
    padding: 4px 8px !important; border: 1px solid #ced4da !important; border-radius: 3px !important; 
    font-weight: bold !important; color: #495057 !important; font-size: 13px !important; 
    background: #f1f3f5 !important; text-align: left !important; margin: 0 !important; box-sizing: border-box !important;
    height: 28px !important; cursor: not-allowed !important;
}
.col-unit-select {
    width: 100% !important;
    padding: 4px 6px !important; border: 1px dashed #adb5bd !important; border-radius: 3px !important; 
    font-weight: bold !important; color: #d63384 !important; font-size: 13px !important; 
    background: #fff !important; text-align: center !important; margin: 0 !important; box-sizing: border-box !important;
    height: 28px !important; cursor: pointer; outline: none !important;
}
.col-group-search-input:focus, .col-unit-select:focus {
    border-color: #0d6efd !important; box-shadow: 0 0 0 2px rgba(13,110,253,.2) !important;
}

.track-setup-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
}
.track-setup-table th {
    background-color: #f1f6fc;
    color: #000;
    font-weight: bold;
    border: 1px solid #c8daf8;
    padding: 6px 4px;
    text-align: center;
    white-space: nowrap;
}
.track-setup-table td {
    border: 1px solid #dee2e6;
    padding: 4px 6px;
    text-align: center;
    vertical-align: middle;
}
.track-setup-table input[type="text"], 
.track-setup-table input[type="number"], 
.track-setup-table select {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ced4da;
    border-radius: 3px;
    padding: 3px 5px;
    font-size: 13px;
    text-align: center;
}
.track-setup-table input:disabled {
    background-color: #e9ecef !important;
    color: #adb5bd !important;
    cursor: not-allowed;
    border-color: #dee2e6 !important;
}
.track-setup-table input[type="checkbox"] {
    cursor: pointer;
    transform: scale(1.15);
    accent-color: #dc3545;
}
.btn-track-action {
    background: #0d6efd;
    color: #fff;
    border: none;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    font-weight: bold;
}
.btn-track-action:hover { background: #0b5ed7; }

.active-file-row {
    background-color: #e8f4fd !important;
}

.log-viewer-container {
    display: block;
    border: 2px solid #000;
    background: #fff;
    overflow-x: auto;
    overflow-y: auto;
    height: calc(100vh - 180px);
    min-height: 550px;
    max-height: none;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.05);
    position: relative;
    -webkit-overflow-scrolling: touch;
}
.log-viewer-content-wrapper {
    display: inline-flex;
    flex-direction: column;
    min-width: 100%;
    min-height: 100%;
    position: relative;
}
.log-headers-row {
    display: flex;
    flex-direction: row;
    position: sticky;
    top: 0;
    z-index: 30;
    background: #f8fbff;
    border-bottom: 2px solid #000;
}
.log-bodies-row {
    display: flex;
    flex-direction: row;
    position: relative;
    flex-grow: 1;
}
.log-track-header {
    background: #f8fbff;
    border-right: 2px solid #000;
    padding: 6px 4px 8px 4px;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow: hidden;
    flex-shrink: 0;
}
.log-track-body {
    position: relative;
    background-color: #fff;
    box-sizing: border-box;
    border-right: 2px solid #000;
    flex-shrink: 0;
}
.depth-track-body {
    background-color: #f8f9fa;
    position: relative;
    box-sizing: border-box;
    border-right: 2px solid #000;
    border-left: 2px solid #000;
    flex-shrink: 0;
}
.depth-label-text {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: #000;
    font-size: 12px;
    background: #e9ecef;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #ced4da;
    z-index: 5;
    white-space: nowrap;
    user-select: none;
    pointer-events: none;
}
.curve-svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}
.header-resize-handle {
    position: absolute;
    bottom: -3px;
    left: 0;
    right: 0;
    width: 100%;
    height: 6px;
    background: #0d6efd;
    opacity: 0.35;
    cursor: row-resize;
    z-index: 40;
    transition: opacity 0.2s, height 0.2s, background 0.2s;
}
.header-resize-handle:hover, .header-resize-handle.resizing {
    opacity: 0.95;
    background: #dc3545;
    height: 8px;
    bottom: -4px;
}

.crosshair-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 1.5px;
    background: red;
    pointer-events: none;
    z-index: 25;
    display: none;
}
.log-crosshair-tooltip {
    position: fixed;
    display: none;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    color: #212529;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    border: 1px solid #ced4da;
    line-height: 1.4;
    max-width: 280px;
}
.log-crosshair-tooltip .tt-depth {
    font-weight: bold;
    color: #0d6efd;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 3px;
    margin-bottom: 4px;
    font-size: 13px;
}

.ml-analysis-active {
    cursor: crosshair !important;
}
.ml-analysis-active * {
    cursor: crosshair !important;
}

.analysis-modal-overlay {
    position: fixed;
    top: 75px;
    right: 25px;
    width: 340px;
    display: none;
    z-index: 9999;
    pointer-events: none; 
}
.analysis-modal-card {
    background: #ffffff;
    border-radius: 6px;
    width: 100%;
    border: 2px solid #0d6efd;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto; 
}
.analysis-modal-header {
    background: #f0f7ff;
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1.5px solid #0d6efd;
    cursor: move;
    user-select: none;
}
.analysis-modal-body {
    padding: 8px 10px;
    overflow: hidden;
}
.analysis-charts-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}
.analysis-chart-box {
    border: 1px solid #c8daf8;
    border-radius: 4px;
    padding: 4px;
    background: #f8fbff;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#pop_triangle_svg {
    width: 100%;
    max-width: 180px;
    height: auto;
    display: block;
}

.curve-quick-edit-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}
.curve-quick-edit-card {
    background: #fff;
    border-radius: 6px;
    width: 380px;
    border: 2px solid #0d6efd;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    overflow: hidden;
}
.curve-quick-edit-header {
    background: #f0f7ff;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #c8daf8;
    font-weight: bold;
    color: #2b579a;
}
.curve-quick-edit-body {
    padding: 15px;
    font-size: 13px;
}
.curve-quick-edit-body .form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.curve-quick-edit-body label {
    font-weight: bold;
    color: #495057;
}
.curve-quick-edit-body input, .curve-quick-edit-body select {
    width: 180px;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 3px;
    font-size: 13px;
}

/* ================================================================
   CÂY THƯ MỤC PROJECT/FIELD/WELL
   ================================================================ */
.tree-sidebar { 
    width: 280px; 
    flex-shrink: 0; 
    background: #f8fbff; 
    border: 1px solid #c8daf8; 
    border-radius: 4px; 
    padding: 10px; 
    height: calc(100vh - 40px); 
    overflow-y: auto; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); 
}
.tree-node { margin-left: 15px; margin-top: 4px; list-style-type: none; }
.tree-item-box { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; border-radius: 3px; cursor: pointer; transition: background 0.2s; border: 1px solid transparent; }
.tree-item-box:hover { background: #e2edff; border-color: #c8daf8; }
.tree-item-box.active { background: #0d6efd; color: white !important; font-weight: bold; }
.tree-item-box.active .tree-label { color: white !important; }
.tree-icon { margin-right: 6px; font-size: 14px; }
.tree-label { font-size: 13px; color: #333; flex-grow: 1; user-select: none; }
.tree-btn-group { display: none; gap: 4px; }
.tree-item-box:hover .tree-btn-group { display: flex; }
.tree-btn { background: none; border: none; font-size: 12px; cursor: pointer; padding: 0 2px; }
.tree-btn:hover { transform: scale(1.2); }

/* ================================================================
   CONTEXT MENU CHO TREE NODE (Basin/Field/Well) — MỚI
   ================================================================ */
.tree-context-menu {
    position: fixed;
    display: none;              /* ẨN MẶC ĐỊNH — chỉ hiện khi chuột phải */
    z-index: 99999;
    background: #ffffff;
    border: 1px solid #c8daf8;
    border-radius: 5px;
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.18);
    min-width: 210px;
    padding: 4px 0;
    font-size: 13px;
    font-family: Arial, Helvetica, sans-serif;
    user-select: none;
    animation: ctxFadeIn 0.12s ease-out;
}
@keyframes ctxFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.tree-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    color: #333;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}
.tree-ctx-item:hover {
    background: #e2edff;
    color: #0d6efd;
}
.tree-ctx-item .tree-ctx-icon {
    display: inline-flex;
    width: 18px;
    justify-content: center;
    font-size: 13px;
}
.tree-ctx-separator {
    height: 1px;
    background: #e9ecef;
    margin: 4px 0;
}
.tree-ctx-item-danger {
    color: #dc3545;
}
.tree-ctx-item-danger:hover {
    background: #f8d7da;
    color: #b02a37;
}
/* ================================================================
   FIX LAYOUT TOOLBAR LOGS VIEW — Depth Type + Reference dropdowns
   ================================================================ */

/* Toolbar chính: cho phép wrap khi hẹp */
#subtab_logs_view > div:first-child {
    flex-wrap: wrap !important;
}

/* Container chứa các control bên trái: cho phép wrap */
#subtab_logs_view > div:first-child > div:first-child {
    flex-wrap: wrap !important;
    gap: 10px !important;
    row-gap: 8px !important;
}

/* Scale dropdown: giới hạn width */
#log_view_scale_select {
    max-width: 170px !important;
}

/* Depth Type dropdown: giới hạn width */
#log_view_depth_type_select {
    max-width: 105px !important;
}

/* Reference dropdown: giới hạn width, ellipsis khi tên file dài */
#log_view_reference_select {
    max-width: 340px !important;
    min-width: 160px !important;
    text-overflow: ellipsis !important;
    overflow: hidden !important;
    white-space: nowrap !important;
}

/* Reference wrapper: đảm bảo không bị vỡ layout */
#reference_wrapper {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    max-width: 420px !important;
    flex-shrink: 1 !important;
    min-width: 0 !important;
}

/* Nhóm View Interval + Depth Range: cho phép wrap */
#subtab_logs_view > div:first-child > div:first-child > div {
    flex-wrap: wrap !important;
}