body {
    background-color: #f8f9fa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

.navbar-brand strong {
    font-size: 1.15rem;
    color: #198754;
}

.drop-zone {
    border: 2px dashed #ccc;
    border-radius: 0.75rem;
    padding: 2.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: #198754;
    background-color: #f0fdf4;
}

.results-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #555;
    border-bottom-width: 2px;
}

.results-table td {
    padding: 0.85rem 0.75rem;
    border-bottom: 1px solid #eee;
}

.results-table tbody tr:last-child td {
    border-bottom: none;
}

.results-table tbody tr:hover {
    background-color: #f0fdf4;
}

.card-header {
    padding: 0.9rem 1.25rem;
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 0 0.375rem 0.375rem;
}

#loading-overlay > div {
    text-align: center;
}

.overall-estimate {
    background: linear-gradient(135deg, #198754 0%, #157347 100%);
    color: #fff;
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
}

.overall-estimate .label {
    font-weight: 600;
    font-size: 0.95rem;
}

.overall-estimate .notes {
    font-size: 0.8rem;
    opacity: 0.85;
    margin-top: 0.15rem;
}

.overall-estimate .price {
    font-size: 1.5rem;
    font-weight: 700;
    white-space: nowrap;
}

.overall-estimate .unit {
    font-size: 0.85rem;
    font-weight: 400;
    opacity: 0.85;
}

/* Breakdown mini-table inside the overall banner */
.overall-breakdown-table {
    border-top: 1px solid rgba(255,255,255,0.25);
    padding-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.overall-breakdown-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    opacity: 0.9;
}
.overall-breakdown-margin {
    border-top: 1px solid rgba(255,255,255,0.25);
    padding-top: 0.2rem;
    font-weight: 600;
    opacity: 1;
}
.overall-breakdown-offer {
    border-top: 1px solid rgba(255,255,255,0.35);
    padding-top: 0.2rem;
    font-weight: 700;
    font-size: 0.88rem;
    opacity: 1;
}
.overall-breakdown-label { opacity: 0.85; }
.overall-breakdown-value { font-variant-numeric: tabular-nums; }
.text-danger-soft { color: #ffaaaa; }

/* Breakdown sub-rows under each component */
.breakdown-sub-row td.breakdown-sub-cell {
    background: #f8f9ff;
    padding: 0.2rem 0.75rem 0.35rem 1.5rem;
    border-top: none;
}
.breakdown-sub-row .breakdown-line {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.78rem;
}
.breakdown-sub-row .breakdown-label {
    color: #6c757d;
}
.breakdown-sub-row .breakdown-sep {
    font-size: 0.75rem;
    color: #adb5bd;
    margin: 0 0.4rem;
}

.thumbnail-wrapper {
    display: inline-block;
}

.thumb-remove {
    padding: 0 0.25rem;
    line-height: 1;
    font-size: 0.7rem;
    border-radius: 50%;
    transform: translate(30%, -30%);
}

.price-edit-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* .item-edit-group removed: detail rows are labelled blocks now (.detail-block). */

.item-input {
    font-weight: 600;
}

/* Keep the commodity-name column readable instead of being crushed to
   near-zero width by the other fixed-width columns on narrow screens --
   .table-responsive handles horizontal scroll for the overflow. */
.results-table td:first-child,
.results-table th:first-child {
    min-width: 150px;
}

/* item-input / desc-input are auto-growing <textarea>s (see _autoGrowTextarea
   in index.html) so long commodity names/descriptions wrap onto multiple
   lines instead of being clipped the way a single-line <input> would. */
.item-input,
.desc-input {
    display: block;
    width: 100%;
    resize: none;
    overflow: hidden;
    overflow-wrap: break-word;
    line-height: 1.3;
    border-color: transparent;
    background: transparent;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
}

.item-input:hover,
.desc-input:hover {
    border-color: #dee2e6;
    background: #fff;
}

.item-input:focus,
.desc-input:focus {
    border-color: #198754;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.15);
}

.price-symbol {
    font-weight: 600;
    font-size: 0.9rem;
    color: #333;
}

.price-dash {
    font-weight: 600;
    margin: 0 2px;
    color: #333;
}

.price-input {
    width: 70px;
    padding: 0.2rem 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: right;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    background: transparent;
    transition: border-color 0.15s, background-color 0.15s;
    -moz-appearance: textfield;
}

.price-input::-webkit-inner-spin-button,
.price-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.price-input:hover {
    border-color: #dee2e6;
    background: #fff;
}

.price-input:focus {
    outline: none;
    border-color: #198754;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.15);
}

.price-input.edited {
    color: #0d6efd;
}

.item-input.edited,
.desc-input.edited {
    border-color: #0d6efd;
}

/* Per-item confidence */
.confidence-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.2rem;
}

.badge-confidence {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.15em 0.5em;
}

.confidence-note {
    font-size: 0.75rem;
    line-height: 1.2;
}

/* Source attribution */
.source-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.2rem;
    font-size: 0.72rem;
    line-height: 1.2;
    flex-wrap: wrap;
}

