/* File Tree Classes */
#fileTree {
    font-size: 0.8em;
}
.file-tree-sidebar-upload {
    padding: 0.35rem 0.6rem;
    background: #fff;
    height: 100%;
    font-size: 0.9em;
    min-height: 44px;
    max-height: 44px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e5e5e5;
}
#file-tree-message-container, 
#boq-message-container {
    margin-bottom: 0;
}
.file-tree-sidebar-body {
    padding: 1rem 1rem 0.5rem 1rem;
    background: #fff;
    height: 100%;
    font-size: 0.9em;
}
.file-delete-btn {
    color: #dc3545;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.9em;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s, opacity 0.2s linear;
}

/* Main contents area */
.estimator-toolbar #scaleDropdownBtn { 
    position: relative; z-index: 1501; 
}
.estimator-toolbar #annotationLayerSelect { 
    margin-right: 4px; 
}
.estimator-main-area {
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
    margin-top: 0.8rem;
    margin-bottom: 0.8rem;
    margin-left: 1.3rem;
    margin-right: 0.8rem;
}
.estimator-toolbar {
    padding: 0.25rem 0.5rem;
    background: #fff;
    height: 100%;
    font-size: 0.9em;
    min-height: 46px;
    max-height: 46px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e5e5e5;
    flex-wrap: nowrap;
    white-space: nowrap; /* prevent button text wrapping */
    overflow-x: auto;   /* show horizontal scrollbar when needed */
    overflow-y: visible; /* allow dropdowns to escape vertically */
}
.estimator-toolbar .btn-group { position: relative; z-index: 1500; overflow: visible; }
.estimator-toolbar .btn-group .dropdown-menu { z-index: 1600; }
.estimator-toolbar #annotationLayerSelect { position: relative; z-index: 1; }
/* Visible vertical separators inside toolbar */
.estimator-toolbar .vr {
    flex: 0 0 auto;
    width: 1px;
    min-width: 1px;
    height: 24px; /* consistent height */
    align-self: center;
    background-color: #d0d7e2; /* subtle neutral */
    opacity: 1; /* ensure visible over gradient */
    border: 0;
}
/* Enhanced toolbar visual separation - neutral theme (no violet haze) */
.estimator-toolbar {
    background: #ffffff;
    position: relative;
}
.estimator-toolbar::after { display: none; }
/* Optional alternates (apply class on toolbar div to try) */
.estimator-toolbar.alt-bg-sky {
    background: linear-gradient(90deg, #f8fafc 0%, #e0f2fe 50%, #f8fafc 100%);
}
.estimator-toolbar.alt-bg-slate {
    background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 50%, #f8fafc 100%);
}
/* Tool buttons */
.est-tool-btn {
    position: relative;
    margin-right: 4px;
    border-color: #ced4da !important;
    background-color: #f9fafb;
    transition: background-color .15s, color .15s, box-shadow .15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1.2;
    padding: 2px 8px; /* tighten vertical height */
}
.est-tool-btn i { opacity: .85; }
.est-tool-btn:hover {
    background-color: #e9f2ff;
    border-color: #9ec5fe !important;
    color: #0d5cb6;
}
.est-tool-btn.active {
    background: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 2px rgba(13,110,253,0.25);
}
.est-tool-btn.active i { opacity: 1; }
.est-tool-btn:focus { box-shadow: 0 0 0 2px rgba(13,110,253,0.35); }
/* Compact icon+label alignment */
.est-tool-btn i { margin-right: 2px; }
/* Ensure all toolbar buttons remain a single line */
.estimator-toolbar .btn { white-space: nowrap; }
.estimator-toolbar .btn .btn-label { display: inline; }
/* Collapse labels on smaller widths to keep height consistent */
@media (max-width: 1400px) {
    .estimator-toolbar .btn .btn-label { display: none; }
}
/* Group-based theming: use data-group attributes to unify colors per functional group */
/* Theme tokens */
:root {
    /* Neutral defaults across groups to avoid color haze */
    --grp-support-bg: #ffffff;
    --grp-support-bd: #e5e7eb;   /* neutral border */
    --grp-support-fg: #334155;   /* slate-700 */

    --grp-nav-bg: #ffffff;
    --grp-nav-bd: #e5e7eb;
    --grp-nav-fg: #334155;

    --grp-scale-bg: #ffffff;
    --grp-scale-bd: #e5e7eb;
    --grp-scale-fg: #334155;

    --grp-tools-bg: #f8fafc;     /* subtle neutral for tools */
    --grp-tools-bd: #d0d7e2;     /* subtle divider */
    --grp-tools-fg: #334155;

    --grp-history-bg: #ffffff;
    --grp-history-bd: #e5e7eb;
    --grp-history-fg: #334155;

    --grp-zoom-bg: #ffffff;
    --grp-zoom-bd: #e5e7eb;
    --grp-zoom-fg: #334155;

    --danger-bg: #fff1f2;
    --danger-bd: #fecdd3;
    --danger-fg: #b91c1c;
}

/* Support group: Help + Back */
[data-group="support"].btn {
    background-color: var(--grp-support-bg);
    border-color: var(--grp-support-bd);
    color: var(--grp-support-fg);
}
[data-group="support"].btn:hover { background-color: #f8fafc; }

/* Page navigation group */
#pdfPageControls [class^="btn"],
#pdfPageControls [class*=" btn"],
#pdfPageControls input#pdfCurrentPageInput,
#pdfPageControls span#pdfTotalPagesLabel {
    /* unify visual look */
    --_bg: var(--grp-nav-bg);
    --_bd: var(--grp-nav-bd);
    --_fg: var(--grp-nav-fg);
}
#pdfPageControls .btn { background-color: var(--_bg); border-color: var(--_bd); color: var(--_fg); }
#pdfPageControls .btn:hover { background-color: #f1f5f9; }
#pdfCurrentPageInput { border-color: var(--grp-nav-bd); color: var(--grp-nav-fg); }
#pdfTotalPagesLabel { color: var(--grp-nav-fg); opacity: .8; }

/* Scale + Layers group */
[data-group="scale"].btn,
[data-group="scale"]#scaleDropdownBtn,
[data-group="scale"]#annotationLayerSelect {
    background-color: var(--grp-scale-bg);
    border-color: var(--grp-scale-bd);
    color: var(--grp-scale-fg);
}
[data-group="scale"].btn:hover,
#scaleDropdownBtn[data-group="scale"]:hover { background-color: #f8fafc; }
#annotationLayerSelect[data-group="scale"] { height: 22px !important; min-height:22px; max-height:22px; }

