/*
 * MIEDECO-DTM interface styles. Bootstrap 5.3 provides the grid, forms and modal mechanics; this file sets the look and the shared components.
 * Order: tokens, base, shell, components, tables, forms, overlays, utilities, breakpoints, print.
 * Breakpoints used everywhere: 1200 (wide), 992 (drawer navigation), 768 (stacked tables and forms), 576 (phones).
 */

/* ---------------------------------------------------------------- tokens */
:root {
  --dtm-brand: #1b6a46;
  --dtm-brand-600: #155538;
  --dtm-brand-50: #e9f2ed;
  --dtm-accent: #b9801a;
  --dtm-side: #14231b;
  --dtm-side-text: #c6d6cc;
  --dtm-side-active: #21402f;
  --dtm-bg: #f4f6f4;
  --dtm-card: #ffffff;
  --dtm-line: #dde4df;
  --dtm-muted: #5b6862;
  --dtm-ok: #17743f;
  --dtm-warn: #9a6200;
  --dtm-bad: #b02a2a;
  --dtm-info: #1f5fa3;
  --dtm-radius: 8px;
  --dtm-radius-sm: 6px;
  --dtm-shadow: 0 1px 2px rgba(20, 35, 27, .06);
  --dtm-focus: 0 0 0 .2rem rgba(27, 106, 70, .28);
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
  --touch: 44px;
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-primary: #1b6a46;
  --bs-primary-rgb: 27, 106, 70;
  --bs-link-color: #155538;
  --bs-link-hover-color: #0e3d27;
  --bs-secondary-color: #5b6862;
  --bs-secondary-color-rgb: 91, 104, 98;
  --bs-border-radius: var(--dtm-radius);
}
[data-bs-theme="dark"] {
  --dtm-brand: #4cc38a;
  --dtm-brand-600: #3aa876;
  --dtm-brand-50: #1a2b22;
  --dtm-side: #0c1510;
  --dtm-side-text: #aec4b8;
  --dtm-side-active: #18322382;
  --dtm-bg: #0e1612;
  --dtm-card: #15201a;
  --dtm-line: #26342b;
  --dtm-muted: #93a69b;
  --dtm-ok: #52c78f;
  --dtm-warn: #e2ac52;
  --dtm-bad: #ee8080;
  --dtm-info: #82b8ee;
  --dtm-shadow: none;
  --dtm-focus: 0 0 0 .2rem rgba(76, 195, 138, .35);
  --bs-body-bg: #0e1612;
  --bs-body-color: #dde8e1;
  --bs-primary: #4cc38a;
  --bs-primary-rgb: 76, 195, 138;
  --bs-link-color: #6fd6a2;
  --bs-link-hover-color: #9be6bf;
  --bs-border-color: #26342b;
  --bs-secondary-bg: #1b2a21;
  --bs-tertiary-bg: #121c16;
  --bs-secondary-color: #93a69b;
  --bs-secondary-color-rgb: 147, 166, 155;
}

/* ---------------------------------------------------------------- base */
html, body { background: var(--dtm-bg); }
body { font-size: .9rem; font-variant-numeric: tabular-nums; overflow-wrap: break-word; }
body.side-open { overflow: hidden; }
a { text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--dtm-brand); outline-offset: 2px; }
.form-control:focus, .form-select:focus, .form-check-input:focus, .btn:focus-visible { border-color: var(--dtm-brand); box-shadow: var(--dtm-focus); outline: 0; }
.skip-link { position: fixed; left: .5rem; top: -4rem; z-index: 3000; background: var(--dtm-card); color: var(--dtm-brand); padding: .5rem .9rem; border: 2px solid var(--dtm-brand); border-radius: var(--dtm-radius-sm); }
.skip-link:focus { top: .5rem; }
.ic { width: 1.1em; height: 1.1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.17em; flex: none; }
.ic-lg { width: 1.35rem; height: 1.35rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }

