/* ============================================================
   Scoped Styles — Brickwork Estimator   (.bk- prefix)
   ============================================================ */

/* ------ Theme tokens (inherits site vars where possible) --- */
.bk-calc-wrapper {
    --bk-brand:        var(--color-brand, #f97316);
    --bk-brand-d:      #ea580c;
    --bk-bg:           var(--color-bg-main, #f8fafc);
    --bk-surface:      var(--color-bg-card, #ffffff);
    --bk-border:       var(--color-border, #e2e8f0);
    --bk-text:         var(--color-text-primary, #0f172a);
    --bk-muted:        var(--color-text-secondary, #64748b);
    --bk-radius:       10px;
    --bk-shadow:       0 1px 4px rgba(0,0,0,.07);
    --bk-success:      #16a34a;
    --bk-danger:       #dc2626;

    width: 100%;
    box-sizing: border-box;
    color: var(--bk-text);
    font-family: inherit;
}

.bk-calc-wrapper *,
.bk-calc-wrapper *::before,
.bk-calc-wrapper *::after { box-sizing: border-box; }

/* ---- Back button spacing ---- */
.bk-calc-wrapper .back-btn { margin-bottom: 16px; }

/* ======================================================
   MODE TABS
   ====================================================== */
.bk-tabs-nav {
    display: inline-flex;
    gap: 4px;
    background: var(--bk-bg);
    border: 1px solid var(--bk-border);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
}

.bk-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--bk-muted);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background .18s, color .18s, box-shadow .18s;
    white-space: nowrap;
}
.bk-tab-btn svg { width: 15px; height: 15px; }
.bk-tab-btn.active {
    background: var(--bk-surface);
    color: var(--bk-brand);
    box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

/* ======================================================
   TWO-PANEL LAYOUT  (uses site's .calc-layout)
   ====================================================== */
/* Override any conflicting width on calc-layout inside our wrapper */
.bk-calc-wrapper .calc-layout {
    width: 100%;
    min-width: 0;
}
.bk-calc-wrapper .calc-panel {
    min-width: 0;          /* allow shrinking */
    overflow: hidden;
}

/* ======================================================
   SECTION DIVIDER
   ====================================================== */
.bk-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--bk-muted);
    margin: 22px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--bk-border);
}

/* ======================================================
   FORM GROUPS & INPUTS
   ====================================================== */
.bk-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.bk-fg {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bk-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bk-text);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bk-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}

.bk-input {
    width: 100%;
    padding: 9px 40px 9px 10px;
    background: var(--bk-bg);
    border: 1px solid var(--bk-border);
    color: var(--bk-text);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 7px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
.bk-input:focus {
    border-color: var(--bk-brand);
    box-shadow: 0 0 0 3px rgba(249,115,22,.15);
}
.bk-input[type="number"] { padding-right: 42px; }
select.bk-input { padding-right: 28px; cursor: pointer; }

.bk-unit {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--bk-muted);
    pointer-events: none;
}

.bk-arrow {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px; height: 14px;
    pointer-events: none;
    stroke: var(--bk-muted);
    flex-shrink: 0;
}

/* ======================================================
   COLLAPSIBLE PANELS (Advanced options)
   ====================================================== */
.bk-card {
    border: 1px solid var(--bk-border);
    border-radius: var(--bk-radius);
    overflow: hidden;
    margin-bottom: 12px;
    box-shadow: var(--bk-shadow);
    background: var(--bk-surface);
}

.bk-card-head {
    width: 100%;
    padding: 13px 16px;
    background: var(--bk-bg);
    border: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--bk-text);
    transition: background .15s;
    text-align: left;
}
.bk-card-head:hover { background: var(--bk-border); }
.bk-card-head svg {
    width: 16px; height: 16px;
    stroke: var(--bk-muted);
    flex-shrink: 0;
    transition: transform .2s;
}
.bk-card.open .bk-card-head svg { transform: rotate(180deg); }

.bk-card-body {
    display: none;
    padding: 16px;
    border-top: 1px solid var(--bk-border);
}
.bk-card.open .bk-card-body { display: block; }

/* ======================================================
   TABLES — wall schedule, openings, materials takeoff, BOQ
   ====================================================== */
.bk-tbl-wrap {
    overflow-x: auto;
    border: 1px solid var(--bk-border);
    border-radius: 8px;
    margin-bottom: 12px;
    -webkit-overflow-scrolling: touch;
}

.bk-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}
.bk-tbl th, .bk-tbl td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--bk-border);
    text-align: left;
}
.bk-tbl th {
    background: var(--bk-bg);
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--bk-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}
.bk-tbl tbody tr:last-child td { border-bottom: none; }
.bk-tbl tbody tr:hover td { background: rgba(249,115,22,.04); }

/* Inline inputs inside table cells */
.bk-tbl input[type="text"],
.bk-tbl input[type="number"] {
    width: 100%;
    min-width: 70px;
    padding: 6px 8px;
    background: var(--bk-bg);
    border: 1px solid transparent;
    color: var(--bk-text);
    font-size: 0.82rem;
    border-radius: 5px;
    outline: none;
    transition: border-color .15s;
}
.bk-tbl input[type="text"]:focus,
.bk-tbl input[type="number"]:focus {
    border-color: var(--bk-brand);
    background: var(--bk-surface);
}

/* ======================================================
   BUTTONS
   ====================================================== */
