/* ASAP Estimating — professional blue theme, RTL/LTR, dense estimator UI */

:root {
    --asap-navy: #0c2340;
    --asap-navy-light: #1a3a5c;
    --asap-blue: #1e5a96;
    --asap-blue-mid: #2d6fad;
    --asap-blue-light: #e8f1fa;
    --asap-blue-calc: #f0f6fc;
    --asap-accent: #0ea5e9;
    --asap-success: #15803d;
    --asap-warning: #b45309;
    --asap-danger: #b91c1c;
    --asap-border: #c5d4e8;
    --asap-border-light: #dce6f2;
    --asap-text: #1e293b;
    --asap-text-muted: #64748b;
    --asap-bg: #f4f7fb;
    --asap-surface: #ffffff;
    --asap-header-h: 52px;
    --asap-subnav-h: 42px;
    --asap-radius: 4px;
    --asap-font: 'Segoe UI', Tahoma, 'Noto Sans Arabic', Arial, sans-serif;
    --asap-mono: 'Consolas', 'Courier New', monospace;
    --asap-shadow: 0 1px 3px rgba(12, 35, 64, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; }

body {
    margin: 0;
    font-family: var(--asap-font);
    color: var(--asap-text);
    background: var(--asap-bg);
    line-height: 1.45;
    min-height: 100vh;
}

[dir="rtl"] body { font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif; }

a { color: var(--asap-blue); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--asap-navy-light); }

/* Layout */
.app-header {
    background: var(--asap-navy);
    color: #fff;
    height: var(--asap-header-h);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: var(--asap-shadow);
}

.app-brand {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    white-space: nowrap;
}
.app-brand:hover { text-decoration: none; color: #fff; opacity: 0.9; }

.app-nav {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    flex-wrap: wrap;
}
.app-nav a {
    color: rgba(255,255,255,0.85);
    padding: 0.35rem 0.65rem;
    border-radius: var(--asap-radius);
    font-size: 0.875rem;
}
.app-nav a:hover, .app-nav a.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    text-decoration: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-inline-start: auto;
}

.locale-form { display: inline; }
.locale-form select {
    background: var(--asap-navy-light);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--asap-radius);
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.user-menu { font-size: 0.85rem; color: rgba(255,255,255,0.9); }
.user-menu a { color: rgba(255,255,255,0.75); margin-inline-start: 0.5rem; }

.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.page-header h1 {
    margin: 0;
    font-size: 1.35rem;
    color: var(--asap-navy);
    font-weight: 600;
}

/* Bid sticky header */
.bid-header {
    background: var(--asap-surface);
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem 1rem;
    position: sticky;
    top: var(--asap-header-h);
    z-index: 150;
    box-shadow: var(--asap-shadow);
}
.bid-header .meta-label { font-size: 0.7rem; color: var(--asap-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.bid-header .meta-value { font-weight: 600; font-size: 0.9rem; }
.bid-header .status-badge { display: inline-block; }

.bid-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem;
    background: var(--asap-surface);
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    padding: 0.35rem;
    margin-bottom: 1rem;
    position: sticky;
    top: calc(var(--asap-header-h) + 4px);
    z-index: 140;
}
.bid-subnav a {
    padding: 0.35rem 0.65rem;
    border-radius: var(--asap-radius);
    font-size: 0.8rem;
    color: var(--asap-text);
    white-space: nowrap;
}
.bid-subnav a:hover { background: var(--asap-blue-light); text-decoration: none; }
.bid-subnav a.active {
    background: var(--asap-blue);
    color: #fff;
}

/* Cards & panels */
.card {
    background: var(--asap-surface);
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    box-shadow: var(--asap-shadow);
    margin-bottom: 1rem;
}
.card-header {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--asap-border-light);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--asap-navy);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.card-body { padding: 0.85rem; }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group[hidden],
.tree-add-mp[hidden] { display: none !important; }
.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--asap-text-muted);
}
.form-group.full { grid-column: 1 / -1; }

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="file"],
select, textarea {
    font: inherit;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    background: var(--asap-surface);
    color: var(--asap-text);
    width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--asap-blue);
    box-shadow: 0 0 0 2px rgba(30, 90, 150, 0.15);
}

