:root {
    --bg: #f5f7fa;
    --card: #ffffff;
    --ink: #1f2933;
    --muted: #6b7280;
    --border: #e2e8f0;
    --accent: #1d4ed8;
    --accent-dark: #1e3a8a;
    --derived: #fff8e6;
    --derived-border: #f0d58a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.5rem;
    background: var(--accent-dark);
    color: #fff;
}

.brand { display: flex; align-items: baseline; gap: 0.75rem; }
.logo { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.5px; }
.tagline { font-size: 0.85rem; opacity: 0.8; }

.placeholder-badge {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #f59e0b;
    color: #1f2933;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 600;
}

.container { max-width: 980px; margin: 1.5rem auto; padding: 0 1.25rem; }

.card, .method, .report-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

h2 { margin-top: 0; font-size: 1.2rem; }
h3 { margin-top: 0; font-size: 1.05rem; color: var(--accent-dark); }
h4 { margin: 0 0 0.6rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }

.hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.note { color: var(--muted); font-size: 0.9rem; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.field-col { display: flex; flex-direction: column; gap: 0.6rem; }

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field-wide { max-width: 520px; }
.field-label { font-size: 0.82rem; color: var(--muted); }

input[type="number"], input[type="text"] {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

input.derived { background: var(--derived); border-color: var(--derived-border); }

.method-total {
    margin-top: 1rem;
    padding-top: 0.8rem;
    border-top: 1px dashed var(--border);
    font-size: 1rem;
}
.method-total strong { font-size: 1.15rem; color: var(--accent-dark); }

.actions { margin: 1.5rem 0; }

.btn-primary, .btn-secondary {
    border: none;
    border-radius: 8px;
    padding: 0.65rem 1.3rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: #e5e7eb; color: var(--ink); }

.report-header { display: flex; align-items: center; justify-content: space-between; }
.report-body { margin-top: 0.5rem; }
.report-body h1 { font-size: 1.4rem; }
.report-body pre { white-space: pre-wrap; background: #f8fafc; padding: 1rem; border-radius: 8px; }
.report-body blockquote {
    border-left: 3px solid #f59e0b;
    margin: 0.8rem 0;
    padding: 0.3rem 1rem;
    background: #fffbeb;
    color: #92400e;
}

/* --- Residential cost method ------------------------------------------- */
.residential-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.residential-head h2 { margin: 0; }

.pinned-legend {
    background: #dbeafe; color: #1e3a8a; padding: 0 0.35rem; border-radius: 4px;
    border: 1px solid #93c5fd; font-style: normal;
}

.res-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 0.5rem 0 1rem; }
.res-line { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.4rem; }
.res-line span { font-size: 0.85rem; color: var(--muted); }

.appr-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem 1rem; margin-bottom: 0.8rem; }
.appr { display: flex; flex-direction: column; gap: 0.2rem; }
.appr span { font-size: 0.78rem; color: var(--muted); }
.appr em { color: var(--accent-dark); font-style: normal; }
.appr select { padding: 0.35rem; border: 1px solid var(--border); border-radius: 6px; }

.res-inline { display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: center; margin-bottom: 1rem; font-size: 0.85rem; color: var(--muted); }
.res-inline span { display: inline-flex; align-items: center; gap: 0.4rem; }

.trace-wrap { overflow-x: auto; }
table.trace { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.trace th, table.trace td { border: 1px solid var(--border); padding: 0.3rem 0.4rem; text-align: right; }
table.trace thead th { background: #f1f5f9; color: var(--muted); font-weight: 600; text-align: right; position: sticky; top: 0; }
table.trace th.row-label { text-align: left; background: #f8fafc; color: var(--ink); white-space: nowrap; }

input.cell {
    width: 100%; min-width: 5.5rem; padding: 0.3rem 0.4rem; border: 1px solid var(--border);
    border-radius: 5px; font-size: 0.82rem; text-align: right; background: var(--derived);
}
input.cell.input { background: #fff; }
input.cell.factor { min-width: 4rem; }
input.cell.pinned { background: #dbeafe; border-color: #60a5fa; font-weight: 600; }
.res-inline input.cell, .res-line input.cell { width: 7rem; }

.synthese { margin-top: 0.5rem; }
.syn-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--border); }
.syn-row span { font-size: 0.88rem; }
.syn-row input.cell { width: 9rem; }
.syn-row.total span { font-weight: 600; }
.syn-row.final { border-bottom: none; padding-top: 0.6rem; }
.syn-row.final strong { font-size: 1.25rem; color: var(--accent-dark); }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.5rem; }

/* --- Tabs --------------------------------------------------------------- */
.tabbar {
    display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0 0 1rem;
    border-bottom: 2px solid var(--border);
}
.tab {
    border: 1px solid transparent; border-bottom: none; background: transparent;
    padding: 0.6rem 1rem; font-size: 0.92rem; font-weight: 600; cursor: pointer;
    color: var(--muted); border-radius: 8px 8px 0 0; margin-bottom: -2px;
}
.tab:hover { color: var(--accent-dark); }
.tab.active {
    color: var(--accent-dark); background: var(--card);
    border-color: var(--border); border-bottom: 2px solid var(--card);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* --- Comparison grid emphasis ------------------------------------------ */
table.trace tr.grid-emph td { background: #eef2ff; font-weight: 600; }
.pct-cell { color: var(--muted); font-size: 0.78rem; }

/* --- Income N/A --------------------------------------------------------- */
.na-banner {
    background: #fff7ed; border: 1px solid #fdba74; color: #9a3412;
    padding: 0.6rem 0.9rem; border-radius: 8px; font-size: 0.88rem;
}
.income-body.disabled { opacity: 0.45; pointer-events: none; }

/* --- Reconciliation ----------------------------------------------------- */
table.recon-table th, table.recon-table td { text-align: left; }
table.recon-table tr.retained { background: #ecfdf5; }
table.recon-table tr.na { opacity: 0.55; }
table.recon-table .retained-cell { text-align: center; color: #059669; font-weight: 700; }
.recon-table select { padding: 0.3rem; border: 1px solid var(--border); border-radius: 6px; }
.na-tag, .na-banner strong { font-weight: 700; }
.na-tag { color: var(--muted); }
.rationale { font-style: italic; color: var(--accent-dark); text-align: right; }

/* --- Photos ------------------------------------------------------------- */
.photo-form { border: 1px dashed var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1.2rem; }
.photo-form-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem 1rem;
    margin-bottom: 0.9rem;
}
.photo-form-grid .field.check { flex-direction: row; align-items: center; gap: 0.4rem; }
.photo-form-grid .field.check span { font-size: 0.85rem; color: var(--muted); }

.photo-gallery {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.photo-card {
    border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
    display: flex; flex-direction: column; background: #fff;
}
.photo-card img { width: 100%; height: 130px; object-fit: cover; background: #f1f5f9; }
.photo-meta { padding: 0.6rem 0.7rem; display: flex; flex-direction: column; gap: 0.3rem; }
.photo-meta strong { font-size: 0.88rem; }
.photo-role { font-size: 0.75rem; color: var(--muted); }
.photo-tags { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.photo-tags em {
    font-style: normal; font-size: 0.68rem; padding: 0.1rem 0.4rem; border-radius: 999px;
}
.tag-report { background: #dbeafe; color: #1e3a8a; }
.tag-applied { background: #dcfce7; color: #166534; }
.photo-actions { display: flex; gap: 0.4rem; margin-top: 0.2rem; }
.btn-secondary.small { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn-secondary.danger { background: #fee2e2; color: #991b1b; }

.photo-evidence { display: inline-flex; align-items: center; gap: 0.25rem; margin-top: 0.25rem; }
.photo-evidence img { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }
.photo-evidence em { font-style: normal; font-size: 0.68rem; color: #166534; }
.note.empty { color: var(--muted); }

@media (max-width: 680px) {
    .field-grid { grid-template-columns: 1fr; }
    .photo-form-grid { grid-template-columns: 1fr 1fr; }
}

/* --- Sales-comparison method (3C, from PR#5) -------------------------- */
tr.comp-dropped { opacity: 0.55; }
tr.comp-dropped th.row-label { font-weight: 400; }
tr.comp-retained th.row-label { color: var(--accent-dark); }
td.retained-flag { text-align: center; font-weight: 700; color: var(--accent); }
.res-line select { padding: 0.35rem; border: 1px solid var(--border); border-radius: 6px; width: 7rem; }
.syn-keys { font-size: 0.88rem; color: var(--accent-dark); font-weight: 600; }

/* --- Conciliation (3F, from PR#4) ------------------------------------- */
.conciliation table.trace td, .conciliation table.trace th { vertical-align: middle; }
.conciliation table.trace th.note-cell, .conciliation table.trace td.note-cell { text-align: left; white-space: normal; font-weight: 400; color: var(--muted); font-size: 0.78rem; max-width: 18rem; }
.conciliation select { padding: 0.3rem; border: 1px solid var(--border); border-radius: 5px; font-size: 0.82rem; }
.conciliation tr.selected-row th.row-label { border-left: 3px solid var(--accent); }
.conciliation tr.selected-row { background: #eff6ff; }
.conciliation tr.discarded td, .conciliation tr.discarded th.row-label { opacity: 0.5; text-decoration: line-through; }

.rationale {
    margin: 0.8rem 0; padding: 0.6rem 0.9rem; border-radius: 8px;
    background: #f1f5f9; border-left: 3px solid var(--accent); font-size: 0.9rem;
}
.rationale.warn { background: #fffbeb; border-left-color: #f59e0b; color: #92400e; }