.bk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 7px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, color .15s, box-shadow .15s;
    white-space: nowrap;
}
.bk-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.bk-btn-primary { background: var(--bk-brand); color: #fff; }
.bk-btn-primary:hover { background: var(--bk-brand-d); }

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

.bk-btn-ghost {
    background: transparent;
    border: 1px dashed var(--bk-brand);
    color: var(--bk-brand);
    width: 100%;
    margin-top: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
}
.bk-btn-ghost:hover { background: rgba(249,115,22,.06); }

.bk-btn-del {
    background: transparent;
    border: none;
    color: var(--bk-danger);
    padding: 4px 6px;
    border-radius: 5px;
    cursor: pointer;
}
.bk-btn-del:hover { background: rgba(220,38,38,.08); }
.bk-btn-del svg { width: 14px; height: 14px; }

/* Calc action bar */
.bk-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
    flex-wrap: wrap;
}
.bk-actions .bk-btn { flex: 1; min-width: 110px; }

/* ======================================================
   RESULTS PANEL
   ====================================================== */
.bk-res-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    margin-bottom: 18px;
    border-bottom: 2px solid var(--bk-border);
}
.bk-res-header h2 { margin: 0; font-size: 1.05rem; font-weight: 700; }

.bk-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: .08em;
    padding: 3px 9px;
    border-radius: 20px;
    background: rgba(249,115,22,.12);
    color: var(--bk-brand);
}

/* KPI cards grid */
.bk-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.bk-kpi {
    background: var(--bk-surface);
    border: 1px solid var(--bk-border);
    border-radius: var(--bk-radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--bk-shadow);
}
.bk-kpi.accent { border-left: 4px solid var(--bk-brand); }
.bk-kpi-label { font-size: 0.75rem; font-weight: 600; color: var(--bk-muted); }
.bk-kpi-val   { font-size: 1.45rem; font-weight: 700; line-height: 1.2; color: var(--bk-text); }
.bk-kpi-unit  { font-size: 0.72rem; color: var(--bk-muted); font-weight: 500; }
.bk-kpi.accent .bk-kpi-val { color: var(--bk-brand); }

/* Formula steps */
.bk-step {
    background: var(--bk-bg);
    border-left: 3px solid var(--bk-brand);
    padding: 10px 14px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 10px;
    font-size: 0.85rem;
}
.bk-step-title { font-weight: 700; margin-bottom: 3px; }
.bk-step-formula { font-family: monospace; color: var(--bk-brand-d); }
.bk-step-result  { font-size: 0.78rem; color: var(--bk-muted); margin-top: 3px; }

/* Export bar */
.bk-export {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--bk-border);
}

/* Empty state */
.bk-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--bk-muted);
}
.bk-empty svg { width: 48px; height: 48px; margin-bottom: 14px; stroke: var(--bk-border); }
.bk-empty p { font-size: 0.9rem; }

/* ======================================================
   ENGINEERING NOTE
   ====================================================== */
.engineering-note {
    font-size: 0.8rem;
    color: var(--bk-muted);
    background: rgba(249,115,22,.06);
    border-left: 3px solid var(--bk-brand);
    padding: 9px 13px;
    border-radius: 0 6px 6px 0;
    margin-bottom: 18px;
}

/* ======================================================
   RESPONSIVE  — mobile-first tweaks
   ====================================================== */
@media (max-width: 900px) {
    .bk-tabs-nav { width: 100%; }
    .bk-tab-btn  { flex: 1; justify-content: center; }

    .bk-kpis { grid-template-columns: repeat(2, 1fr); }

    /* Stack the two panels vertically on small screens */
    .bk-calc-wrapper .calc-layout {
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
    }
    .bk-calc-wrapper .calc-panel { width: 100% !important; }
}

@media (max-width: 560px) {
    .bk-row { grid-template-columns: 1fr; }
    .bk-kpis { grid-template-columns: 1fr 1fr; }
    .bk-actions { flex-direction: column; }

    /* Mobile-friendly table cards */
    .bk-tbl, .bk-tbl thead, .bk-tbl tbody,
    .bk-tbl th, .bk-tbl td, .bk-tbl tr { display: block; }
    .bk-tbl thead tr { position: absolute; top:-9999px; left:-9999px; }
    .bk-tbl tbody tr {
        border: 1px solid var(--bk-border);
        border-radius: 10px;
        margin-bottom: 12px;
        background: var(--bk-surface);
        overflow: hidden;
        white-space: normal;
    }
    .bk-tbl td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 14px;
        border-bottom: 1px solid var(--bk-border);
    }
    .bk-tbl td:last-child { border-bottom: none; }
    .bk-tbl td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--bk-muted);
        margin-bottom: 3px;
    }
    /* Highlight "Final to Order" rows on mobile */
    .bk-tbl td[data-label="✅ Final to Order"] {
        background: rgba(249,115,22,.06);
    }
    .bk-tbl td[data-label="✅ Final to Order"]::before {
        color: var(--bk-brand);
    }
}

/* ======================================================
   PRINT
   ====================================================== */
@media print {
    .app-header, .side-nav, .app-footer,
    .back-btn, .bk-tabs-nav, .bk-actions, .bk-export,
    .bk-card-head svg, .bk-btn-ghost, .bk-btn-del,
    #seo-content, #seo-article { display: none !important; }

    body, html { background: #fff !important; color: #000 !important; }

    .bk-calc-wrapper .calc-layout { display: block !important; }
    .bk-calc-wrapper .calc-panel  { width: 100% !important; box-shadow: none !important; }

    .bk-card         { page-break-inside: avoid; border: none; box-shadow: none; }
    .bk-card-body    { display: block !important; border-top: none; }
    .bk-card-head    { font-size: 1rem; font-weight: 700; padding: 6px 0; background: transparent; }

    .bk-kpis { grid-template-columns: repeat(3, 1fr); }
    .bk-kpi  { border: 1px solid #000; box-shadow: none; }

    .bk-tbl th, .bk-tbl td { border: 1px solid #999; white-space: normal; }
}