.source-row > i {
    font-size: 0.85rem;
    line-height: 1;
}

.source-name {
    font-weight: 600;
    color: #495057;
    word-break: break-all;
}

.source-note {
    color: #6c757d;
    font-style: italic;
}

.view-source-photo-btn {
    font-size: 0.72rem;
    margin-top: 0.2rem;
}

#source-photo-modal-body img {
    max-width: 100%;
    display: block;
}

#source-photo-modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

/* Weight percentage input */
.weight-pct-input {
    width: 58px;
    padding: 0.2rem 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: right;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    background: transparent;
    transition: border-color 0.15s, background-color 0.15s;
    -moz-appearance: textfield;
}

.weight-pct-input::-webkit-inner-spin-button,
.weight-pct-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.weight-pct-input:hover {
    border-color: #dee2e6;
    background: #fff;
}

.weight-pct-input:focus {
    outline: none;
    border-color: #198754;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.15);
}

.weight-pct-input.edited {
    color: #0d6efd;
}

/* Repricing row animation */
tr.repricing {
    opacity: 0.6;
    pointer-events: none;
}

tr.repricing td {
    background: #f0fdf4;
}

.reprice-row-btn {
    margin-right: 0.25rem;
}

/* Email body editor */
.email-preview-wrapper {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    background: #fff;
    overflow: hidden;
    min-height: 380px;
    position: relative;
}

.email-body-editor {
    padding: 1rem;
    min-height: 380px;
    max-height: 500px;
    overflow-y: auto;
    outline: none;
}

.email-body-editor:focus {
    box-shadow: inset 0 0 0 2px rgba(25, 135, 84, 0.2);
}

#email-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
}

/* Save to history */
#save-history-btn .bi-database-add,
#save-history-btn .bi-check-circle {
    margin-right: 0.25rem;
}

#save-history-status {
    min-height: 1.1rem;
}

#save-history-status code {
    background: #f1f5f9;
    color: #0f172a;
    padding: 0.05rem 0.35rem;
    border-radius: 0.25rem;
    font-size: 0.85em;
}

/* Summary table (Grade/Weight/%/$lb/$/Factor/Final) -- compact, copy-to-Excel */
.summary-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #555;
}

.summary-table td {
    padding: 0.45rem 0.6rem;
    font-size: 0.88rem;
}

.summary-table tfoot td {
    border-top: 2px solid #dee2e6;
}

.sm-grade {
    font-weight: 500;
}

.sm-final {
    color: #198754;
    font-variant-numeric: tabular-nums;
}

.factor-input {
    width: 64px;
    padding: 0.2rem 0.35rem;
    font-size: 0.85rem;
    text-align: center;
    border: 1px solid #dee2e6;
    border-radius: 0.3rem;
    -moz-appearance: textfield;
}

.factor-input::-webkit-inner-spin-button,
.factor-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.factor-input:focus {
    outline: none;
    border-color: #198754;
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.15);
}

/* Editable summary-table cells (weight %, $/lb, total weight) */
.sm-inline-input {
    width: 78px;
    padding: 0.2rem 0.35rem;
    font-size: 0.85rem;
    border: 1px solid #dee2e6;
    border-radius: 0.3rem;
    -moz-appearance: textfield;
}

