/* Ergos CRM Viewer - warm coffee-trade look. Mobile-first; breakpoints: 760px, 1024px. */
:root {
  --green-900: #143427;
  --green-700: #1f4d3a;
  --green-600: #2a6650;
  --green-100: #e2eee7;
  --green-50: #f0f6f2;
  --cream: #faf6ee;
  --cream-2: #f3ecdd;
  --card: #fffdf9;
  --line: #e7dfce;
  --ink: #2a2724;
  --muted: #655e52;
  --accent: #a4561a;       /* the one accent: roasted caramel */
  --accent-700: #8a4613;
  --accent-100: #f7e8d8;
  --good: #1c7048; --good-bg: #dff1e6;
  --bad: #b3261e;  --bad-bg: #fbe3e0;
  --warn: #8a5a00; --warn-bg: #fbefcf;
  --info: #25557d; --info-bg: #e1edf8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(42, 39, 36, .06), 0 4px 14px rgba(42, 39, 36, .06);
  --font: "Noto Sans TC", system-ui, -apple-system, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--cream); overflow-x: hidden; }
h1, h2, h3, p { margin: 0; }
a { color: var(--green-700); text-underline-offset: 2px; }
a:hover { color: var(--green-900); }
ul { margin: 0; padding: 0; list-style: none; }
dl, dd { margin: 0; }
address { font-style: normal; }
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .9em; }
.longtext { white-space: pre-wrap; overflow-wrap: anywhere; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.icon { flex: none; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--green-900); color: #fff; padding: .6rem 1rem; border-radius: 8px; }
.skip-link:focus { top: 8px; }

/* ---------- shell ---------- */
.app-header { background: var(--green-700); color: #fff; }
.app-header__inner { max-width: 1240px; margin: 0 auto; padding: .7rem 16px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: inline-flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand__mark { width: 32px; height: 32px; border-radius: 9px; background: var(--cream); color: var(--green-700); display: grid; place-items: center; font-weight: 800; }
.brand__text span { opacity: .8; }
.pill { font-size: .75rem; padding: .15rem .6rem; border-radius: 999px; border: 1px solid rgba(255,255,255,.4); }
.app { max-width: 1240px; margin: 0 auto; padding: 0 16px 56px; outline: none; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px; padding: .55rem 1.1rem; border-radius: 10px; border: 1px solid transparent; background: var(--green-700); color: #fff; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s, transform .05s; }
.btn:hover { background: var(--green-900); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--green-700); }
.btn--accent { background: var(--accent); }
.btn--accent:hover { background: var(--accent-700); }
.btn--ghost { background: var(--card); color: var(--green-700); border-color: var(--line); }
.btn--ghost:hover { background: var(--green-50); color: var(--green-900); }
.btn--sm { min-height: 36px; padding: .3rem .8rem; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.is-disabled { background: var(--cream-2); color: var(--muted); cursor: not-allowed; }
.input { width: 100%; min-height: 44px; padding: .5rem .75rem; border: 1px solid #cfc5b0; border-radius: 10px; background: #fff; }
.input:hover { border-color: var(--green-600); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }
.field label { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .2rem; }

/* ---------- chips / badges ---------- */
.chip { display: inline-flex; align-items: center; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.chip--good { background: var(--good-bg); color: var(--good); }
.chip--warn { background: var(--warn-bg); color: var(--warn); }
.chip--alert { background: var(--bad-bg); color: var(--bad); }
.chip--info { background: var(--info-bg); color: var(--info); }
.chip--muted { background: var(--cream-2); color: var(--muted); }
.tags { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
.cls { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 .4rem; border-radius: 8px; font-weight: 800; font-size: .9rem; }
.cls--a { background: var(--green-700); color: #fff; }
.cls--b { background: #5b8c75; color: #fff; }
.cls--c { background: #e8dcc0; color: #5a4a22; }
.cls--d { background: #d9d4cb; color: #4b463e; }
.cls--e, .cls--f { background: #ece7de; color: #4b463e; }
.cls-pair { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); }
.var { font-weight: 700; white-space: nowrap; }
.var--good { color: var(--good); }
.var--bad { color: var(--bad); }
.ext-link::after { content: " ↗"; }
.count, .badge-count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 .4rem; border-radius: 999px; background: var(--green-100); color: var(--green-700); font-size: .75rem; font-weight: 700; }
.badge-count { background: var(--accent); color: #fff; }
.count--zero { background: var(--cream-2); color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.card__title { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: .7rem; display: flex; align-items: center; gap: .5rem; }

/* ---------- list page ---------- */
.searchbar { position: sticky; top: 0; z-index: 20; margin: 0 -16px; padding: .75rem 16px .6rem; background: rgba(250, 246, 238, .96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.searchbar__row { display: flex; gap: .6rem; }
.searchbox { position: relative; flex: 1; min-width: 0; }
.searchbox .icon { position: absolute; left: 12px; top: 12px; color: var(--muted); pointer-events: none; }
.input--search { padding-left: 2.4rem; }
.filters-toggle { flex: none; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .7rem; }
.filters[hidden] { display: none; }
.filters__clear { grid-column: 1 / -1; }
.list__count { margin: .8rem 0 .5rem; font-size: .85rem; color: var(--muted); }
.cards { display: grid; gap: .7rem; }
.client-card { display: block; padding: .9rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: inherit; text-decoration: none; }
.client-card:hover { border-color: var(--green-600); }
.client-card__top { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.client-card__name { font-weight: 700; font-size: 1.05rem; line-height: 1.3; color: var(--green-900); overflow-wrap: anywhere; }
.client-card__meta { color: var(--muted); font-size: .88rem; margin-top: .15rem; }
.client-card__chips { margin-top: .5rem; }
.client-card__nums { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .7rem; padding-top: .6rem; border-top: 1px dashed var(--line); }
.client-card__nums dt { font-size: .72rem; color: var(--muted); }
.client-card__nums dd { font-weight: 700; font-variant-numeric: tabular-nums; }
.clients-table-wrap { display: none; }
.list__more { text-align: center; margin-top: 1rem; }
.list__updated { margin: .6rem 0 0; font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: center; }
.list__updated:empty { display: none; }
.list__loading { margin: 0 0 .5rem; font-size: .85rem; color: var(--muted); }
.list__loading[hidden] { display: none; }

.clients-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.clients-table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--cream-2); padding: .7rem .9rem; white-space: nowrap; }
.clients-table td { padding: .75rem .9rem; border-top: 1px solid var(--line); vertical-align: middle; }
.clients-table th.num, .clients-table td.num { text-align: right; }
.clients-table tbody tr { cursor: pointer; }
.clients-table tbody tr:hover { background: var(--green-50); }
.row-link { font-weight: 700; color: var(--green-900); text-decoration: none; }
.row-link:hover { text-decoration: underline; }
.sub { font-size: .8rem; color: var(--muted); }

/* ---------- client page ---------- */
.back-link { display: inline-flex; align-items: center; gap: .2rem; margin: 1rem 0 .7rem; text-decoration: none; font-weight: 600; min-height: 32px; }
.client-head { display: grid; gap: 1rem; padding: 1.2rem; border-top: 4px solid var(--green-700); }
.client-head__name { font-size: 1.55rem; line-height: 1.25; color: var(--green-900); overflow-wrap: anywhere; outline: none; }
.client-head__chips { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .9rem; margin-top: .6rem; }
.client-head__meta { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; margin-top: .8rem; }
.client-head__meta dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.client-head__meta dd { font-weight: 600; }
.client-head__actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.client-head__actions .btn { min-height: 48px; }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; margin: .9rem 0 1.1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; box-shadow: var(--shadow); min-width: 0; }
.kpi__label { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi__value { font-size: 1.3rem; font-weight: 800; color: var(--green-900); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; margin-top: .15rem; }
.kpi__sub { font-size: .8rem; margin-top: .15rem; }
.kpi__subtext { color: var(--muted); }
.kpi--alert { background: #fff6f4; border-color: #f0c9c3; }
.kpi--alert .kpi__value { color: var(--bad); }

/* tabs: scrollable top bar on mobile/tablet, left rail on desktop */
.tabs-layout { display: block; }
.tabs-rail { position: sticky; top: 0; z-index: 15; margin: 0 -16px; padding: .4rem 16px 0; background: var(--cream); border-bottom: 1px solid var(--line); }
.tablist { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tablist::-webkit-scrollbar { display: none; }
.tab { flex: none; display: inline-flex; align-items: center; gap: .45rem; min-height: 46px; padding: .5rem .9rem; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; border-radius: 8px 8px 0 0; }
.tab:hover { color: var(--green-900); background: var(--cream-2); }
.tab[aria-selected="true"] { color: var(--green-700); border-bottom-color: var(--green-700); }
.tab[aria-selected="true"] .count { background: var(--green-700); color: #fff; }
.panels { padding-top: 1rem; min-width: 0; }
.panel { outline-offset: 4px; }
.tab-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }

/* overview */
.overview { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.overview__bar { display: flex; justify-content: flex-end; }
.toggle { display: inline-flex; align-items: center; gap: .4rem; font-size: .88rem; color: var(--muted); cursor: pointer; min-height: 32px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--green-700); }
.hide-empty .is-empty { display: none; }
.overview__grid { display: grid; gap: 1rem; align-items: start; }
.comments { background: var(--accent-100); border-color: #ecd1b5; border-left: 5px solid var(--accent); }
.comments .card__title { color: var(--accent-700); }
.comments p { font-size: 1.02rem; }
.fields { display: grid; gap: .1rem; }
.field-row { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: .75rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.field-row:first-child { border-top: 0; }
.field-row dt { font-size: .85rem; color: var(--muted); }
.field-row dd { overflow-wrap: anywhere; font-weight: 500; }
.people { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.person { border: 1px solid var(--line); border-radius: 12px; padding: .8rem .9rem; background: #fff; min-width: 0; }
.person__name { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-weight: 700; overflow-wrap: anywhere; }
.person__job { font-size: .85rem; color: var(--muted); margin-top: .1rem; }
.person__rows { margin-top: .5rem; display: grid; gap: .25rem; }
.person__rows > div { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); gap: .5rem; font-size: .92rem; }
.person__rows dt { color: var(--muted); font-size: .8rem; padding-top: .1rem; }
.person__rows dd { overflow-wrap: anywhere; }
.person__rows a { display: inline-block; padding: .1rem 0; }
.addr { margin-top: .4rem; line-height: 1.45; }

/* summary strip */
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .75rem; min-width: 0; }
.stat dt { font-size: .72rem; color: var(--muted); font-weight: 600; }
.stat dd { font-weight: 800; font-size: 1.1rem; color: var(--green-900); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat--alert dd { color: var(--bad); }

/* data table */
.dt { display: grid; grid-template-columns: minmax(0, 1fr); gap: .7rem; }
.dt__toolbar { display: grid; grid-template-columns: 1fr; gap: .6rem; }
.dt__status { font-size: .82rem; color: var(--muted); min-height: 1.2em; }
.dtable-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.dtable { width: 100%; border-collapse: separate; border-spacing: 0; }
.dtable th { position: sticky; top: 0; z-index: 2; text-align: left; background: var(--cream-2); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .65rem .8rem; white-space: nowrap; border-bottom: 1px solid var(--line); }
.dtable td { padding: .6rem .8rem; border-top: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
.dtable td.is-text, .dtable td.is-wide { white-space: normal; min-width: 14rem; }
.dtable td.w-l { min-width: 20rem; }
.dtable td.w-xl { min-width: 26rem; }
.dtable td.w-xxl { min-width: 34rem; }
.dtable td.is-text .longtext { display: block; }
.dtable th.num, .dtable td.num { text-align: right; }
.dtable tbody tr:hover { background: var(--green-50); }
.dtable tr.is-flagged { background: #fff3f1; box-shadow: inset 4px 0 0 var(--bad); }
.dtable td.is-strong { font-weight: 800; color: var(--bad); }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.pager:empty { display: none; }
.pager__info { font-size: .88rem; color: var(--muted); }

/* sales by year */
.charts { display: grid; gap: 1rem; }
.chart { margin: 0; }
.chart__svg { width: 100%; max-width: 460px; height: auto; display: block; margin: 0 auto; }
.bar { fill: var(--green-700); }
.bar--y1 { fill: #5b8c75; }
.bar--y2 { fill: #a9bdb0; }
.bar--est { stroke: var(--green-700); stroke-width: 1.5; stroke-dasharray: 4 3; }
.hatch-bg { fill: #e8f1ec; }
.hatch-fg { fill: #9fc0ae; }
.chart__axis { stroke: var(--line); stroke-width: 2; }
.chart__val { font-size: 13px; font-weight: 700; fill: var(--ink); }
.chart__lbl { font-size: 11.5px; font-weight: 600; fill: var(--ink); }
.chart__sub { font-size: 10.5px; fill: var(--muted); }
.legend { font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.legend__sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1.5px solid var(--green-700); }
.legend__sw--est { background: repeating-linear-gradient(45deg, #e8f1ec 0 3px, #9fc0ae 3px 6px); border-style: dashed; }
.legend__sw--act { background: var(--green-700); margin-left: .6rem; }
.dtable-wrap--static { max-height: none; }
.ytable { width: 100%; border-collapse: collapse; min-width: 520px; }
.ytable th, .ytable td { padding: .7rem .9rem; border-top: 1px solid var(--line); white-space: nowrap; }
.ytable thead th { background: var(--cream-2); font-size: .8rem; text-align: right; border-top: 0; }
.ytable thead th:first-child { text-align: left; }
.ytable tbody th { text-align: left; font-weight: 600; color: var(--muted); font-size: .88rem; white-space: normal; }
.th-sub { font-weight: 500; color: var(--muted); font-size: .72rem; text-transform: none; letter-spacing: 0; }
.note { font-size: .82rem; color: var(--muted); }

/* emails */
.callout { display: flex; gap: .9rem; padding: 1rem 1.1rem; border-radius: var(--radius); background: var(--green-50); border: 1px dashed #9fc0ae; }
.callout__icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: var(--green-100); color: var(--green-700); }
.callout h3 { font-size: 1.05rem; color: var(--green-900); }
.callout p { color: var(--muted); font-size: .92rem; margin-top: .2rem; }
.threads { display: grid; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.thread { display: flex; gap: .8rem; padding: .85rem 1rem; border-top: 1px solid var(--line); opacity: .92; }
.thread:first-child { border-top: 0; }
.thread__avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--accent-100); color: var(--accent-700); display: grid; place-items: center; font-weight: 800; }
.thread__main { min-width: 0; flex: 1; }
.thread__top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.thread__from { font-weight: 700; }
.thread__date { margin-left: auto; font-size: .8rem; color: var(--muted); }
.thread__subject { font-weight: 600; overflow-wrap: anywhere; }
.thread__n { color: var(--muted); font-weight: 500; }
.thread__snippet { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* empty + skeleton */
.empty { text-align: center; padding: 2.5rem 1rem; background: var(--card); border: 1px dashed #d8cdb6; border-radius: var(--radius); display: grid; gap: .4rem; justify-items: center; }
.empty__art { font-size: 2rem; }
.empty__title { font-size: 1.1rem; color: var(--green-900); }
.empty__text { color: var(--muted); max-width: 36ch; }
.empty .btn { margin-top: .6rem; }
.skeleton { border-radius: var(--radius); background: linear-gradient(90deg, #eee6d4 25%, #f6f0e2 37%, #eee6d4 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.view-skeleton { display: grid; gap: .8rem; padding-top: 1rem; }
.sk-bar { height: 48px; } .sk-row { height: 84px; } .sk-head { height: 150px; } .sk-kpi { height: 78px; } .sk-tabs { height: 44px; }
.sk-kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } * { scroll-behavior: auto !important; } }

/* ---------- mobile: tables become cards ---------- */
@media (max-width: 759px) {
  .dtable-wrap { overflow: visible; background: none; border: 0; box-shadow: none; }
  .dtable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .dtable, .dtable tbody { display: block; }
  .dtable tr { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem 1rem; padding: .8rem .9rem; margin-bottom: .6rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  .dtable tr.is-flagged { box-shadow: inset 4px 0 0 var(--bad), var(--shadow); }
  .dtable td { display: block; padding: 0; border: 0; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: left; }
  .dtable td.num { text-align: left; }
  .dtable td::before { content: attr(data-label); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
  .dtable td.is-primary, .dtable td.is-wide, .dtable td.is-text { grid-column: 1 / -1; min-width: 0; }
  .dtable td.is-primary { font-weight: 700; font-size: 1.02rem; }
  .dtable td.is-primary::before { display: none; }
  .dtable-wrap--static { overflow-x: auto; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
}

/* ---------- >= 560px ---------- */
@media (min-width: 560px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sk-kpis { grid-template-columns: repeat(3, 1fr); }
  .dt__toolbar { grid-template-columns: 1fr 220px; }
}

/* ---------- >= 760px: table list, inline filters ---------- */
@media (min-width: 760px) {
  body { font-size: 15.5px; }
  .app, .app-header__inner { padding-left: 24px; padding-right: 24px; }
  .searchbar { margin: 0 -24px; padding: .8rem 24px; }
  .tabs-rail { margin: 0 -24px; padding: .4rem 24px 0; }
  .filters-toggle { display: none; }
  .filters, .filters[hidden] { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; align-items: end; }
  .filters__clear { grid-column: auto; }
  .cards { display: none; }
  .clients-table-wrap { display: block; }
  .client-head { grid-template-columns: 1fr auto; align-items: start; padding: 1.4rem 1.5rem; }
  .client-head__name { font-size: 1.9rem; }
  .client-head__actions { grid-template-columns: auto auto; }
  .overview__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card--wide { grid-column: 1 / -1; }
  .charts { grid-template-columns: 1fr 1fr; }
  .summary { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* ---------- >= 1024px: left rail tabs ---------- */
@media (min-width: 1024px) {
  .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .kpi__value { font-size: 1.15rem; }
  .tabs-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
  .tabs-rail { position: sticky; top: 16px; margin: 0; padding: .5rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
  .tablist { flex-direction: column; overflow: visible; }
  .tab { justify-content: space-between; border-bottom: 0; border-left: 3px solid transparent; border-radius: 8px; min-height: 42px; }
  .tab[aria-selected="true"] { background: var(--green-50); border-left-color: var(--green-700); }
  .panels { padding-top: 0; }
  .dtable-wrap:not(.dtable-wrap--static) { max-height: min(68vh, 640px); }
}

/* sr-only children are absolutely positioned: give them a clipped containing block so they cannot widen the page */
.var, .dtable-wrap, .ytable td, .ytable th, .dtable td, .stat dd, .kpi { position: relative; }
@media (max-width: 759px) {
  .client-head__actions .btn { padding: .5rem .6rem; font-size: .92rem; white-space: nowrap; gap: .35rem; }
}

/* ---------- login gate, user menu, banners (added with the Ragic data layer) ---------- */
.app-header__side { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.user-menu[hidden] { display: none; }
.user-menu { display: flex; align-items: center; gap: .6rem; font-size: .8rem; min-width: 0; }
.user-menu__email { opacity: .85; max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu__out { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 999px; padding: .2rem .7rem; cursor: pointer; min-height: 32px; }
.user-menu__out:hover { background: rgba(255,255,255,.14); }
@media (max-width: 520px) { .user-menu__email { display: none; } }

.banners:empty { display: none; }
.banners { max-width: 1240px; margin: .6rem auto 0; padding: 0 16px; display: grid; gap: .4rem; }
.banner { display: flex; align-items: flex-start; gap: .6rem; padding: .55rem .8rem; border-radius: 10px; font-size: .88rem; border: 1px solid var(--line); }
.banner--warn { background: var(--warn-bg); color: var(--warn); border-color: #ecd28a; }
.banner__text { flex: 1; overflow-wrap: anywhere; }
.banner__close { background: none; border: 0; color: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; min-width: 32px; min-height: 32px; }

/* Hide the whole app until signed in. */
body[data-auth="pending"] .app-header, body[data-auth="pending"] #app, body[data-auth="pending"] #banners,
body[data-auth="out"] .app-header, body[data-auth="out"] #app, body[data-auth="out"] #banners { display: none; }
.gate { display: none; }
body[data-auth="out"] .gate { display: grid; min-height: 100vh; place-items: center; padding: 1.5rem 16px; background: var(--cream); }
.gate__card { width: min(100%, 26rem); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem 1.5rem; display: grid; gap: .9rem; justify-items: center; text-align: center; }
.gate__mark { width: 52px; height: 52px; border-radius: 14px; background: var(--green-700); color: var(--cream); display: grid; place-items: center; font-weight: 800; font-size: 1.5rem; }
.gate__title { font-size: 1.35rem; color: var(--green-900); }
.gate__text { color: var(--muted); }
.gate__msg { font-size: .9rem; padding: .5rem .7rem; border-radius: 8px; width: 100%; }
.gate__msg--info { background: var(--info-bg); color: var(--info); }
.gate__msg--error { background: var(--bad-bg); color: var(--bad); }
.gate__btn { width: 100%; }
.gate__skip { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: .85rem; }
.gate__foot { font-size: .8rem; color: var(--muted); }

/* ---- section nav (Clients / Suppliers) ---- */
.app-nav { display: flex; gap: .25rem; margin-left: auto; margin-right: .5rem; }
.app-nav a { color: #fff; text-decoration: none; padding: .35rem .7rem; border-radius: 999px; font-weight: 600; font-size: .92rem; opacity: .85; }
.app-nav a[hidden] { display: none; }
.app-nav a[aria-current] { background: rgba(255,255,255,.18); opacity: 1; }
.app-nav a:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.secret { white-space: nowrap; }
.card__title { font-size: 1rem; margin-bottom: .6rem; }
.card + .card, .kpis + .card { margin-top: 1rem; }
@media (max-width: 520px) { .app-nav a { padding: .3rem .5rem; font-size: .85rem; } .brand__text span { display: none; } }

.shape-list { list-style: none; margin: .5rem 0 0; padding: 0; columns: 2 18rem; }
.shape-list li { padding: .15rem 0; break-inside: avoid; overflow-wrap: anywhere; }
.shape-list .muted { color: var(--muted); font-size: .8rem; }

.client-card__farms { color: var(--ink); font-size: .85rem; margin-top: .3rem; overflow-wrap: anywhere; }
.farms-cell { max-width: 26rem; overflow-wrap: anywhere; font-size: .88rem; }

.client-card__regions { color: var(--muted); font-size: .82rem; margin-top: .15rem; overflow-wrap: anywhere; }
.field--range { grid-column: 1 / -1; }
.range { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem; }

@media (min-width: 700px) { .filters--sup { grid-template-columns: minmax(0, 12rem) minmax(0, 12rem) minmax(0, 22rem); } .filters--sup .field--range { grid-column: auto; } }