/* Tools group: neutral base; active tool stays primary */
[data-group="tools"].est-tool-btn {
    background-color: var(--grp-tools-bg);
    border-color: var(--grp-tools-bd) !important;
    color: var(--grp-tools-fg);
}
[data-group="tools"].est-tool-btn:hover { background-color: #e9ecef; }
.est-tool-btn.active { /* keep primary cue for the single active tool */
    background: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 2px rgba(13,110,253,0.25);
}
/* Erase remains destructive */
[data-tool="erase"].est-tool-btn { background-color: var(--danger-bg); border-color: var(--danger-bd) !important; color: var(--danger-fg); }
[data-tool="erase"].est-tool-btn:hover { background-color: #ffe4e6; }

/* History group: undo/redo */
[data-group="history"].btn { background-color: var(--grp-history-bg); border-color: var(--grp-history-bd); color: var(--grp-history-fg); }
[data-group="history"].btn:hover { background-color: #f8fafc; }

/* Zoom group */
[data-group="zoom"].btn { background-color: var(--grp-zoom-bg); border-color: var(--grp-zoom-bd); color: var(--grp-zoom-fg); }
[data-group="zoom"].btn:hover { background-color: #f8fafc; }

/* Compact other small buttons */
.estimator-toolbar .btn.btn-sm { padding: 2px 8px; line-height: 1.2; }
.estimator-toolbar .form-select.form-select-sm { height: 32px; padding-top: 2px; padding-bottom: 2px; }
.estimator-toolbar input.form-control-sm { 
    height: 22px !important;
    min-height: 22px;
    max-height: 22px;
}

/* Scale dropdown inherits group styling above; keep icon color in sync */
#scaleDropdownBtn i { color: inherit; }

/* Old per-button color rules replaced by group-based styling above */

/* Annotation layer controls inherit scale group; delete remains danger */
#annotationLayerSelect { padding-top: 2px !important; padding-bottom: 2px !important; padding-left: 8px; padding-right: 28px; line-height: 1; }
#annotationLayerDeleteBtn { background-color: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger-fg); }
#annotationLayerDeleteBtn:hover { background-color:#ffe4e6; }

/* Undo/Redo and Zoom inherit group styling */
.estimator-file-tree-sidebar {
    width: 330px;
    min-width: 330px;
    max-width: 330px;
    height: 100%;
    border-right: 1px solid #e5e5e5;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}
.list-group-item:hover .file-delete-btn {
    visibility: visible;
    opacity: 1;
}
.plan-viewer-area {
    min-height: 400px;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f8f9fa;
    position: relative;
}
.plan-placeholder-text {
    font-size: 1.1em;
    color: #888;
    display: block;
    text-align: center;
    margin: 0 auto;
    width: 100%;
    padding-top: 20px;
    padding-left: 20px;
}
.plan-viewer-bg {
    background: repeating-linear-gradient(
        0deg, #f8f9fa, #f8f9fa 39px, #e9ecef 40px
    ), repeating-linear-gradient(
        90deg, #f8f9fa, #f8f9fa 39px, #e9ecef 40px
    );
}

/* Bill of Quantities (BoQ) Sidebar */
.estimator-boq-sidebar {
    /* Width is set in setupSidebarToggle in estimator_boq.js */
    /* width: 500px; */
    /* min-width: 500px; */
    /* max-width: 500px; */
    height: 100%;
    background: #fff;
    border-right: 1px solid #e5e5e5;
    box-shadow: 0 0 4px rgba(0,0,0,0.02);
    transition: all 0.3s ease;
}
.boq-header-row {
    background: #5091e6 !important;
}
.boq-header-row > td {
    background: #5091e6 !important;
}
/* Center the grip icon in header rows */
.boq-header-row > td:first-child {
    text-align: center;
    vertical-align: middle;
}
.boq-header-row .boq-header-input-new,
.boq-header-row .boq-header-input {
    background: #5091e6 !important;
    color: #161414;
    border: none;
}
.boq-header-row .boq-header-input-new:focus,
.boq-header-row .boq-header-input:focus,
.boq-header-row .boq-header-input-new:focus {
    outline: none !important;
}
.boq-sidebar-header {
    min-height: 44px;
    border-bottom: 1px solid #e5e5e5;
    padding: 0.35rem 0.75rem;
    background: #fff;
}
.boq-sidebar-body {
    padding: 1rem 1rem 0.5rem 1rem;
    background: #fff;
    height: 100%;
    font-size: 0.9em;
}
.boq-action-btn {
    width: 110px;
    min-width: 0;
    font-size: 0.80em;
    padding: 4px 0;
    text-align: center;
}
.boq-grip-col {
    width: 5%;
    text-align: center;
    vertical-align: middle;
}
.boq-desc-col {
    width: 30%;
}
.boq-qty-col {
    width: 15%;
    text-align: center;
    vertical-align: middle;
}
.boq-unit-col {
    width: 10%;
    text-align: center;
    vertical-align: middle;
}
.boq-cost-col {
    width: 17%;
    text-align: center;
    vertical-align: middle;
}
.boq-total-col {
    width: 18%;
    text-align: center;
    vertical-align: middle;
}
.boq-actions-col {
    width: 5%;
    text-align: center;
    vertical-align: middle;
}
.boq-input-small {
    font-size: 0.85em !important;
    padding: 2px 4px !important;
    height: 2.5em !important;
    min-height: 2.5em !important;
}
.boq-unit-dropdown {
    height: 2.5em !important;
    min-height: 2.5em !important;
    padding-top: 2px !important;
    padding-bottom: 2px !important;
    font-size: 0.85em !important;
    line-height: 1.2 !important;
    text-align: left !important;
    text-align-last: left !important;
}

/* Drag and Drop Styles */
.boq-drag-handle {
    cursor: grab;
    color: #6c757d;
    padding: 2px;  /* Reduced from 4px */
    text-align: center;
    user-select: none;
    font-size: 0.9rem;  /* Slightly smaller icon */
}
.boq-drag-handle:hover {
    color: #495057;
}
.boq-drag-handle:active {
    cursor: grabbing;
}
.sortable-ghost {
    opacity: 0.4;
    background: #f0f8ff;
}
.sortable-chosen {
    box-shadow: 0 0 6px rgba(0,123,255,0.5);
}
.sortable-drag {
    transform: rotate(5deg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Template Controls */
#boqTemplateSelect {
    font-size: 0.85em;
}
#boqApplyTemplateBtn {
    font-size: 0.80em;
    padding: 4px 8px;
    min-width: 50px;
}
.sidebar-toggle-btn {
    width: 22px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #375abd; /* Default blue */
    color: white !important; /* Make icon white */
    border-radius: 0 4px 4px 0;
    box-shadow: 2px 0 5px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 1010;
    transition: all 0.2s ease;
    border: none;
    position: absolute;
    top: 50%;
    /* vertical label styling */
    writing-mode: vertical-rl;
    text-orientation: mixed;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    transform: translate(0, -50%) rotate(180deg); /* make text read top-to-bottom */
    padding: 0;
    /* Ensure toggle is clickable even when parent has overflow hidden */
    pointer-events: auto;
}
.sidebar-toggle-btn.sidebar-visible i {
    transform: rotate(0deg);
    transition: transform 0.3s ease;
}
.sidebar-toggle-btn.sidebar-hidden i {
    transform: rotate(180deg);
    transition: transform 0.3s ease;
}
.sidebar-toggle-btn:hover {
    background-color: #2a4898; /* Slightly darker blue on hover */
    box-shadow: 2px 0 7px rgba(0,0,0,0.3);
}

/* Distinguish the two handles by color */
#fileTreeSidebar .sidebar-toggle-btn { background-color: #375abd; }
#fileTreeSidebar .sidebar-toggle-btn:hover { background-color: #2a4898; }
#boqSidebar .sidebar-toggle-btn { background-color: #198754; }
#boqSidebar .sidebar-toggle-btn:hover { background-color: #146c43; }

/* Right-edge toggle placement for both sidebars */
#fileTreeSidebar .sidebar-toggle-btn,
#boqSidebar .sidebar-toggle-btn {
    right: -18px; /* attach to the sidebar's right edge */
}
/* Separate vertical positions to avoid overlap */
#fileTreeSidebar .sidebar-toggle-btn { top: calc(50% - 28px); }
#boqSidebar .sidebar-toggle-btn { top: calc(50% + 28px); }
#fileTreeSidebarLabel,
#boqSidebarLabel {
    padding-top: 0.3rem;
    line-height: 1.5;
}
.file-tree-sidebar-body hr,
.boq-sidebar-body hr {
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

/* Modals should appear above the estimator toolbar and its dropdowns */
.modal-backdrop { z-index: 1990 !important; }
.modal { z-index: 2000 !important; }