.sm-inline-input::-webkit-inner-spin-button,
.sm-inline-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.sm-inline-input:focus {
    outline: none;
    border-color: #198754;
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.15);
}

.sm-grade-input {
    width: 100%;
    min-width: 130px;
    padding: 0.2rem 0.4rem;
    font-size: 0.88rem;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    background: transparent;
}

.sm-grade-input:hover {
    border-color: #dee2e6;
    background: #fff;
}

.sm-grade-input:focus {
    outline: none;
    border-color: #198754;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.15);
}

/* Dismantle / DPC card */
.dpc-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
    align-items: center;
    font-size: 0.9rem;
}

.dpc-label {
    color: #6c757d;
}

.dpc-val {
    font-variant-numeric: tabular-nums;
}

.dpc-table {
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.5);
}

.dpc-table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #888;
    font-weight: 600;
}

.dpc-table td {
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
    padding: 0.3rem 0.5rem;
}

.dpc-inline-input {
    display: inline-block;
    width: 90px;
    -moz-appearance: textfield;
}

.dpc-inline-input::-webkit-inner-spin-button,
.dpc-inline-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.dpc-charge-row {
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 0.5rem;
    font-size: 1rem;
}

/* Context tips panel */
.context-tips-panel {
    background: #f0fdf4;
    border: 1px solid #c3e6cb;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
}

.context-tips-panel ul {
    padding-left: 1.2rem;
}

.context-tips-panel li + li {
    margin-top: 0.25rem;
}

/* Unified Costs card */
#dpc-costs-table td, #dpc-costs-table th { font-size: 0.85rem; }
.move-line-btn { color: #6c757d; padding: 0 0.25rem; text-decoration: none; }
.move-line-btn:hover { color: #198754; }

/* ------------------------------------------------------------------ */
/* Detail rows as labelled blocks                                       */
/* Each component is ONE table row whose single cell holds a stacked    */
/* label/value grid, so long descriptions, source citations and         */
/* confidence notes get the full table width instead of being squeezed  */
/* into narrow columns. Keeping it to one <tr> matters: gatherResults   */
/* and friends iterate `#results-table tbody tr[data-cid]`.             */
/* ------------------------------------------------------------------ */
#results-table > tbody > tr[data-cid] > td.detail-cell {
    padding: 0;
    border-top: 2px solid #dee2e6;
}
#results-table > tbody > tr[data-cid]:first-child > td.detail-cell {
    border-top: 0;
}

.detail-block {
    display: flex;
    flex-direction: column;
}

.db-row {
    display: grid;
    grid-template-columns: 172px minmax(0, 1fr);
    align-items: start;
    border-top: 1px solid #f1f3f5;
}
.db-row:first-child {
    border-top: 0;
}
/* The first block carries the row actions in a third column. */
.db-row.db-head {
    grid-template-columns: 172px minmax(0, 1fr) auto;
}

.db-label {
    padding: 0.55rem 0.75rem;
    background: #f8f9fa;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6c757d;
    line-height: 1.3;
    align-self: stretch;
}

.db-value {
    padding: 0.5rem 0.75rem;
    min-width: 0;           /* lets long source paths wrap instead of stretching the grid */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
}
.db-value > textarea {
    flex: 1 1 100%;
}

.db-actions {
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: flex-start;
    gap: 0.25rem;
    white-space: nowrap;
}

.db-weight {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex: 0 0 auto;
}
.db-weight-unit,
.db-unit {
    font-size: 0.72rem;
    color: #6c757d;
    white-space: nowrap;
}

/* The confidence note sits beside its badge and wraps freely. */
.db-row .confidence-note {
    flex: 1 1 14rem;
    min-width: 0;
}
/* Source attribution already has its own rules; just let it take a full line. */
.db-value > .source-row {
    flex: 1 1 100%;
    margin-top: 0;
}

@media (max-width: 640px) {
    .db-row,
    .db-row.db-head {
        grid-template-columns: 1fr;
    }
    .db-label {
        padding-bottom: 0.15rem;
        background: transparent;
    }
    .db-row.db-head .db-actions {
        justify-content: flex-end;
    }
}