.field-input { background: #fff !important; }
.field-calc {
    background: var(--asap-blue-calc) !important;
    color: var(--asap-navy);
    font-family: var(--asap-mono);
    font-size: 0.85rem;
}
.field-calc[readonly] { cursor: default; }
.field-input[readonly] {
    background: var(--asap-blue-light, #eef4fb);
    cursor: default;
}

/* Per-field BiDi: Arabic → RTL/right, English → LTR/left (overrides page dir) */
input.field-bidi[dir="rtl"],
textarea.field-bidi[dir="rtl"],
.field-bidi[dir="rtl"],
td.field-bidi[dir="rtl"] {
    direction: rtl;
    text-align: right;
    unicode-bidi: isolate;
}
input.field-bidi[dir="ltr"],
textarea.field-bidi[dir="ltr"],
.field-bidi[dir="ltr"],
td.field-bidi[dir="ltr"] {
    direction: ltr;
    text-align: left;
    unicode-bidi: isolate;
}
.excel-formula-bar .formula-input.field-bidi[dir="rtl"] { text-align: right; }
.excel-formula-bar .formula-input.field-bidi[dir="ltr"] { text-align: left; }

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--asap-radius);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.3;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--asap-blue); color: #fff; border-color: var(--asap-blue); }
.btn-primary:hover { background: var(--asap-navy-light); color: #fff; }
.btn-secondary { background: var(--asap-surface); color: var(--asap-text); border-color: var(--asap-border); }
.btn-secondary:hover { background: var(--asap-blue-light); }
.btn-danger { background: var(--asap-danger); color: #fff; }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.78rem; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--asap-blue); }
.btn-ghost:hover { background: var(--asap-blue-light); }

/* Tables — dense estimator */
.table-wrap { overflow-x: auto; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
table.data-table th,
table.data-table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--asap-border-light);
    text-align: start;
    vertical-align: middle;
}
table.data-table th {
    background: var(--asap-blue-light);
    color: var(--asap-navy);
    font-weight: 600;
    font-size: 0.75rem;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}
table.data-table tr:hover td { background: rgba(232, 241, 250, 0.5); }
table.data-table .num {
    font-family: var(--asap-mono);
    text-align: end;
    white-space: nowrap;
}
table.data-table th.col-check,
table.data-table td.col-check {
    width: 2.2rem;
    text-align: center;
}
table.data-table input, table.data-table select {
    padding: 0.2rem 0.35rem;
    font-size: 0.82rem;
    min-width: 60px;
}
table.data-table.compact th,
table.data-table.compact td { padding: 0.25rem 0.4rem; }

/* Tree UI */
.tree-panel { font-size: 0.82rem; }
.tree-toolbar {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.tree-list { list-style: none; margin: 0; padding: 0; }
.tree-node { margin: 0; }
.tree-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.4rem;
    border-bottom: 1px solid var(--asap-border-light);
    cursor: grab;
}
.tree-row:hover { background: var(--asap-blue-light); }
.tree-row.selected { background: #dbeafe; }
.tree-toggle {
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    color: var(--asap-blue);
    font-size: 0.7rem;
    flex-shrink: 0;
}
.tree-toggle.placeholder { visibility: hidden; }
.tree-indent { flex-shrink: 0; }
.tree-label { flex: 1; min-width: 0; }
.tree-label .node-id {
    font-family: var(--asap-mono);
    font-size: 0.7rem;
    margin-inline-end: 0.25rem;
}
.tree-label .node-name { font-weight: 500; }
.tree-label .node-type {
    font-size: 0.7rem;
    color: var(--asap-text-muted);
    margin-inline-start: 0.35rem;
}
.cost-node-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.75rem 1rem;
    margin-bottom: 0.85rem;
    padding: 0.65rem 0.75rem;
    background: var(--asap-blue-light, #eef4fb);
    border: 1px solid var(--asap-border-light);
    border-radius: var(--asap-radius);
}
.cost-node-summary .meta-label {
    font-size: 0.72rem;
    color: var(--asap-text-muted);
    font-weight: 600;
}
.cost-node-summary .meta-value { font-size: 0.9rem; font-weight: 500; }
.tree-row[data-node-id] { cursor: grab; }
.tree-row.tree-dragging { opacity: 0.4; }
.tree-row.tree-drop-ok,
.tree-boq-header.tree-drop-ok {
    outline: 2px solid var(--asap-blue);
    outline-offset: -2px;
    background: #dbeafe;
}
.tree-row.tree-drop-bad { outline: 2px solid #fca5a5; outline-offset: -2px; }
body.tree-is-dragging,
body.tree-is-dragging * { cursor: grabbing !important; user-select: none !important; }
.tree-drag-ghost {
    position: fixed;
    z-index: 11000;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.65rem;
    min-width: 160px;
    max-width: min(360px, 80vw);
    background: #fff;
    border: 1px solid var(--asap-blue);
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(12, 35, 64, 0.22);
    opacity: 0.96;
}
.tree-drag-hint {
    font-size: 0.75rem;
    margin-inline-start: auto;
}
.tree-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.1rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.tree-row:hover .tree-actions,
.tree-row.selected .tree-actions,
.tree-boq-header:hover .tree-action {
    opacity: 1;
}
.tree-action {
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--asap-text-muted);
    width: 1.4rem;
    height: 1.4rem;
    line-height: 1;
    padding: 0;
    border-radius: 3px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.tree-action-add { font-weight: 600; font-size: 1rem; }
.tree-action:hover { background: rgba(12, 35, 64, 0.08); color: var(--asap-navy); }
.tree-action-delete { font-size: 0.75rem; opacity: 0.75; }
.tree-action-delete:hover { color: var(--asap-danger); background: #fee2e2; }
.tree-boq-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--asap-navy);
    margin-bottom: 0.35rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--asap-border-light);
}
.tree-boq-title { flex: 1; min-width: 0; }
.tree-boq-header .tree-action { opacity: 0.55; }
.tree-empty-hint { margin: 0.35rem 0 0.5rem 1.25rem; font-size: 0.8rem; }

.tree-add-popover {
    position: absolute;
    z-index: 400;
    min-width: 260px;
    max-width: 360px;
    width: 320px;
    background: var(--asap-surface, #fff);
    border: 1px solid var(--asap-border, #c5d4e8);
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(12, 35, 64, 0.15);
    padding: 0.35rem;
}
.tree-row[data-node-type="ACTIVITY"] .node-type {
    color: var(--asap-blue);
}
.tree-add-popover[hidden] { display: none !important; }
.tree-add-option {
    display: block;
    width: 100%;
    text-align: start;
    border: none;
    background: transparent;
    padding: 0.55rem 0.65rem;
    border-radius: 3px;
    cursor: pointer;
    font: inherit;
    color: var(--asap-text);
}
.tree-add-option:hover { background: var(--asap-blue-light); color: var(--asap-navy); }
.tree-add-step[data-step="item"],
.tree-add-step[data-step="sub"] { padding: 0.35rem; }
.tree-add-step[data-step="item"] label,
.tree-add-step[data-step="sub"] label { font-size: 0.75rem; color: var(--asap-text-muted); }
.tree-metrics {
    display: flex;
    gap: 0.75rem;
    font-family: var(--asap-mono);
    font-size: 0.78rem;
    color: var(--asap-navy);
    flex-shrink: 0;
}
.tree-metrics .metric { min-width: 70px; text-align: end; }
.tree-children { list-style: none; margin: 0; padding-inline-start: 1.25rem; }
.tree-children.collapsed { display: none; }

/* Combobox */
.combobox { position: relative; }
.combobox-input { width: 100%; }
.combobox-dropdown {
    position: absolute;
    top: 100%;
    inset-inline-start: 0;
    inset-inline-end: 0;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    box-shadow: 0 8px 24px rgba(12, 35, 64, 0.18);
    z-index: 300;
    display: none;
}
.combobox-dropdown.open,
.combobox-dropdown-fixed.open {
    display: block !important;
}
.combobox-dropdown-fixed {
    max-height: min(320px, 50vh);
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    box-shadow: 0 8px 24px rgba(12, 35, 64, 0.18);
}
.combobox-option {
    padding: 0.45rem 0.65rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--asap-border-light);
    background: #fff;
}
.combobox-option:hover, .combobox-option.highlighted { background: var(--asap-blue-light); }
.combobox-option .opt-code { color: var(--asap-text-muted); font-size: 0.75rem; }
.combobox-option .opt-alt {
    display: block;
    color: var(--asap-text-muted);
    font-size: 0.78rem;
    margin-top: 0.12rem;
}
.combobox-msg { color: var(--asap-text-muted); cursor: default; font-style: italic; }
.combobox-msg-error { color: var(--asap-danger, #b91c1c); }

/* Badges & flash */
.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-estimating { background: #dbeafe; color: #1d4ed8; }
.badge-under_review { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dcfce7; color: #166534; }
.badge-submitted { background: #e0e7ff; color: #3730a3; }
.badge-won { background: #bbf7d0; color: #14532d; }
.badge-lost { background: #fecaca; color: #991b1b; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }

.flash {
    padding: 0.65rem 0.85rem;
    border-radius: var(--asap-radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.flash-success { background: #dcfce7; border: 1px solid #86efac; color: #14532d; }
.flash-error { background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--asap-surface);
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    padding: 0.75rem;
    text-align: center;
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--asap-blue); }
.stat-card .stat-label { font-size: 0.75rem; color: var(--asap-text-muted); margin-top: 0.15rem; }

/* Thumbnails */
.thumb-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    background: var(--asap-bg);
}

/* Login (guest layout) */
.guest-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--asap-navy) 0%, var(--asap-blue) 100%);
    padding: 1rem;
}
.login-card {
    background: var(--asap-surface);
    border-radius: 6px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 380px;
    padding: 2rem;
}
.login-card h1 {
    margin: 0 0 0.25rem;
    font-size: 1.25rem;
    color: var(--asap-navy);
    text-align: center;
}
.login-card .tagline {
    text-align: center;
    color: var(--asap-text-muted);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

/* Autosave indicator */
.autosave-status {
    font-size: 0.75rem;
    color: var(--asap-text-muted);
    font-style: italic;
}
.autosave-status.saving { color: var(--asap-warning); }
.autosave-status.saved { color: var(--asap-success); }
.autosave-status.error { color: var(--asap-danger); }

/* Print — A4 quotation */
@media print {
    .app-header, .bid-subnav, .form-actions, .no-print, .tree-toolbar,
    .btn, .locale-form, .user-menu, .flash { display: none !important; }

    body { background: #fff; font-size: 11pt; }
    .app-main { max-width: none; padding: 0; }

    .print-quotation {
        width: 210mm;
        min-height: 297mm;
        margin: 0 auto;
        padding: 12mm 15mm;
    }
    .print-quotation .q-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        border-bottom: 2px solid var(--asap-navy);
        padding-bottom: 8mm;
        margin-bottom: 6mm;
    }
    .print-quotation .q-logo { max-height: 18mm; max-width: 50mm; }
    .print-quotation table { page-break-inside: avoid; }
    .print-quotation .q-totals { margin-top: 6mm; text-align: end; }
    .print-quotation .q-terms { margin-top: 8mm; font-size: 9pt; color: #333; }
}

@media (max-width: 768px) {
    .app-nav { display: none; }
    .bid-header { position: relative; top: auto; }
    .tree-metrics { flex-direction: column; gap: 0.15rem; align-items: flex-end; }
}

/* Masters dropdown */
.nav-dropdown { position: relative; display: inline-block; }
.nav-drop-btn {
    background: transparent; border: none; color: rgba(255,255,255,0.85);
    padding: 0.35rem 0.65rem; border-radius: var(--asap-radius); cursor: pointer; font: inherit;
}
.nav-drop-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-drop-menu {
    display: none; position: absolute; top: 100%; inset-inline-start: 0;
    background: #fff; min-width: 220px; border: 1px solid var(--asap-border);
    box-shadow: var(--asap-shadow); border-radius: var(--asap-radius); z-index: 300; padding: 0.35rem 0;
}
.nav-dropdown:hover .nav-drop-menu, .nav-dropdown:focus-within .nav-drop-menu { display: block; }
.nav-drop-menu-wide { min-width: 14rem; }
.nav-drop-divider { border: none; border-top: 1px solid var(--asap-border-light); margin: 0.35rem 0; }

.split-pane {
    display: grid;
    grid-template-columns: minmax(220px, 28%) 1fr;
    gap: 1rem;
    align-items: start;
}
.split-pane-left { min-width: 0; }
.split-pane-right { min-width: 0; }

/* Cost build-up: use full page width/height so rate search is usable */
body:has(#cost-split) .app-main {
    max-width: none;
    padding-inline: 0.75rem;
}
#cost-split {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    align-items: stretch;
    min-height: calc(100vh - 11rem);
}
#cost-split .split-pane-right,
#cost-split .split-pane-right > .card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}
#cost-split .split-pane-right > .card {
    flex: 1;
}
#cost-split .split-pane-right > .card > .card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 0.75rem;
}
.cost-add-bar {
    display: grid;
    grid-template-columns: 9rem minmax(14rem, 1.6fr) 6.5rem 6rem 6rem auto;
    gap: 0.5rem 0.65rem;
    align-items: end;
    padding: 0.65rem 0.75rem;
    background: #f7fafc;
    border: 1px solid var(--asap-border-light);
    border-radius: var(--asap-radius);
    flex-shrink: 0;
}
.cost-add-bar .form-group { margin: 0; }
.cost-add-bar .cost-add-rate { min-width: 0; }
.cost-add-bar .cost-mp-only[hidden] { display: none !important; }
.cost-table-wrap {
    flex: 1;
    min-height: 14rem;
    max-height: none;
    overflow: auto;
    border: 1px solid var(--asap-border-light);
    border-radius: var(--asap-radius);
}
.cost-table-wrap .excel-grid {
    min-width: 1100px;
    width: 100%;
}
.combobox-dropdown-fixed {
    max-height: min(320px, 50vh);
}
@media (max-width: 960px) {
    #cost-split {
        grid-template-columns: 1fr;
    }
    .cost-add-bar {
        grid-template-columns: 1fr 1fr;
    }
    .cost-add-bar .cost-add-rate,
    .cost-add-bar .cost-add-action {
        grid-column: 1 / -1;
    }
}
.tree-boq-group { margin-bottom: 1rem; }
.excel-grid tr.row-selected td { background: #dbeafe !important; }
.translating-target { transition: opacity 0.2s ease; }
.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.35rem 1rem;
}
.perm-check { font-size: 0.82rem; display: flex; align-items: center; gap: 0.35rem; }
.nav-drop-menu a {
    display: block; padding: 0.45rem 0.85rem; color: var(--asap-text); font-size: 0.875rem;
}
.nav-drop-menu a:hover { background: var(--asap-blue-light); text-decoration: none; }

/* Excel formula bar */
.excel-formula-bar {
    display: flex; align-items: center; gap: 0.5rem;
    background: #fff; border: 1px solid var(--asap-border); border-radius: var(--asap-radius);
    padding: 0.35rem 0.6rem; margin-bottom: 0.75rem;
}
.formula-label {
    font-family: var(--asap-mono); font-weight: 700; color: var(--asap-blue);
    padding: 0 0.4rem;
}
.formula-input { flex: 1; border: none !important; box-shadow: none !important; background: transparent !important; }

/* Excel grid cells */
.excel-grid { border-collapse: collapse; width: 100%; table-layout: auto; }
.excel-grid th, .excel-grid td {
    border: 1px solid var(--asap-border); padding: 0 !important; vertical-align: middle;
}
.excel-grid th { background: var(--asap-blue-light); padding: 0.4rem 0.5rem !important; font-weight: 600; white-space: nowrap; }
.excel-grid .excel-cell, .excel-grid select.field-input, .excel-grid input.field-input {
    width: 100%; min-width: 3.5rem; border: none !important; border-radius: 0 !important;
    background: #fff; padding: 0.35rem 0.45rem; box-shadow: none !important;
}
.excel-grid .cell-grow { min-width: 12rem; }
.excel-grid .boq-desc,
#ocr-drafts-table .ocr-desc {
    min-width: 16rem;
    min-height: 4.5rem;
    white-space: pre-wrap;
    line-height: 1.45;
    resize: vertical;
}
.excel-grid .cell-wide { min-width: 10rem; padding: 0.35rem 0.45rem !important; }
.excel-grid .field-calc {
    background: var(--asap-blue-calc) !important; color: #334155;
    padding: 0.35rem 0.45rem !important; white-space: nowrap;
}
.excel-grid .cell-active, .excel-grid .excel-cell:focus {
    outline: 2px solid var(--asap-accent); outline-offset: -2px; z-index: 1; position: relative;
}
.excel-grid .row-actions { text-align: center; width: 2.2rem; background: #fafbfc; }
.btn-icon {
    border: none; background: transparent; cursor: pointer; font-size: 1.1rem; line-height: 1;
    color: var(--asap-text-muted); padding: 0.25rem 0.4rem;
}
.btn-icon.danger:hover { color: var(--asap-danger); background: #fee2e2; border-radius: 3px; }
.help-text { color: var(--asap-text-muted); margin: 0 0 0.75rem; font-size: 0.9rem; }
.muted { color: var(--asap-text-muted); font-size: 0.8rem; }
.translating { opacity: 0.6; }
.customer-select-row { display: flex; gap: 0.5rem; align-items: center; }
.customer-select-row select { flex: 1; }
.asap-dialog {
    border: 1px solid var(--asap-border); border-radius: 8px; padding: 1.25rem; max-width: 420px; width: 90%;
}
.asap-dialog.asap-dialog-wide { max-width: 720px; }
.asap-dialog::backdrop { background: rgba(12,35,64,0.35); }
.mat-edit-media {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 0.85rem;
}
.mat-edit-preview {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border: 1px solid var(--asap-border);
    border-radius: var(--asap-radius);
    background: var(--asap-bg);
    flex-shrink: 0;
}
.mat-edit-preview.is-empty { display: none; }
.mat-edit-placeholder {
    width: 140px;
    height: 140px;
    border: 1px dashed var(--asap-border);
    border-radius: var(--asap-radius);
    background: var(--asap-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.5rem;
    flex-shrink: 0;
}
.mat-edit-placeholder[hidden],
.mat-edit-preview[hidden] { display: none !important; }
.mat-row-edit { cursor: pointer; }
.mat-row-edit:hover { background: var(--asap-blue-light); }
.mat-edit-error { color: var(--asap-danger); font-size: 0.85rem; margin: 0 0 0.5rem; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }
.kpi { background: var(--asap-blue-light); border-radius: var(--asap-radius); padding: 0.75rem; }
.kpi-label { font-size: 0.75rem; color: var(--asap-text-muted); }
.kpi-value { font-size: 1.15rem; font-weight: 700; color: var(--asap-navy); }

/* UNSPSC browser */
.unspsc-browser {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-top: 1rem;
}
@media (max-width: 1100px) {
    .unspsc-browser { grid-template-columns: 1fr 1fr; }
}
.unspsc-col .unspsc-list {
    max-height: 420px;
    overflow: auto;
    padding: 0.35rem !important;
}
.unspsc-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    text-align: start;
    border: none;
    background: transparent;
    padding: 0.45rem 0.55rem;
    border-radius: var(--asap-radius);
    cursor: pointer;
    color: inherit;
    font: inherit;
    border-bottom: 1px solid var(--asap-border-light);
}
.unspsc-item:hover { background: var(--asap-blue-light); }
.unspsc-item.active { background: #dbeafe; }
.unspsc-item strong { font-family: var(--asap-mono); font-size: 0.8rem; color: var(--asap-blue); }
.unspsc-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.25rem; }
.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    background: var(--asap-blue-light);
    color: var(--asap-navy);
}

.sub-tree-table .sub-parent td {
    background: #f3f7fb;
    font-weight: 500;
}
.sub-tree-table .sub-child td { background: #fff; }
.sub-tree-table .sub-tree-name {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 16rem;
}
.sub-tree-table .sub-code {
    font-family: var(--asap-mono);
    font-size: 0.72rem;
    color: var(--asap-text-muted);
    flex-shrink: 0;
}
.sub-tree-table .sub-branch {
    color: var(--asap-text-muted);
    margin-inline-end: 0.15rem;
    opacity: 0.7;
}
.sub-tree-table .sub-empty-cell { padding-inline-start: 2.4rem; font-size: 0.8rem; }
.sub-tree-table .sub-tree-actions {
    white-space: nowrap;
    width: 1%;
}
.sub-tree-table .sub-tree-actions .tree-action { opacity: 0.55; }
.sub-tree-table tr:hover .sub-tree-actions .tree-action { opacity: 1; }
.sub-tree-table .node-type-manpower { color: #0f766e; }
.sub-tree-table .node-type-material { color: var(--asap-blue); }
.sub-tree-table .node-type-equipment { color: #a16207; }

.comm-ifthen {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.55rem 0.65rem;
}
.comm-ifthen > select.field-input {
    width: auto;
    min-width: 16rem;
    flex: 1 1 16rem;
}
.comm-word {
    font-weight: 700;
    color: var(--asap-navy);
    padding-bottom: 0.45rem;
}
.comm-extra {
    min-width: 14rem;
    flex: 1 1 14rem;
}
.comm-extra[hidden] { display: none !important; }
.inline-form { display: inline-block; margin-inline-end: 0.25rem; }

/* Competition details — ASAP blue (not Etimad green) */
.etimad-details { margin-bottom: 1.25rem; }
.etimad-page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.85rem;
}
.etimad-page-head h1 {
    margin: 0;
    font-size: 1.45rem;
    color: var(--asap-navy);
}
.etimad-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    position: sticky;
    top: calc(var(--asap-header-h) + 96px);
    z-index: 135;
    background: var(--asap-bg);
    padding: 0.35rem 0;
}
.etimad-tab {
    flex: 1 1 6.5rem;
    min-width: 5.5rem;
    max-width: 9.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35rem;
    padding: 0.55rem 0.4rem 0.45rem;
    border: 1px solid var(--asap-border);
    border-radius: 6px;
    background: #f3f4f6;
    color: #374151;
    cursor: pointer;
    font: inherit;
    font-size: 0.72rem;
    line-height: 1.25;
    text-align: center;
    min-height: 5.4rem;
}
.etimad-tab:hover { background: #e8eaed; text-decoration: none; }
.etimad-tab.is-active {
    background: var(--asap-blue);
    border-color: var(--asap-blue);
    color: #fff;
}
.etimad-tab-icon { width: 22px; height: 22px; flex-shrink: 0; }
.etimad-card {
    background: var(--asap-surface);
    border: 1px solid var(--asap-border);
    border-radius: 8px;
    box-shadow: var(--asap-shadow);
    padding: 1rem 1.1rem 1.15rem;
}
.etimad-h {
    margin: 0 0 0.75rem;
    color: var(--asap-navy);
    font-size: 1.05rem;
    font-weight: 700;
}
.etimad-h + .etimad-h,
.etimad-table + .etimad-h,
.etimad-split + .etimad-h,
.etimad-overview + .etimad-h { margin-top: 1.25rem; }
.etimad-subh { margin: 0 0 0.6rem; font-size: 0.95rem; color: var(--asap-blue); }
.etimad-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1rem;
}
.etimad-kv {
    display: grid;
    grid-template-columns: minmax(9rem, 32%) 1fr;
    border: 1px solid #e5e7eb;
    border-bottom: none;
}
.etimad-col .etimad-kv:last-child,
.etimad-panel > .etimad-kv:last-of-type { border-bottom: 1px solid #e5e7eb; }
.etimad-k {
    background: var(--asap-blue-light);
    padding: 0.55rem 0.7rem;
    color: var(--asap-navy);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
}
.etimad-v {
    background: #fff;
    padding: 0.4rem 0.7rem;
    min-height: 2.4rem;
    display: flex;
    align-items: center;
}
.etimad-v .etimad-input,
.etimad-v textarea.etimad-input {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    padding: 0.2rem 0;
    min-height: 1.6rem;
}
.etimad-v .etimad-input:focus {
    border-color: var(--asap-blue);
    background: #fff;
}
.etimad-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.etimad-pill {
    background: var(--asap-blue);
    color: #fff;
    border-radius: 4px;
    padding: 0.2rem 0.55rem;
    font-size: 0.8rem;
    font-weight: 600;
}
.etimad-table thead th {
    background: var(--asap-navy);
    color: #fff;
    font-weight: 600;
}
.etimad-panel[hidden] { display: none !important; }
.etimad-save-bar { margin-top: 1rem; }
.etimad-save-bar.is-hidden { display: none; }
.etimad-attach-box {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.85rem;
}
.etimad-file-list { list-style: none; margin: 0; padding: 0; }
.etimad-file-list li { padding: 0.35rem 0; border-bottom: 1px solid #f3f4f6; }
.etimad-file-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem 0.7rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--asap-border-light);
}
.etimad-alias-form { display: flex; gap: 0.35rem; flex: 1 1 12rem; }
.etimad-alias-form .field-input { min-width: 8rem; }
.etimad-overview { margin-bottom: 0.35rem; }
.etimad-embed-boq .card { box-shadow: none; }
.etimad-boq-caption {
    border-bottom: 2px solid var(--asap-blue);
    padding-bottom: 0.35rem;
    margin: 0.35rem 0 0.75rem;
    font-weight: 600;
}
.etimad-upload { margin-top: 1rem; }
.etimad-local-files {
    margin: 0.25rem 0 1.35rem;
}
.etimad-local-files .etimad-subh { margin-top: 0.35rem; }
.etimad-local-files .etimad-upload { margin-top: 0.65rem; }
.etimad-boq-titles { margin-bottom: 0.85rem; }
.etimad-paste-hint {
    margin: 0.35rem 0 0.65rem;
    color: #5f6368;
    font-size: 0.85rem;
}
.etimad-paste-status {
    margin: 0 0 0.65rem;
    padding: 0.45rem 0.7rem;
    border-radius: 8px;
    background: #e8f0fe;
    color: var(--asap-navy);
    font-size: 0.88rem;
}
.etimad-paste-status.is-error { background: #fee2e2; color: #991b1b; }
.etimad-paste-status.is-ok { background: #e6f4ea; color: #137333; }
.etimad-input.is-ocr-filled,
select.etimad-input.is-ocr-filled {
    outline: 2px solid var(--asap-blue);
    background: #f8fbff;
}
@media (max-width: 900px) {
    .etimad-split { grid-template-columns: 1fr; }
}

.asap-dialog.asap-dialog-xl {
    max-width: min(880px, 96vw);
    width: 96vw;
    max-height: 90vh;
    overflow: auto;
}
.tree-ai-btn { flex-shrink: 0; white-space: nowrap; font-weight: 600; }
.ai-status { margin: 0 0 0.75rem; }
.ai-error { color: var(--asap-danger); margin: 0 0 0.75rem; }
.ai-contract, .ai-block {
    border: 1px solid var(--asap-border-light);
    border-radius: 6px;
    padding: 0.65rem 0.75rem;
    margin: 0 0 0.85rem;
    background: var(--asap-blue-light);
    font-size: 0.85rem;
}
.ai-block { background: var(--asap-surface, #fff); }
.ai-contract h3, .ai-block h3, .ai-q h3 {
    margin: 0 0 0.4rem;
    font-size: 0.85rem;
}
.ai-contract ul, .ai-block ul, .ai-preview { margin: 0; padding-inline-start: 1.1rem; }
.ai-q { margin: 0 0 0.85rem; }
.ai-q-item {
    border-bottom: 1px solid var(--asap-border-light);
    padding: 0.55rem 0;
}
.ai-q-item:last-child { border-bottom: 0; }
.ai-q-item .help-text { margin: 0.2rem 0 0.4rem; }
.ai-preview { list-style: none; padding: 0; }
.ai-preview ul { list-style: none; padding-inline-start: 1rem; margin: 0.15rem 0 0; }
.ai-preview li { margin: 0.15rem 0; }
.ai-node-type { color: var(--asap-text-muted); font-size: 0.75rem; margin-inline-start: 0.25rem; }
.ai-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    margin-inline-start: 0.25rem;
    background: var(--asap-blue-light);
    color: var(--asap-navy);
}
.ai-badge.tbd { background: #fef3c7; color: #92400e; }
.ai-cite { display: block; color: var(--asap-text-muted); font-size: 0.72rem; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.asap-dialog [hidden],
.ai-actions .btn[hidden] { display: none !important; }
