/* ==========================================================================
   Ahskar Valuation Suite — UI
   ========================================================================== */
:root {
    --brand: #0b3d6e;
    --brand-2: #155a9c;
    --brand-soft: #e8f0f9;
    --accent: #c8962e;
    --ink: #1b2430;
    --muted: #6b7686;
    --line: #e3e8ef;
    --bg: #f4f6fa;
    --card: #ffffff;
    --sidebar-w: 248px;
    --radius: 10px;
    --bs-font-sans-serif: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bs-body-font-size: .9rem;
    --bs-primary: #0b3d6e;
    --bs-primary-rgb: 11, 61, 110;
    --bs-link-color: #155a9c;
    --bs-link-color-rgb: 21, 90, 156;
}
body { background: var(--bg); color: var(--ink); font-feature-settings: "cv11", "ss01"; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-2); --bs-btn-hover-border-color: var(--brand-2); --bs-btn-active-bg: #082c50; }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: #b8cbe0; --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
.text-purple-emphasis { color: #5b2a86 !important; } .bg-purple-subtle { background: #f1e8fa !important; } .border-purple-subtle { border-color: #dcc8f0 !important; }
.form-control, .form-select { border-color: #d6dde7; font-size: .875rem; }
.form-control:focus, .form-select:focus { border-color: #7aa3cf; box-shadow: 0 0 0 .2rem rgba(21, 90, 156, .12); }
.form-label { font-weight: 500; font-size: .8rem; color: #435064; margin-bottom: .3rem; }
.table { --bs-table-color: var(--ink); font-size: .86rem; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f8fafc; border-bottom-color: var(--line); }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: linear-gradient(180deg, #0a2f55 0%, #0b3d6e 100%); color: #cdd8e6; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 1030; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem 1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.brand-text { font-weight: 600; line-height: 1.15; font-size: .95rem; }
.brand-text small { display: block; font-weight: 400; color: #9fb3cc; font-size: .72rem; letter-spacing: .03em; }
.side-nav { padding: .8rem .6rem; flex: 1; overflow-y: auto; }
.side-nav a { display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; color: #cdd8e6; text-decoration: none; border-radius: 8px; margin-bottom: 2px; font-size: .87rem; }
.side-nav a i { font-size: 1.05rem; opacity: .85; }
.side-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-nav a.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-label { text-transform: uppercase; font-size: .66rem; letter-spacing: .1em; color: #7f97b5; padding: 1rem .75rem .35rem; }
.side-foot { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .me { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-size: .84rem; line-height: 1.2; min-width: 0; }
.side-foot .me small { display: block; color: #9fb3cc; font-size: .72rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #2a5d92; display: grid; place-items: center; font-weight: 600; flex: none; }
.side-foot .logout { color: #9fb3cc; font-size: 1.15rem; }
.side-foot .logout:hover { color: #fff; }
.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; position: sticky; top: 0; z-index: 1020; }
.topbar-title { font-weight: 600; font-size: 1.05rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.content { padding: 1.5rem; }
.content.flush { padding: 0; }
.btn-icon { border: 0; background: transparent; font-size: 1.3rem; }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
    .main { margin-left: 0; }
    .content { padding: 1rem; }
}

/* ---------- cards / stats ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 600; padding: .85rem 1.1rem; }
.card-header .sub { font-weight: 400; color: var(--muted); font-size: .8rem; }
.stat { padding: 1.1rem 1.2rem; display: flex; gap: 1rem; align-items: center; }
.stat .ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem; flex: none; }
.stat .val { font-size: 1.55rem; font-weight: 700; line-height: 1; }
.stat .lbl { color: var(--muted); font-size: .78rem; margin-top: .3rem; }
.status-badge { font-weight: 500; font-size: .74rem; padding: .35em .6em; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.3rem; font-weight: 700; margin: 0; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty i { font-size: 2.5rem; display: block; margin-bottom: .5rem; color: #b6c2d1; }
.row-link { cursor: pointer; }
.row-link:hover td { background: #f7faff; }
.ref { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; font-weight: 600; color: var(--brand); }
.flash { border-radius: 10px; }
.filters .form-control, .filters .form-select { min-width: 140px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(circle at 20% 20%, #1d5f9e 0, #0b3d6e 45%, #072845 100%); color: #fff; padding: 3.5rem; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h1 { font-size: 2.2rem; font-weight: 700; max-width: 480px; line-height: 1.2; }
.login-art p { color: #bcd0e6; max-width: 460px; }
.login-art .feat { display: flex; gap: .75rem; margin-top: 1.1rem; color: #dbe7f4; font-size: .92rem; }
.login-art .feat i { color: var(--accent); font-size: 1.2rem; }
.login-form { display: grid; place-items: center; padding: 2rem; background: #fff; }
.login-form form { width: 100%; max-width: 380px; }
@media (max-width: 900px) { .login-wrap { grid-template-columns: 1fr; } .login-art { display: none; } }
.login-brand-sm { display: none; align-items: center; gap: .75rem; margin-bottom: 2rem; }
.login-brand-sm img { width: 48px; height: 48px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); padding: 3px; }
.login-brand-sm strong { display: block; font-size: 1.05rem; color: var(--brand); line-height: 1.2; }
.login-brand-sm small { color: var(--muted); font-size: .78rem; }
@media (max-width: 900px) { .login-brand-sm { display: flex; } }

/* ---------- editor ---------- */
.editor-head { background: #fff; border-bottom: 1px solid var(--line); padding: .9rem 1.5rem .1rem; }
.editor-head .meta { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; color: var(--muted); font-size: .8rem; margin: .35rem 0 .7rem; }
.editor-head .meta b { color: var(--ink); font-weight: 600; }
.editor-tabs { border-bottom: 0; gap: .25rem; }
.editor-tabs .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; padding: .6rem .9rem; border-radius: 0; }
.editor-tabs .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); background: transparent; }
.editor-tabs .nav-link .badge { font-weight: 500; }
.editor-body { display: grid; grid-template-columns: 210px minmax(0, 1fr) 300px; gap: 1.25rem; padding: 1.25rem 1.5rem; align-items: start; }
@media (max-width: 1399.98px) { .editor-body { grid-template-columns: minmax(0, 1fr) 290px; } .sec-nav { display: none; } }
@media (max-width: 991.98px) { .editor-body { grid-template-columns: 1fr; } }
.sec-nav { position: sticky; top: 76px; font-size: .82rem; }
.sec-nav a { display: flex; justify-content: space-between; align-items: baseline; gap: .4rem; padding: .38rem .7rem; color: var(--muted); text-decoration: none; border-left: 2px solid var(--line); }
.sec-nav a:hover { color: var(--ink); }
.sec-nav a.active { color: var(--brand); border-left-color: var(--brand); font-weight: 600; }
.sec-nav .fill { flex: none; font-size: .7rem; color: #9aa6b5; }
.summary-panel { position: sticky; top: 76px; }
.summary-panel .card-body { padding: 1rem 1.1rem; }
.sum-row { display: flex; justify-content: space-between; padding: .32rem 0; font-size: .84rem; border-bottom: 1px dashed #edf0f4; }
.sum-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 500; }
.sum-total { background: var(--brand); color: #fff; border-radius: 10px; padding: .9rem 1rem; margin: .8rem 0 .6rem; }
.sum-total .l { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #b9cde3; }
.sum-total .v { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sum-total .w { font-size: .74rem; color: #d4e2f1; margin-top: .2rem; line-height: 1.3; }
.save-state { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.save-state.dirty { color: #b26a00; }
.save-state.saving { color: var(--brand-2); }
.save-state.error { color: #c0392b; }

.fsec { margin-bottom: 1.25rem; scroll-margin-top: 80px; }
.fsec > .card-header { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 60px; z-index: 5; border-radius: var(--radius) var(--radius) 0 0; }
.frow { display: grid; grid-template-columns: 54px minmax(180px, 34%) minmax(0, 1fr); border-bottom: 1px solid #f0f2f6; align-items: start; }
.frow:last-child { border-bottom: 0; }
.frow .num { padding: .65rem .3rem .65rem .9rem; color: #8a96a6; font-size: .78rem; font-weight: 600; }
.frow .lab { padding: .62rem .8rem .62rem 0; font-size: .84rem; color: #3b4757; white-space: pre-line; line-height: 1.35; }
.frow .lab .tags { display: inline-flex; gap: .25rem; margin-left: .3rem; vertical-align: middle; }
.frow .inp { padding: .38rem .9rem .38rem 0; position: relative; }
.frow.heading { background: #f8fafc; }
.frow.heading .lab { font-weight: 600; color: var(--ink); }
.frow:focus-within { background: #fbfdff; }
.frow:focus-within .num { color: var(--brand); }
.tag { font-size: .62rem; padding: .1em .4em; border-radius: 4px; font-weight: 600; letter-spacing: .02em; }
.tag-ai { background: #efe7fb; color: #6a35b0; }
.tag-site { background: #e5f4ec; color: #1f7a4a; }
.tag-custom { background: #fff1d6; color: #9a6400; }
.frow { position: relative; }
.ins-row { position: absolute; left: 16px; bottom: -11px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid #9fbbdb; background: #fff; color: var(--brand); padding: 0; display: none; place-items: center; z-index: 6; box-shadow: 0 2px 6px rgba(16,24,40,.15); font-size: .95rem; line-height: 1; }
.frow:hover > .ins-row, .ins-row:focus { display: grid; }
.ins-row:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.frow.custom { background: #fffbf2; }
.frow.custom .num { padding: .42rem .3rem .42rem .6rem; }
.frow.custom .num input { padding: .25rem .3rem; font-size: .78rem; text-align: center; }
.frow.custom .lab { padding: .38rem .8rem .38rem 0; white-space: normal; display: flex; align-items: center; gap: .4rem; }
.frow.custom .lab .tag { flex: none; margin: 0 !important; }
.frow.custom.flash { animation: rowflash 1.2s ease-out; }
@keyframes rowflash { from { background: #ffe9b3; } to { background: #fffbf2; } }
.inp .form-control, .inp .form-select { border-color: transparent; background-color: #f6f8fb; }
.inp .form-control:hover, .inp .form-select:hover { border-color: #dfe5ee; }
.inp .form-control:focus, .inp .form-select:focus { background: #fff; border-color: #7aa3cf; }
.inp textarea.form-control { min-height: 38px; resize: vertical; field-sizing: content; }
.inp.ai-filled .form-control { background: #f6f0ff; }
.pick-btn { position: absolute; right: 1.25rem; top: .62rem; border: 0; background: transparent; color: #9aa6b5; padding: 0 .2rem; z-index: 3; }
.pick-btn:hover { color: var(--brand); }
.picker { position: absolute; right: .9rem; top: 2.4rem; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(16,24,40,.14); min-width: 260px; max-width: 440px; max-height: 280px; overflow: auto; padding: .3rem; }
.picker button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: .4rem .6rem; border-radius: 6px; font-size: .82rem; white-space: pre-line; }
.picker button:hover { background: var(--brand-soft); }
.picker .ph { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .3rem .6rem; }

.mini-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.mini-table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .3rem .4rem; text-align: left; }
.mini-table td { padding: .15rem .2rem; vertical-align: top; }
.mini-table td.dir { font-size: .8rem; color: #435064; font-weight: 500; padding-top: .5rem; width: 58px; }
.mini-table .form-control { font-size: .84rem; padding: .3rem .5rem; }

/* calc grid (spreadsheet-like) */
.grid-wrap { overflow-x: auto; }
.xgrid { width: 100%; border-collapse: collapse; font-size: .84rem; }
.xgrid th { background: #f3f6fa; color: #4a5768; font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; padding: .45rem .5rem; border: 1px solid #e3e8ef; white-space: nowrap; }
.xgrid td { border: 1px solid #e8ecf2; padding: 0; position: relative; }
.xgrid td.ro { background: #fafbfd; text-align: right; padding: .4rem .6rem; font-variant-numeric: tabular-nums; color: #2c3a4b; white-space: nowrap; }
.xgrid td.idx { width: 34px; text-align: center; color: #9aa6b5; font-size: .75rem; background: #fafbfd; }
.xgrid input { width: 100%; border: 0; padding: .42rem .55rem; background: transparent; font-size: .84rem; outline: none; }
.xgrid input.num { text-align: right; font-variant-numeric: tabular-nums; min-width: 96px; }
.xgrid select { min-width: 86px; font-size: .84rem; }
.xgrid td.ro { min-width: 104px; }
.editor-body.no-nav { grid-template-columns: minmax(0, 1fr) 300px; }
.editor-body.no-nav .sec-nav { display: none; }
@media (max-width: 991.98px) { .editor-body.no-nav { grid-template-columns: 1fr; } }
.xgrid input:focus { background: #fff; box-shadow: inset 0 0 0 2px #4d8ad0; }
.xgrid tfoot td { background: #f3f6fa; font-weight: 700; padding: .45rem .6rem; text-align: right; font-variant-numeric: tabular-nums; }
.xgrid .act { width: 34px; text-align: center; }
.xgrid .act button { border: 0; background: transparent; color: #c0c8d3; padding: .3rem; }
.xgrid tr:hover .act button { color: #d64545; }
.calc-card .card-header { position: static; }
.grid-help { font-size: .74rem; color: var(--muted); }
kbd { font-size: .68rem; background: #eef1f5; color: #384556; border: 1px solid #d9dfe7; box-shadow: none; padding: .1rem .3rem; }

/* documents & photos */
.dropzone { border: 2px dashed #c9d5e3; border-radius: 12px; padding: 1.4rem; text-align: center; color: var(--muted); background: #fafcff; cursor: pointer; transition: .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--brand-2); background: var(--brand-soft); color: var(--brand); }
.dropzone i { font-size: 1.8rem; display: block; margin-bottom: .3rem; }
.doc-item { display: flex; align-items: center; gap: .8rem; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; background: #fff; }
.doc-item .ico { width: 38px; height: 38px; border-radius: 8px; background: #fdecec; color: #c53030; display: grid; place-items: center; font-size: 1.2rem; flex: none; }
.doc-item .ico.img { background: #e6f2ff; color: #1d64b5; }
.doc-item .nm { font-weight: 500; font-size: .86rem; word-break: break-all; }
.doc-item .sm { color: var(--muted); font-size: .75rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .9rem; }
.photo-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; position: relative; }
.photo-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #eef1f5; cursor: grab; }
.photo-card .pb { padding: .5rem .6rem; }
.photo-card .pb input { font-size: .78rem; }
.photo-card .geo { font-size: .7rem; color: var(--muted); margin-top: .3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-card .tools { position: absolute; top: .4rem; right: .4rem; display: flex; gap: .25rem; }
.photo-card .tools button { background: rgba(255,255,255,.92); border: 0; border-radius: 6px; width: 28px; height: 28px; display: grid; place-items: center; font-size: .85rem; }
.photo-card.excluded img { opacity: .4; filter: grayscale(1); }
.photo-card.dragging { opacity: .5; outline: 2px dashed var(--brand-2); }
.photo-card .order { position: absolute; top: .4rem; left: .4rem; background: var(--brand); color: #fff; font-size: .7rem; font-weight: 600; border-radius: 5px; padding: .05rem .4rem; }

/* AI review */
.ai-review td { vertical-align: top; font-size: .82rem; }
.ai-review .cur { color: var(--muted); white-space: pre-line; max-width: 280px; }
.ai-review textarea { font-size: .82rem; }
.ai-review tr.same { opacity: .55; }
.ai-loader { text-align: center; padding: 2.5rem 1rem; }
.ai-loader .spinner-border { width: 3rem; height: 3rem; color: #6a35b0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; font-size: .83rem; }
.timeline li::before { content: ''; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-2); }
.timeline li::after { content: ''; position: absolute; left: 7.5px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .t { color: var(--muted); font-size: .74rem; }

/* template builder */
.tb-section { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 1rem; background: #fff; }
.tb-section > .head { display: flex; gap: .5rem; align-items: center; padding: .6rem .8rem; background: #f8fafc; border-bottom: 1px solid var(--line); border-radius: 10px 10px 0 0; }
.tb-field { display: grid; grid-template-columns: 60px minmax(160px, 1.6fr) 130px 115px minmax(120px, 1fr) 46px 46px 100px; gap: .4rem; align-items: start; padding: .45rem .8rem; border-bottom: 1px solid #f0f2f6; font-size: .82rem; }
.tb-field:last-child { border-bottom: 0; }
.tb-field .form-control, .tb-field .form-select { font-size: .8rem; padding: .28rem .45rem; }
.tb-field.hd { background: #fbfcfe; font-size: .68rem; text-transform: uppercase; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.tb-field .more { grid-column: 2 / -1; }
.tb-field .btn-group .btn { padding: .15rem .35rem; font-size: .75rem; }
.perm-group { border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; margin-bottom: 1rem; background: #fff; }
.perm-group h6 { font-weight: 600; margin-bottom: .7rem; }
.settings-nav .nav-link { color: var(--muted); border-radius: 8px; }
.settings-nav .nav-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.img-preview { max-height: 70px; max-width: 220px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* ==========================================================================
   Phones & small tablets
   ========================================================================== */
/* KPI tile: icon beside the figure (Bootstrap's .card is a column flexbox) */
.card.stat { flex-direction: row; }

@media (max-width: 767.98px) {
    /* top bar: [menu] title [bell] on the first row, page actions on a second row */
    .topbar { height: auto; min-height: 56px; flex-wrap: wrap; gap: .35rem .5rem; padding: .45rem .75rem; }
    .topbar-title { order: 1; font-size: 1rem; }
    .topbar > .dropdown { order: 2; }
    .topbar-actions { order: 3; flex: 1 0 100%; flex-wrap: wrap; justify-content: flex-end; gap: .4rem; }
    .topbar-actions:not(:has(*)) { display: none; }
    .topbar-actions { white-space: nowrap; align-items: center; }
    .topbar-actions .btn { padding: .32rem .7rem; font-size: .83rem; }
    .topbar-actions .save-state { order: -1; margin: 0 auto 0 0 !important; font-size: .72rem; }
    .card-header.d-flex { flex-wrap: wrap; gap: .5rem; }
    .topbar-actions .form-control, .topbar-actions .form-select { font-size: .83rem; }
    .topbar .dropdown-menu { max-width: calc(100vw - 1rem); }
    .content { padding: .75rem; }
    .page-head h1 { font-size: 1.1rem; }
    .card-header { padding: .7rem .9rem; }

    /* filter bars: full-width search, two controls per row */
    .filters { gap: .5rem !important; }
    .filters > .input-group, .filters > input[name=q] { max-width: none !important; flex: 1 1 100%; }
    .filters > .form-select, .filters > .form-control:not([name=q]) { flex: 1 1 calc(50% - .25rem); width: auto !important; min-width: 0; }
    .filters > .ms-auto { margin-left: 0 !important; flex: 1 1 100%; text-align: right; }

    /* settings: the section menu becomes a scrolling row of chips */
    .settings-nav { flex-direction: row !important; flex-wrap: nowrap; overflow-x: auto; position: static !important; gap: .35rem; padding-bottom: .2rem; scrollbar-width: none; }
    .settings-nav .nav-link { white-space: nowrap; border: 1px solid var(--line); background: #fff; padding: .4rem .75rem; font-size: .82rem; }

    /* valuation editor: label above a full-width input */
    .editor-head { padding: .7rem .9rem 0; }
    .editor-head .meta { gap: .2rem 1rem; }
    .editor-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .editor-tabs .nav-link { white-space: nowrap; padding: .55rem .7rem; }
    .editor-body { padding: .75rem; gap: .9rem; }
    .fsec { scroll-margin-top: 120px; }
    .fsec > .card-header, .summary-panel { position: static; }
    .frow { grid-template-columns: 40px minmax(0, 1fr); }
    .frow .num { padding: .6rem .2rem .15rem .75rem; }
    .frow .lab { padding: .6rem .75rem .25rem 0; }
    .frow .inp { grid-column: 1 / -1; padding: 0 .75rem .65rem; }
    .pick-btn { right: 1.1rem; }
    .picker { left: .75rem; right: .75rem; min-width: 0; max-width: none; }
    .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }

    /* template builder: the field grid scrolls sideways inside its card */
    .tb-section { overflow-x: auto; }
    .tb-section > .head { flex-wrap: wrap; }
    .tb-field { min-width: 820px; }
}
@media (max-width: 991.98px) {
    body.nav-open { overflow: hidden; }
    body.nav-open .main::after { content: ''; position: fixed; inset: 0; background: rgba(10, 25, 45, .45); z-index: 1025; }
}
/* touch screens have no hover: keep the "insert row here" button visible */
@media (hover: none) { .ins-row { display: grid; opacity: .75; } }

@media (max-width: 575.98px) {
    .card.stat { flex-direction: column; align-items: flex-start; gap: .55rem; padding: .85rem .9rem; }
    .stat .ico { width: 36px; height: 36px; border-radius: 10px; font-size: 1.05rem; }
    .stat .val { font-size: 1.2rem !important; }

    /* data tables become label / value cards (app.js copies the header text into data-label) */
    .table-stack > thead { display: none; }
    .table-stack, .table-stack > tbody, .table-stack > tfoot, .table-stack > tbody > tr, .table-stack > tfoot > tr { display: block; width: 100%; }
    .table-stack > tbody > tr, .table-stack > tfoot > tr { padding: .55rem .9rem; border-bottom: 1px solid var(--line); }
    /* flow-root + floated label: multi-line labels and values never overlap the next line */
    .table-stack > tbody > tr > *, .table-stack > tfoot > tr > * { display: flow-root; width: auto !important; max-width: none !important; padding: .2rem 0; border: 0; text-align: right !important; box-shadow: none; }
    .table-stack > tbody > tr > *::before, .table-stack > tfoot > tr > *::before { content: attr(data-label); float: left; width: 38%; margin-right: .6rem; padding-top: .12rem; text-align: left; color: var(--muted); font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; line-height: 1.3; white-space: normal; }
    .table-stack > tbody > tr > *:first-child, .table-stack .stack-full { text-align: left !important; }
    .table-stack > tbody > tr > *:first-child::before, .table-stack .stack-full::before, .table-stack [data-label=""]::before { content: none; }
    .table-stack > tbody > tr > *:empty { display: none; }
    .table-stack.table-hover > tbody > tr:hover { background: #f7faff; }
}