/* ---------------------------------------------------------------- buttons */
.btn { --bs-btn-border-radius: var(--dtm-radius-sm); --bs-btn-font-weight: 500; }
.btn-primary { --bs-btn-bg: var(--dtm-brand); --bs-btn-border-color: var(--dtm-brand); --bs-btn-hover-bg: var(--dtm-brand-600); --bs-btn-hover-border-color: var(--dtm-brand-600); --bs-btn-active-bg: var(--dtm-brand-600); --bs-btn-active-border-color: var(--dtm-brand-600); --bs-btn-disabled-bg: var(--dtm-brand); --bs-btn-disabled-border-color: var(--dtm-brand); --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff; --bs-btn-disabled-color: #fff; }
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #06150d; --bs-btn-hover-color: #06150d; --bs-btn-active-color: #06150d; --bs-btn-disabled-color: #06150d; }
.btn-outline-primary { --bs-btn-color: var(--dtm-brand); --bs-btn-border-color: var(--dtm-brand); --bs-btn-hover-bg: var(--dtm-brand); --bs-btn-hover-border-color: var(--dtm-brand); --bs-btn-active-bg: var(--dtm-brand); --bs-btn-active-border-color: var(--dtm-brand); }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-hover-color: #06150d; --bs-btn-active-color: #06150d; }
.btn-outline-secondary { --bs-btn-color: #424d46; --bs-btn-border-color: #8a948e; --bs-btn-hover-bg: var(--dtm-brand-50); --bs-btn-hover-color: #1f2a24; --bs-btn-hover-border-color: #6f7a73; --bs-btn-active-bg: var(--dtm-brand-50); --bs-btn-active-color: #1f2a24; --bs-btn-active-border-color: #6f7a73; }
[data-bs-theme="dark"] .btn-outline-secondary { --bs-btn-color: #cfdcd4; --bs-btn-border-color: #5c6d63; --bs-btn-hover-bg: #223329; --bs-btn-hover-color: #ffffff; --bs-btn-hover-border-color: #7d9185; --bs-btn-active-bg: #223329; --bs-btn-active-color: #ffffff; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: var(--dtm-radius-sm); border: 1px solid transparent; background: transparent; color: inherit; position: relative; flex: none; }
.icon-btn:hover { background: var(--dtm-brand-50); }
.icon-btn .dot { position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; border-radius: 9px; background: var(--dtm-bad); color: #fff; font-size: .65rem; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }

/* ---------------------------------------------------------------- shell */
/* theme-init.js sets .pre-collapsed before first paint so a remembered collapsed sidebar does not flash open */
@media (min-width: 992px) { html.pre-collapsed .sidebar { width: var(--sidebar-w-collapsed); } html.pre-collapsed .main { margin-left: var(--sidebar-w-collapsed); } }
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--dtm-side); color: var(--dtm-side-text); position: fixed; inset: 0 auto 0 0; z-index: 1030; display: flex; flex-direction: column; transition: width .16s ease; overflow: hidden; }
.brand { height: var(--topbar-h); display: flex; align-items: center; gap: .65rem; padding: 0 .9rem; color: #fff; border-bottom: 1px solid rgba(255, 255, 255, .08); flex: none; }
.brand-link { display: flex; align-items: center; gap: .65rem; color: #fff; text-decoration: none; min-width: 0; flex: 1; height: 100%; }
.brand-link:hover { color: #fff; }
.brand .logo { width: 32px; height: 32px; border-radius: var(--dtm-radius-sm); background: var(--dtm-accent); color: #1a1202; display: grid; place-items: center; font-weight: 800; flex: none; overflow: hidden; }
.brand .logo img { width: 100%; height: 100%; object-fit: cover; }
.brand .name { line-height: 1.1; font-weight: 650; white-space: nowrap; min-width: 0; }
.brand .name small { display: block; font-weight: 400; opacity: .7; font-size: .72rem; overflow: hidden; text-overflow: ellipsis; }
.side-close { margin-left: auto; color: #fff; display: none; }
.side-close:hover { background: rgba(255, 255, 255, .1); }
.sidebar nav { flex: 1; overflow-y: auto; padding: .5rem .5rem 1rem; overscroll-behavior: contain; }
.nav-group { margin-top: .35rem; }
.sidebar .grp { display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: 0; color: inherit; opacity: .6; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; padding: .6rem .65rem .3rem; text-align: left; white-space: nowrap; }
.sidebar .grp:hover { opacity: .95; }
.sidebar .grp .ic { width: .85rem; height: .85rem; transition: transform .15s; }
.nav-group.is-closed .grp .ic { transform: rotate(-90deg); }
.nav-group.is-closed .grp-items { display: none; }
.sidebar .nav-link { display: flex; align-items: center; gap: .7rem; color: var(--dtm-side-text); padding: .5rem .65rem; min-height: 38px; border-radius: var(--dtm-radius-sm); white-space: nowrap; position: relative; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar .nav-link.active { background: var(--dtm-side-active); color: #fff; font-weight: 600; }
.sidebar .nav-link.active::before { content: ""; position: absolute; left: -.5rem; top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: var(--dtm-accent); }
.sidebar .nav-link .badge { margin-left: auto; }
.side-foot { padding: .6rem .9rem; border-top: 1px solid rgba(255, 255, 255, .08); flex: none; font-size: .78rem; opacity: .75; white-space: nowrap; }
.side-backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 1025; }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; transition: margin-left .16s ease; display: flex; flex-direction: column; }
body.side-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.side-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
body.side-collapsed .brand .name, body.side-collapsed .grp, body.side-collapsed .nav-link .lbl, body.side-collapsed .nav-link .badge, body.side-collapsed .side-foot .lbl { display: none; }
body.side-collapsed .nav-group.is-closed .grp-items { display: block; }
body.side-collapsed .brand, body.side-collapsed .sidebar .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
body.side-collapsed .nav-group { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid rgba(255, 255, 255, .08); }
body.side-collapsed .nav-group:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: .6rem; padding: 0 1.25rem; background: var(--dtm-card); border-bottom: 1px solid var(--dtm-line); position: sticky; top: 0; z-index: 1020; }
.topbar-title { margin: 0; font-size: 1rem; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: .5rem; border: 0; background: none; padding: .15rem .35rem; border-radius: var(--dtm-radius-sm); color: inherit; }
.user-chip:hover { background: var(--dtm-brand-50); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--dtm-brand); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
[data-bs-theme="dark"] .avatar { color: #06150d; }
.sync-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .75rem; color: var(--dtm-muted); padding: .2rem .6rem; border: 1px solid var(--dtm-line); border-radius: 999px; background: var(--dtm-card); white-space: nowrap; }
.sync-pill .led { width: 8px; height: 8px; border-radius: 50%; background: var(--dtm-ok); }
.sync-pill.off .led { background: var(--dtm-bad); }
.sync-pill.paused .led { background: var(--dtm-warn); }
.sync-pill.busy .led { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.notif-menu { width: min(92vw, 380px); }
.notif-list { max-height: 60vh; overflow: auto; }
.content { padding: 1.25rem; max-width: 1560px; width: 100%; margin: 0 auto; flex: 1; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: .25rem; font-size: .78rem; color: var(--dtm-muted); margin-bottom: .1rem; }
.crumbs span + span::before { content: "/"; margin-right: .25rem; opacity: .6; }
.page-title { font-size: 1.35rem; font-weight: 650; margin: 0; line-height: 1.25; overflow-wrap: anywhere; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; align-items: center; }
.page-head .page-actions { margin-bottom: 0; }
.page-actions .spacer { flex: 1; }
.loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--dtm-accent); z-index: 2000; opacity: 0; transition: width .25s ease, opacity .3s; }
.loading-bar.on { opacity: 1; width: 75%; transition: width 8s cubic-bezier(.1, .7, .2, 1), opacity .3s; }
.bottom-nav { display: none; }
.pad-bottom { padding-bottom: 1rem; }

/* ---------------------------------------------------------------- cards and figures */
.card { background: var(--dtm-card); border: 1px solid var(--dtm-line); border-radius: var(--dtm-radius); box-shadow: var(--dtm-shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--dtm-line); font-weight: 600; padding: .7rem 1rem; display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .6rem; }
.card-header .sub { font-weight: 400; color: var(--dtm-muted); font-size: .8rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; }
.kpi { padding: .85rem 1rem; height: 100%; min-width: 0; }
.kpi .lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dtm-muted); font-weight: 600; display: flex; align-items: center; gap: .35rem; }
.kpi .val { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; margin-top: .15rem; overflow-wrap: anywhere; }
.kpi .hint { font-size: .76rem; color: var(--dtm-muted); margin-top: .1rem; }
.kpi.warn .val { color: var(--dtm-warn); }
.kpi.bad .val { color: var(--dtm-bad); }
.bal-row { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-bottom: 1px dashed var(--dtm-line); }
.bal-row:last-child { border-bottom: 0; }
.bal-group-total { font-weight: 700; border-top: 1px solid var(--dtm-line); margin-top: .25rem; padding-top: .5rem; display: flex; justify-content: space-between; }
.kv { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr; gap: .35rem .9rem; margin: 0; }
.kv dt { color: var(--dtm-muted); font-weight: 500; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--dtm-line); border-radius: var(--dtm-radius); background: var(--dtm-card); overflow: hidden; }
.figures > div { padding: .65rem .9rem; min-width: 0; }
.figures > div + div { border-left: 1px solid var(--dtm-line); }
.figures .h { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dtm-muted); font-weight: 650; }
.figures .v { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.chart-box { position: relative; height: 240px; min-width: 0; }

/* status chips: colour plus a text label and a leading mark, so colour is never the only signal */
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-size: .73rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; line-height: 1.35; }
.chip::before { font-weight: 800; font-size: .8em; }
.chip.neutral { background: var(--dtm-brand-50); color: var(--dtm-brand); }
.chip.t-ok { background: #e0f2e8; color: #115c33; border-color: #bfe0cd; } .chip.t-ok::before { content: "\2713"; }
.chip.t-warn { background: #fbefd2; color: #7a4d00; border-color: #efd9a3; } .chip.t-warn::before { content: "!"; }
.chip.t-bad { background: #f9dede; color: #8c2020; border-color: #eab6b6; } .chip.t-bad::before { content: "\00d7"; }
.chip.t-info { background: #dcebf8; color: #174c82; border-color: #b7d3ee; } .chip.t-info::before { content: "i"; font-style: italic; }
.chip.t-mute { background: #ebeef0; color: #46515a; border-color: #d5dadd; } .chip.t-mute::before { content: "\2013"; }
.chip.t-pur { background: #ece4f7; color: #4b2f82; border-color: #d4c6ea; } .chip.t-pur::before { content: "\2022"; }
[data-bs-theme="dark"] .chip.t-ok { background: #153a28; color: #8ee0b3; border-color: #1f5238; }
[data-bs-theme="dark"] .chip.t-warn { background: #3d2f10; color: #f1c777; border-color: #574317; }
[data-bs-theme="dark"] .chip.t-bad { background: #411b1b; color: #f5a3a3; border-color: #5e2828; }
[data-bs-theme="dark"] .chip.t-info { background: #15304d; color: #9ccaf5; border-color: #204468; }
[data-bs-theme="dark"] .chip.t-mute { background: #263029; color: #b6c4bc; border-color: #34423a; }
[data-bs-theme="dark"] .chip.t-pur { background: #2c2142; color: #cdb9f0; border-color: #41325f; }
.cmp { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--dtm-line); border-radius: var(--dtm-radius); overflow: hidden; background: var(--dtm-card); }
.cmp > div { padding: .65rem .85rem; min-width: 0; }
.cmp > div + div { border-left: 1px solid var(--dtm-line); }
.cmp .h { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dtm-muted); font-weight: 700; margin-bottom: .2rem; }
.cmp .diff { background: rgba(214, 140, 0, .16); border-radius: 4px; padding: 0 .25rem; font-weight: 600; }
.sel-bar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .6rem 1rem; background: var(--dtm-card); border-top: 2px solid var(--dtm-brand); }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { border-left: 2px solid var(--dtm-line); padding: 0 0 .7rem .8rem; position: relative; }
.tl li::before { content: ""; position: absolute; left: -5px; top: .35rem; width: 8px; height: 8px; border-radius: 50%; background: var(--dtm-brand); }
.timeline { list-style: none; margin: 0 0 0 .35rem; padding: 0; border-left: 2px solid var(--dtm-line); }
.timeline li { position: relative; padding: 0 0 .8rem 1rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--dtm-brand); }
.row-flash { animation: rowflash 1.6s ease-out; }
@keyframes rowflash { from { background: rgba(27, 106, 70, .22); } to { background: transparent; } }
.dupbox { border: 1px solid #d4a017; background: rgba(212, 160, 23, .1); border-radius: var(--dtm-radius); padding: .8rem 1rem; }
.dupbox.hard { border-color: #b8372a; background: rgba(184, 55, 42, .08); }
.calc-box { background: var(--dtm-brand-50); border: 1px solid var(--dtm-line); border-radius: var(--dtm-radius); padding: .75rem .9rem; }
.calc-box .r { display: flex; justify-content: space-between; gap: .75rem; padding: .12rem 0; }
.calc-box .r.total { font-weight: 700; border-top: 1px solid var(--dtm-line); margin-top: .3rem; padding-top: .4rem; font-size: 1.05rem; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--dtm-line); border-radius: var(--dtm-radius-sm); overflow: hidden; background: var(--dtm-card); }
.seg button { border: 0; background: transparent; padding: .4rem .8rem; font-size: .85rem; color: var(--dtm-muted); font-weight: 600; min-height: 36px; }
.seg button.active { background: var(--dtm-brand); color: #fff; }
[data-bs-theme="dark"] .seg button.active { color: #06150d; }
.alert-stack { display: grid; gap: .5rem; }
.alert-line { display: flex; gap: .6rem; align-items: flex-start; padding: .55rem .8rem; border: 1px solid var(--dtm-line); border-left-width: 3px; border-radius: var(--dtm-radius-sm); background: var(--dtm-card); font-size: .86rem; }
.alert-line.bad { border-left-color: var(--dtm-bad); }
.alert-line.warn { border-left-color: var(--dtm-warn); }
.alert-line.info { border-left-color: var(--dtm-info); }
.empty { text-align: center; padding: 2.25rem 1rem; color: var(--dtm-muted); }
.empty .ic { width: 2rem; height: 2rem; opacity: .5; display: block; margin: 0 auto .5rem; }
.skeleton { background: linear-gradient(90deg, var(--dtm-line) 25%, transparent 50%, var(--dtm-line) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--dtm-radius-sm); min-height: 1em; }
@keyframes shimmer { to { background-position: -200% 0; } }
.report-list .list-group-item { border-color: var(--dtm-line); background: transparent; }
.report-list .list-group-item.active { background: var(--dtm-brand-50); color: var(--dtm-brand); border-left: 3px solid var(--dtm-brand); font-weight: 650; }
.report-list .grp { padding: .7rem .25rem .2rem; color: var(--dtm-muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 650; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; max-height: 68vh; border-radius: 0 0 var(--dtm-radius) var(--dtm-radius); -webkit-overflow-scrolling: touch; }
.table { --bs-table-bg: transparent; margin: 0; }
.table thead th { position: sticky; top: 0; z-index: 2; background: var(--dtm-card); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--dtm-muted); font-weight: 650; border-bottom: 1px solid var(--dtm-line); white-space: nowrap; }
.table td { vertical-align: middle; border-color: var(--dtm-line); }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover > *, .table tbody tr.clickable:focus-visible > * { background: var(--dtm-brand-50); }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--dtm-line); background: var(--dtm-card); position: sticky; bottom: 0; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.money.neg, .text-neg { color: var(--dtm-bad); }
.cell-wrap { max-width: 22rem; overflow-wrap: anywhere; }
.cell-clip { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-grid th, .perm-grid td { text-align: center; }
.perm-grid td:first-child, .perm-grid th:first-child { text-align: left; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; padding: .8rem 1rem; border-bottom: 1px solid var(--dtm-line); }
.toolbar > div { min-width: 0; }
.toolbar .form-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--dtm-muted); margin-bottom: .15rem; font-weight: 600; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; border-top: 1px solid var(--dtm-line); font-size: .82rem; color: var(--dtm-muted); gap: .5rem; flex-wrap: wrap; }

/* ---------------------------------------------------------------- forms */
.form-label { font-weight: 600; font-size: .82rem; margin-bottom: .2rem; }
.form-label .req { color: var(--dtm-bad); }
.form-control, .form-select { border-radius: var(--dtm-radius-sm); }
.form-text { font-size: .76rem; }
.input-money { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem 1rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }

/* ---------------------------------------------------------------- overlays: modals, dropdowns, toasts */
.modal-content { border-radius: var(--dtm-radius); border: 1px solid var(--dtm-line); background: var(--dtm-card); }
.modal-dialog-scrollable .modal-content { max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); }
.modal-body { overscroll-behavior: contain; min-width: 0; }
.modal-header, .modal-footer { border-color: var(--dtm-line); }
.modal-title { overflow-wrap: anywhere; }
.dropdown-menu { border-color: var(--dtm-line); max-width: calc(100vw - 1rem); }
.toast-container { z-index: 3000; max-width: 100vw; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: var(--dtm-bg); }
.login-card { width: 100%; max-width: 410px; padding: 2rem; }

/* ---------------------------------------------------------------- utilities */
.text-wrap-any { overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.hide-sm { display: inherit; }

/* ---------------------------------------------------------------- breakpoints */
@media (max-width: 1199.98px) {
  .content { padding: 1rem; }
  .sync-pill .txt { display: none; }
}

/* tablet and phone: the sidebar becomes a drawer */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); width: min(86vw, 300px); transition: transform .2s ease; box-shadow: 0 0 36px rgba(0, 0, 0, .4); visibility: hidden; }
  body.side-open .sidebar { transform: none; visibility: visible; }
  body.side-open .side-backdrop { display: block; }
  .side-close { display: inline-grid; }
  .main, body.side-collapsed .main { margin-left: 0; }
  body.side-collapsed .sidebar { width: min(86vw, 300px); }
  body.side-collapsed .brand .name, body.side-collapsed .grp, body.side-collapsed .nav-link .lbl, body.side-collapsed .nav-link .badge, body.side-collapsed .side-foot .lbl { display: revert; }
  body.side-collapsed .sidebar .grp { display: flex; }
  body.side-collapsed .brand, body.side-collapsed .sidebar .nav-link { justify-content: flex-start; padding-left: .65rem; padding-right: .65rem; }
  body.side-collapsed .brand { padding-left: .9rem; }
  body.side-collapsed .nav-group { margin-top: .35rem; padding-top: 0; border-top: 0; }
  body.side-collapsed .nav-group.is-closed .grp-items { display: none; }
  .topbar { padding: 0 .75rem; }
  .content { padding: .85rem .85rem calc(4.9rem + env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040; background: var(--dtm-card); border-top: 1px solid var(--dtm-line); padding: .15rem .25rem calc(.15rem + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { flex: 1; min-width: 0; min-height: var(--touch); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; padding: .3rem 0; font-size: .68rem; color: var(--dtm-muted); text-decoration: none; background: none; border: 0; border-radius: var(--dtm-radius-sm); }
  .bottom-nav .active { color: var(--dtm-brand); font-weight: 700; }
  .bottom-nav .ic { width: 1.3rem; height: 1.3rem; }
  .kpi .val { font-size: 1.25rem; }
  .hide-sm { display: none; }
  .toolbar > div { flex: 1 1 140px; }
  .sel-bar { bottom: calc(3.9rem + env(safe-area-inset-bottom)); }
  .pad-bottom { padding-bottom: 0; }
}

/* stacked tables and single-column forms */
@media (max-width: 767.98px) {
  .page-title { font-size: 1.15rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { margin-top: .5rem; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
  .figures > div + div { border-left: 0; border-top: 1px solid var(--dtm-line); }
  .figures { grid-template-columns: minmax(0, 1fr); }
  .cmp { grid-template-columns: 1fr; }
  .cmp > div + div { border-left: 0; border-top: 1px solid var(--dtm-line); }
  .table-wrap { max-height: none; }
  .table.rt { display: block; }
  .table.rt thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.rt tbody, .table.rt tfoot { display: block; }
  .table.rt tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .15rem .9rem; padding: .7rem .9rem; border-bottom: 1px solid var(--dtm-line); position: relative; }
  .table.rt td { display: block; border: 0; padding: .1rem 0; min-width: 0; overflow-wrap: anywhere; text-align: left; background: transparent; }
  .table.rt td[data-label]::before { content: attr(data-label); display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--dtm-muted); font-weight: 650; }
  .table.rt td.rt-main, .table.rt td.rt-wide, .table.rt td.rt-actions { grid-column: 1 / -1; }
  .table.rt td.rt-main { font-weight: 600; }
  .table.rt td.rt-main::before, .table.rt td.rt-nolabel::before { display: none; }
  .table.rt td.rt-hide, .table.rt td:empty { display: none; }
  .table.rt td.rt-actions { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: flex-start; padding-top: .35rem; }
  .table.rt td.text-end, .table.rt td .money { text-align: left; }
  .table.rt tfoot tr { background: var(--dtm-brand-50); }
  .table.rt tbody tr.clickable:active { background: var(--dtm-brand-50); }
  .table.rt .form-check-input { position: absolute; top: .7rem; right: .8rem; }
  .perm-grid.rt tr { grid-template-columns: 1fr; }
}

/* phones */
@media (max-width: 575.98px) {
  .modal-dialog { margin: 0; }
  .modal-content { border-radius: 0; border: 0; }
  .modal-footer { position: sticky; bottom: 0; background: var(--dtm-card); padding-bottom: calc(.5rem + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .modal-footer > .btn { flex: 1 1 auto; }
  .form-actions .btn, .page-actions .btn { flex: 1 1 auto; }
  .stat-grid { grid-template-columns: minmax(0, 1fr); }
  .card-header { padding: .65rem .85rem; }
  .toolbar { padding: .7rem .85rem; }
  .topbar .user-chip .name-block { display: none; }
  .login-card { padding: 1.4rem; }
}
@media (max-width: 575.98px) and (min-width: 360px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi .val { font-size: 1.1rem; } }
@media (max-width: 359.98px) { .topbar { gap: .25rem; } .icon-btn { width: 34px; } }
@media (pointer: coarse) {
  .btn, .form-control, .form-select, .nav-link, .dropdown-item { min-height: var(--touch); }
  .btn-sm, .form-control-sm, .form-select-sm { min-height: 40px; }
  .form-check-input { width: 1.25rem; height: 1.25rem; }
  .icon-btn { width: var(--touch); height: var(--touch); }
}
@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation-duration: .01ms; animation-iteration-count: 1; transition-duration: .01ms; } }

/* ---------------------------------------------------------------- print */
.print-only { display: none; }
@media print {
  /* Bootstrap utilities such as d-flex carry !important, so hiding screen-only parts has to as well. */
  .sidebar, .topbar, .bottom-nav, .no-print, .toast-container, .loading-bar, .toolbar, .pager .btn, .side-backdrop, .page-head .page-actions { display: none !important; }
  body { background: #fff; color: #000; font-size: 11px; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .print-only { display: block; }
  .card { border: 0; box-shadow: none; }
  .table-wrap { max-height: none; overflow: visible; }
  .table.rt, .table.rt tbody, .table.rt tfoot { display: table; }
  .table.rt thead { position: static; width: auto; height: auto; clip: auto; display: table-header-group; }
  .table.rt tbody { display: table-row-group; }
  .table.rt tr { display: table-row; padding: 0; }
  .table.rt td { display: table-cell; padding: .25rem .4rem; }
  .table.rt td[data-label]::before { display: none; }
  .table.rt td.rt-hide { display: table-cell; }
  .table thead th { position: static; color: #000; }
  .table tfoot td { position: static; }
  .modal.show { position: static; display: block; }
  .modal-backdrop { display: none; }
  body.print-slip > *:not(.modal) { display: none !important; }
  .print-slip .modal-dialog { max-width: 80mm; margin: 0; }
  .print-slip .modal-content { border: 0; }
}
