/* Mustache Home — Studio Admin */
:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #16130f;
  --ink-2: #211d18;
  --text: #1c1917;
  --text-2: #57514a;
  --text-3: #7d766d;
  --line: #e6e0d6;
  --line-2: #efeae2;
  --gold: #b07a1f;
  --gold-soft: #f6ecd9;
  --gold-hover: #94661a;
  --focus: #b07a1f;
  /* chart series (validated: tools/dataviz validator, light surface) */
  --s1: #b07a1f; --s2: #00968a; --s3: #c2502f; --s4: #3f63b8; --s5: #6f8f1f; --s6: #a2468a;
  /* status (reserved, always with label) */
  --good: #0f7b3e; --good-bg: #e3f4ea;
  --warn: #8a5a00; --warn-bg: #fdf1d6;
  --bad: #b42323; --bad-bg: #fbe5e3;
  --info: #2f55a4; --info-bg: #e4ebf8;
  --muted-bg: #efeae2;
  --surface-2: #fbf9f5;
  --hover: #fcfaf6;
  --field: #ffffff;
  --line-strong: #cfc6b8;
  --glass: rgba(255,255,255,.95);
  --glass-top: rgba(245,242,236,.88);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22,19,15,.05), 0 8px 24px -12px rgba(22,19,15,.12);
  --f-display: 'Cinzel', Georgia, serif;
  --f-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --side-w: 256px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--f-body); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 500; text-decoration: none; white-space: nowrap; transition: background .2s, border-color .2s, color .2s, transform .1s; }
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn--primary:hover { background: #2c2620; border-color: #2c2620; color: #fff; }
.btn--gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn--gold:hover { background: var(--gold-hover); color: #fff; }
.btn--danger { color: var(--bad); }
.btn--danger:hover { background: var(--bad-bg); border-color: #efc2bd; }
.btn--sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn--block { width: 100%; }
.btn--ghost { border-color: transparent; background: transparent; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; display: inline-grid; place-items: center; color: var(--text-2); position: relative; }
.icon-btn:hover { background: var(--muted-bg); color: var(--text); }
.icon-btn--sm { width: 32px; height: 32px; }
.badge { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.2fr 1fr; background: var(--ink); }
.login__art { position: relative; overflow: hidden; }
.login__art img { width: 100%; height: 100%; object-fit: cover; opacity: .75; }
.login__card { align-self: center; justify-self: center; width: min(420px, 90vw); background: var(--card); padding: 44px 40px; border-radius: 22px; display: grid; gap: 16px; }
.login__mark { width: 72px; fill: var(--gold); }
.login h1 { font-family: var(--f-display); font-weight: 500; margin: 0; font-size: 28px; }
.login p { margin: 0; }
.login__err { color: var(--bad); min-height: 20px; font-size: 14px; }
.login__back { font-size: 14px; color: var(--text-2); text-decoration: none; text-align: center; }
@media (max-width: 860px) { .login { grid-template-columns: 1fr; } .login__art { display: none; } }

/* Layout */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; background: var(--ink); color: #d8d1c6; display: flex; flex-direction: column; overflow-y: auto; z-index: 60; }
.side__brand { display: flex; align-items: center; gap: 10px; padding: 22px 22px 18px; text-decoration: none; color: #fff; }
.side__brand svg { width: 40px; fill: var(--gold); }
.side__brand span { font-family: var(--f-display); letter-spacing: .1em; text-transform: uppercase; font-size: 15px; }
.side__brand b { font-weight: 400; color: #d6ad62; margin-left: 4px; }
.side__nav { padding: 6px 12px 20px; display: grid; gap: 2px; }
.side__group { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #8d857a; padding: 16px 12px 6px; }
.side__nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; text-decoration: none; color: #d8d1c6; font-size: 14.5px; transition: background .2s, color .2s; }
.side__nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side__nav a.is-active { background: rgba(214,173,98,.16); color: #f2d9a8; }
.side__nav a .count { margin-left: auto; font-size: 11px; background: #d6ad62; color: var(--ink); border-radius: 9px; padding: 1px 7px; font-weight: 700; }
.side__foot { margin-top: auto; padding: 16px 24px 24px; font-size: 13px; }
.side__foot a { color: #b5ada1; text-decoration: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: var(--glass-top); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top__menu { display: none; }
.search { position: relative; flex: 1; max-width: 560px; display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
.search input { border: 0; outline: 0; background: transparent; height: 42px; flex: 1; min-width: 0; }
.search .i { color: var(--text-3); }
.search__results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 420px; overflow: auto; padding: 6px; }
.search__results a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; text-decoration: none; }
.search__results a:hover, .search__results a.is-focus { background: var(--muted-bg); }
.search__results small { color: var(--text-3); margin-left: auto; }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--gold-soft); color: var(--gold-hover); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.user__meta { line-height: 1.2; }
.user__meta b { display: block; font-size: 14px; font-weight: 600; }
.user__meta span { font-size: 12px; color: var(--text-3); text-transform: capitalize; }
.page { padding: 26px 28px 60px; outline: none; }
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: var(--side-w); transform: translateX(-100%); transition: transform .3s; }
  .side.is-open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .top__menu { display: inline-grid; }
  .user__meta { display: none; }
  .page { padding: 18px 16px 60px; }
  .top { padding: 10px 14px; }
}

/* Page header */
.ph { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.ph h1 { margin: 0; font-family: var(--f-display); font-weight: 500; font-size: 26px; letter-spacing: .01em; }
.ph p { margin: 4px 0 0; color: var(--text-2); }
.ph__actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 13px; color: var(--text-3); text-decoration: none; display: inline-flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.crumb:hover { color: var(--text); }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card__h h2, .card__h h3 { margin: 0; font-size: 15.5px; font-weight: 600; }
.card__h .sub { color: var(--text-3); font-size: 13px; }
.card__h .tools { margin-left: auto; display: flex; gap: 6px; }
.card__b { padding: 16px 18px 18px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1200px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .g-2, .g-3, .g-4 { grid-template-columns: minmax(0, 1fr); } }
.mt { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* KPI tiles */
.kpi { padding: 16px 18px; display: grid; gap: 4px; position: relative; }
.kpi__label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.kpi__label .i { color: var(--gold); }
.kpi__value { font-size: 26px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: 12.5px; color: var(--text-3); }
.kpi--link { text-decoration: none; transition: border-color .2s; }
.kpi--link:hover { border-color: var(--line-strong); }
.delta { font-weight: 600; }
.delta--up { color: var(--good); } .delta--down { color: var(--bad); }

/* Filter bar */
.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 6px 11px; font-size: 13px; color: var(--text-2); min-height: 32px; }
.seg button:hover { color: var(--text); }
.seg button.is-on { background: var(--ink); color: #fff; }
.inp, .sel { height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 0 12px; min-width: 0; }
.sel { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2357514a' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.inp:focus, .sel:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.inp--sm, .sel--sm { height: 34px; font-size: 13.5px; }

/* Tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--text-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .arr { opacity: .5; margin-left: 4px; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tbody tr { transition: background .15s; }
.tbl tbody tr:hover { background: var(--hover); }
.tbl tbody tr.is-click { cursor: pointer; }
.tbl tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--line); }
.tbl .actions { white-space: nowrap; text-align: right; width: 1%; }
.tbl-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.tbl-top .inp { width: 260px; }
.tbl-foot { display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-size: 13px; color: var(--text-2); }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty .i { width: 36px; height: 36px; margin-bottom: 8px; color: var(--text-3); }
.link { color: var(--text); font-weight: 500; text-decoration: none; }
.link:hover { color: var(--gold-hover); text-decoration: underline; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--text-2); }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--muted-bg); display: block; }

/* Pills (status always shows its text label) */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--muted-bg); color: var(--text-2); white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--good { background: var(--good-bg); color: var(--good); }
.pill--warn { background: var(--warn-bg); color: var(--warn); }
.pill--bad { background: var(--bad-bg); color: var(--bad); }
.pill--info { background: var(--info-bg); color: var(--info); }
.pill--gold { background: var(--gold-soft); color: var(--gold-hover); }

/* Progress */
.prog { height: 6px; background: var(--muted-bg); border-radius: 6px; overflow: hidden; min-width: 80px; }
.prog span { display: block; height: 100%; background: var(--gold); border-radius: 6px; }

/* Forms */
.form { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.fld { display: grid; gap: 6px; grid-column: span 6; align-content: start; }
.fld--12 { grid-column: span 12; } .fld--4 { grid-column: span 4; } .fld--3 { grid-column: span 3; } .fld--8 { grid-column: span 8; }
@media (max-width: 700px) { .fld, .fld--4, .fld--3, .fld--8 { grid-column: span 12; } }
.fld > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.fld > span em { color: var(--bad); font-style: normal; }
.fld input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .fld select, .fld textarea { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); padding: 9px 12px; }
.fld textarea { resize: vertical; min-height: 84px; }
.fld select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2357514a' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.fld input[readonly] { background: var(--hover); color: var(--text-2); }
.fld small { color: var(--text-3); font-size: 12.5px; }
.fld { min-width: 0; grid-template-columns: minmax(0, 1fr); }
.fld select, .row > select, .row > input { min-width: 0; max-width: 100%; }
.fld .err { color: var(--bad); }
.fld.is-invalid input, .fld.is-invalid select { border-color: var(--bad); }
.check { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); }
.form-sec { grid-column: span 12; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--gold-hover); font-weight: 700; border-top: 1px solid var(--line-2); padding-top: 14px; margin-top: 4px; }

/* Uploader */
.upl { border: 1.5px dashed var(--line-strong); border-radius: 12px; padding: 14px; background: var(--hover); }
.upl.is-drag { border-color: var(--gold); background: var(--gold-soft); }
.upl__row { display: flex; flex-wrap: wrap; gap: 10px; }
.upl__item { position: relative; width: 96px; height: 96px; border-radius: 10px; overflow: hidden; background: var(--muted-bg); }
.upl__item img, .upl__item video { width: 100%; height: 100%; object-fit: cover; }
.upl__item button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }
.upl__item button .i { width: 14px; height: 14px; }
.upl__add { width: 96px; height: 96px; border-radius: 10px; border: 1px solid var(--line); background: var(--field); display: grid; place-items: center; align-content: center; gap: 4px; color: var(--text-2); font-size: 12px; }
.upl__add input { display: none; }
.upl__add:hover { border-color: var(--gold); color: var(--gold-hover); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; background: rgba(22,19,15,.45); animation: fade .2s ease-out; }
.modal__box { width: min(760px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--card); border-radius: 18px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); animation: pop .25s cubic-bezier(.16,1,.3,1); }
.modal__box--lg { width: min(1100px, 100%); }
.modal__box--sm { width: min(460px, 100%); }
.modal__h { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal__h h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal__h .icon-btn { margin-left: auto; }
.modal__b { padding: 20px 22px; overflow-y: auto; }
.modal__f { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 18px 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

/* Toast */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: grid; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; display: flex; gap: 10px; align-items: center; animation: pop .25s; max-width: 380px; }
.toast--error { background: var(--bad); }
.toast .i { color: #d6ad62; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.is-on { color: var(--text); border-color: var(--gold); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list b { font-weight: 600; }
.list .meta { font-size: 12.5px; color: var(--text-3); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); flex: none; }

/* Charts */
.chart { position: relative; height: 280px; }
.chart--sm { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); padding: 0 18px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 2px; border-radius: 1px; }
.chart-table { max-height: 280px; overflow: auto; }

/* Board (follow-ups) */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; }
.col { background: var(--muted-bg); border-radius: 14px; padding: 12px; min-height: 200px; }
.col h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.col h3 .n { margin-left: auto; font-size: 12px; background: var(--field); border-radius: 10px; padding: 1px 8px; }
.fu { background: var(--field); border-radius: 12px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); display: grid; gap: 6px; }
.fu b { font-size: 14px; }
.fu .row { gap: 6px; }

/* Media grid */
.media { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.media__item { position: relative; border-radius: 12px; overflow: hidden; background: var(--muted-bg); aspect-ratio: 4/3; border: 1px solid var(--line); }
.media__item img, .media__item video { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.media__bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 4px; padding: 6px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; font-size: 12px; }
.media__bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; }
.media__bar button { width: 28px; height: 28px; border: 0; border-radius: 8px; background: rgba(255,255,255,.18); color: #fff; display: grid; place-items: center; }
.media__bar button:hover { background: rgba(255,255,255,.35); }
.media__bar .i { width: 15px; height: 15px; }
.media__tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; }

/* Catalogue cards */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.cat-card { overflow: hidden; display: flex; flex-direction: column; }
.cat-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--muted-bg); }
.cat-card .card__b { padding: 12px 14px 14px; display: grid; gap: 6px; }
.cat-card b { font-size: 14.5px; }

/* Map */
.map { height: 460px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.map--sm { height: 240px; }
.mpin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }

/* Line-item editor */
.items { width: 100%; border-collapse: collapse; min-width: 820px; }
.items td:first-child { min-width: 300px; }
.items td:nth-child(2) input { min-width: 120px; }
.items th { font-size: 12.5px; color: var(--text-2); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-weight: 600; }
.items td { padding: 6px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.items input, .items select, .items textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-height: 36px; background: var(--field); }
.items textarea { resize: vertical; min-height: 36px; }
.items input:focus, .items textarea:focus { outline: none; border-color: var(--gold); }
.items .num input { text-align: right; }
.items .amt { padding-top: 14px; font-weight: 600; }
.totals { margin-left: auto; width: min(380px, 100%); display: grid; gap: 8px; }
.totals div { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.totals .grand { font-size: 20px; font-weight: 700; border-top: 1px solid var(--line); padding-top: 10px; }
.totals input { width: 110px; text-align: right; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

/* Detail key-values */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }

/* P&L bars */
.pl { display: grid; gap: 10px; }
.pl__row { display: grid; grid-template-columns: 150px 1fr 120px; gap: 12px; align-items: center; font-size: 14px; }
.pl__bar { height: 12px; border-radius: 4px; background: var(--muted-bg); overflow: hidden; }
.pl__bar span { display: block; height: 100%; border-radius: 0 4px 4px 0; }

/* Attendance */
.att { display: inline-flex; gap: 4px; }
.att label { position: relative; }
.att input { position: absolute; opacity: 0; }
.att span { display: inline-grid; place-items: center; min-width: 38px; height: 32px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.att input:checked + span.p { background: var(--good-bg); color: var(--good); border-color: #b9e0c8; }
.att input:checked + span.a { background: var(--bad-bg); color: var(--bad); border-color: #efc2bd; }
.att input:checked + span.h { background: var(--warn-bg); color: var(--warn); border-color: #f0d9a4; }
.att input:checked + span.l { background: var(--info-bg); color: var(--info); border-color: #c5d3ee; }
.att input:focus-visible + span { outline: 2px solid var(--focus); }

/* Notifications panel */
.notif { position: fixed; top: 64px; right: 20px; width: min(380px, calc(100vw - 40px)); z-index: 120; }
.notif .card__b { max-height: 60vh; overflow: auto; }

/* Print documents */
.doc { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto; padding: 16mm 14mm; color: #111; font-size: 12.5px; box-shadow: var(--shadow); }
.doc__head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 14px; border-bottom: 2px solid #111; }
.doc__brand { display: flex; gap: 12px; align-items: center; }
.doc__brand svg { width: 64px; fill: var(--gold); }
.doc__brand h1 { font-family: var(--f-display); font-size: 22px; margin: 0; font-weight: 600; letter-spacing: .04em; }
.doc__brand p { margin: 2px 0 0; color: #555; font-size: 11.5px; max-width: 320px; }
.doc__title { text-align: right; }
.doc__title h2 { margin: 0; font-family: var(--f-display); font-size: 24px; letter-spacing: .12em; color: var(--gold-hover); }
.doc__title p { margin: 2px 0; }
.doc__parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 16px 0; }
.doc__parties h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #777; }
.doc__parties p { margin: 0; }
.doc table { width: 100%; border-collapse: collapse; }
.doc th { background: #16130f; color: #fff; text-align: left; padding: 7px 8px; font-size: 11.5px; font-weight: 600; }
.doc td { padding: 7px 8px; border-bottom: 1px solid #e5e5e5; vertical-align: top; }
.doc td.num, .doc th.num { text-align: right; }
.doc__sum { display: flex; justify-content: space-between; gap: 20px; margin-top: 14px; }
.doc__sum table { width: 300px; }
.doc__sum td { border: 0; padding: 4px 8px; }
.doc__sum tr.grand td { border-top: 2px solid #111; font-size: 15px; font-weight: 700; padding-top: 8px; }
.doc__words { font-style: italic; color: #333; max-width: 360px; }
.doc__terms { margin-top: 20px; font-size: 11.5px; color: #333; white-space: pre-line; }
.doc__terms h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #777; }
.doc__sign { display: flex; justify-content: space-between; margin-top: 50px; }
.doc__sign div { border-top: 1px solid #111; padding-top: 6px; width: 200px; text-align: center; font-size: 11.5px; }
.doc__bank { margin-top: 14px; font-size: 11.5px; }
.doc-actions { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: var(--field); }
  .side, .top, .doc-actions, .toasts, .ph { display: none !important; }
  .app { display: block; }
  .page { padding: 0; }
  .doc { box-shadow: none; margin: 0; width: auto; min-height: auto; }
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ==========================================================================
   Mobile-first layer — the admin behaves like a phone app for site teams
   ========================================================================== */
.bnav, .m-only { display: none; }
@media (max-width: 980px) {
  .bnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
  .bnav a, .bnav button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border: 0; background: none; border-radius: 12px; font-size: 11px; font-weight: 500; color: var(--text-2); text-decoration: none; -webkit-tap-highlight-color: transparent; }
  .bnav a:active, .bnav button:active { background: var(--muted-bg); }
  .bnav .i { width: 22px; height: 22px; }
  .bnav .is-active { color: var(--gold-hover); }
  .bnav .is-active .i { stroke-width: 2.3; }
  .bnav .badge { top: 3px; right: calc(50% - 24px); }
  .page { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .side { padding-top: env(safe-area-inset-top); z-index: 120; }
  .top { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; gap: 6px; }
  .notif { top: calc(60px + env(safe-area-inset-top)); left: 12px; right: 12px; width: auto; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .m-only { display: inline-flex; }
  .search { padding: 0 10px; }
  .search input { height: 40px; font-size: 16px; }
  .user .avatar { display: none; }
  .page { padding: 16px 14px calc(110px + env(safe-area-inset-bottom)); }

  /* page header: title on top, actions as a swipeable row */
  .ph { gap: 12px; margin-bottom: 14px; }
  .ph h1 { font-size: 21px; }
  .ph p { font-size: 13.5px; }
  .ph__actions { margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .ph__actions::-webkit-scrollbar { display: none; }
  .ph__actions .btn { flex: none; min-height: 42px; }

  /* floating "Add" button */
  .ph__actions [data-new] { position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 75; min-height: 54px; padding: 0 20px; border-radius: 999px; box-shadow: 0 14px 30px -10px rgba(22,19,15,.6); }

  /* KPIs two-up */
  .grid { gap: 10px; }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 12px 14px; }
  .kpi__label { font-size: 12px; gap: 6px; }
  .kpi__value { font-size: 20px; }
  .kpi__sub, .delta { font-size: 11.5px; }
  .card__h { padding: 14px 14px 0; flex-wrap: wrap; }
  .card__b { padding: 14px; }
  .chart { height: 240px; }
  .chart--sm { height: 220px; }

  /* filters scroll sideways instead of wrapping */
  .filterbar { flex-wrap: nowrap; overflow-x: auto; margin: 0 -14px 14px; padding: 0 14px 4px; scrollbar-width: none; }
  .filterbar::-webkit-scrollbar { display: none; }
  .filterbar > * { flex: none; }
  .filterbar .spacer { display: none; }
  .seg { flex-wrap: nowrap; }
  .seg button { min-height: 36px; white-space: nowrap; }

  /* touch targets */
  .icon-btn--sm { width: 40px; height: 40px; }
  .btn--sm { min-height: 38px; }
  .inp, .sel { height: 42px; font-size: 16px; }

  /* data tables become cards */
  .tbl-top { padding: 12px; }
  .tbl-top .inp { width: 100%; flex: 1 1 100%; }
  .tbl-top .sel { flex: 1 1 45%; }
  .tbl-wrap > .tbl, .tbl-wrap > .tbl tbody, .tbl-wrap > .tbl tfoot { display: block; }
  .tbl-wrap > .tbl thead { display: none; }
  .tbl-wrap > .tbl tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 14px; border-bottom: 1px solid var(--line-2); }
  .tbl-wrap > .tbl tbody tr:active { background: var(--hover); }
  .tbl-wrap > .tbl td { display: block; padding: 0; border: 0; text-align: left; min-width: 0; overflow-wrap: anywhere; }
  .tbl-wrap > .tbl td::before { content: attr(data-label); display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 2px; }
  .tbl-wrap > .tbl td:not([data-label])::before, .tbl-wrap > .tbl td[data-label=""]::before { display: none; }
  .tbl-wrap > .tbl td.num { text-align: left; }
  .tbl-wrap > .tbl td.m-first { order: -1; grid-column: 1 / -1; font-size: 16px; }
  .tbl-wrap > .tbl td.m-first::before { display: none; }
  .tbl-wrap > .tbl td.m-hide { display: none; }
  .tbl-wrap > .tbl td.actions { order: 99; }
  .tbl-wrap > .tbl td[colspan] { grid-column: 1 / -1; }
  .tbl-wrap > .tbl td.actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 4px; width: auto; border-top: 1px dashed var(--line); padding-top: 8px; }
  .tbl-wrap > .tbl tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 12px 14px; background: var(--surface-2); }
  .tbl-wrap > .tbl tfoot td { border: 0; padding: 0; background: none; }
  .tbl-wrap > .tbl tfoot td:empty { display: none; }
  .tbl-foot { padding: 10px 12px; }

  /* forms open as bottom sheets */
  .modal { padding: 0; place-items: end stretch; }
  .modal__box, .modal__box--lg, .modal__box--sm { width: 100%; max-height: 94svh; border-radius: 20px 20px 0 0; animation: sheet .32s cubic-bezier(.16,1,.3,1); }
  .modal__box--lg { height: 100svh; max-height: 100svh; border-radius: 0; }
  .modal__h { position: relative; padding: 20px 16px 12px; }
  .modal__h::before { content: ''; position: absolute; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line-strong); }
  .modal__box--lg .modal__h { padding-top: calc(14px + env(safe-area-inset-top)); }
  .modal__box--lg .modal__h::before { display: none; }
  .modal__b { padding: 16px; }
  .modal__f { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-radius: 0; }
  .modal__f .btn { flex: 1; min-height: 48px; }
  .form { gap: 12px; }
  .fld input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .fld select, .fld textarea { font-size: 16px; min-height: 46px; }
  .map--sm { height: 220px; }
  .upl__item, .upl__add { width: calc(33.33% - 7px); height: auto; aspect-ratio: 1; }

  /* quotation / invoice line items stack */
  .items { min-width: 0; }
  .items thead { display: none; }
  .items, .items tbody { display: block; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .items td { padding: 0; border: 0; min-width: 0 !important; }
  .items td:first-child { grid-column: 1 / -1; }
  .items td:nth-child(2) { grid-column: span 2; }
  .items td:nth-child(6) { grid-column: span 2; padding-top: 22px; font-size: 16px; text-align: left; }
  .items td:nth-child(7) { padding-top: 16px; text-align: right; }
  .items td:nth-child(2)::before { content: 'Room / category'; }
  .items td:nth-child(3)::before { content: 'Unit'; }
  .items td:nth-child(4)::before { content: 'Qty'; }
  .items td:nth-child(5)::before { content: 'Rate'; }
  .items td::before { display: block; font-size: 11px; color: var(--text-3); margin-bottom: 3px; text-align: left; }
  .items input, .items textarea { width: 100% !important; min-height: 44px; font-size: 16px; }
  .items td.num input { text-align: left; }
  .totals { width: 100%; }

  /* follow-up board swipes column by column */
  .board { grid-template-columns: repeat(4, 86vw); scroll-snap-type: x mandatory; margin: 0 -14px; padding: 0 14px 6px; scrollbar-width: none; }
  .board::-webkit-scrollbar { display: none; }
  .col { scroll-snap-align: start; }

  /* detail pages */
  .kv { grid-template-columns: 104px 1fr; font-size: 14px; }
  .pl__row { grid-template-columns: 1fr auto; row-gap: 4px; }
  .pl__bar { grid-column: 1 / -1; order: 3; }
  .media { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .cat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cat-card .card__b { padding: 10px; }
  .cat-card b { font-size: 13.5px; }
  .map { height: 360px; }
  #bigmap { height: 420px !important; }
  .list li { flex-wrap: wrap; }
  .att span { min-width: 34px; height: 36px; }
  .login__card { width: 100%; min-height: 100svh; border-radius: 0; padding: calc(40px + env(safe-area-inset-top)) 24px 40px; align-content: center; }

  /* printable docs fit the phone screen */
  .doc { width: 100%; min-height: 0; padding: 18px 14px; font-size: 12px; overflow-x: auto; }
  .doc__head, .doc__sum, .doc__sign { flex-direction: column; gap: 14px; }
  .doc__title { text-align: left; }
  .doc__parties { grid-template-columns: 1fr; }
  .doc__sum table { width: 100%; }
  .doc-actions { position: sticky; top: calc(64px + env(safe-area-inset-top)); z-index: 5; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
@media print { .bnav { display: none !important; } }

/* ==========================================================================
   Dark theme
   ========================================================================== */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12100e;
  --card: #1b1815;
  --surface-2: #211d19;
  --hover: #25211c;
  --field: #15120f;
  --ink: #0b0a08;
  --text: #eee7dc;
  --text-2: #b8ae9f;
  --text-3: #8f8678;
  --line: #322c25;
  --line-2: #29241e;
  --line-strong: #4a4238;
  --gold: #c9922f;
  --gold-soft: #3a2e1a;
  --gold-hover: #e0b56a;
  --focus: #e0b56a;
  /* chart series re-stepped for the dark surface (validated with the dataviz validator, surface #1c1916) */
  --s1: #b98424; --s2: #1aa899; --s3: #d9663f; --s4: #6f8fe6; --s5: #7f9d2c; --s6: #c46aad;
  --good: #6fd49a; --good-bg: #173222;
  --warn: #f0c26a; --warn-bg: #3a2e12;
  --bad: #ff8f85; --bad-bg: #3f1b18;
  --info: #9ab6ff; --info-bg: #1c2742;
  --muted-bg: #2a251f;
  --glass: rgba(27,24,21,.94);
  --glass-top: rgba(18,16,14,.86);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -14px rgba(0,0,0,.7);
}
html[data-theme="dark"] .btn--primary { background: #efe8dd; color: #16130f; border-color: #efe8dd; }
html[data-theme="dark"] .btn--primary:hover { background: #fff; border-color: #fff; color: #16130f; }
html[data-theme="dark"] .btn--gold { color: #16130f; }
html[data-theme="dark"] .btn:hover { border-color: var(--line-strong); }
html[data-theme="dark"] .badge { background: #d6453a; }
html[data-theme="dark"] .toast { background: #efe8dd; color: #16130f; }
html[data-theme="dark"] .toast .i { color: var(--gold); }
html[data-theme="dark"] .toast--error { background: #d6453a; color: #fff; }
html[data-theme="dark"] .toast--error .i { color: #fff; }
html[data-theme="dark"] .modal { background: rgba(0,0,0,.6); }
html[data-theme="dark"] .login__card { border: 1px solid var(--line); }
html[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }
html[data-theme="dark"] .leaflet-popup-content-wrapper, html[data-theme="dark"] .leaflet-popup-tip { background: var(--card); color: var(--text); }
html[data-theme="dark"] .leaflet-bar a { background: var(--card); color: var(--text); border-color: var(--line); }
html[data-theme="dark"] .fld select, html[data-theme="dark"] .sel { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23b8ae9f' stroke-width='1.5'/%3E%3C/svg%3E"); }
html[data-theme="dark"] .doc { color-scheme: light; }
html[data-theme="dark"] .bnav .is-active { color: var(--gold-hover); }
.theme-btn .i-sun, html[data-theme="dark"] .theme-btn .i-moon { display: none; }
html[data-theme="dark"] .theme-btn .i-sun { display: block; }
.login .theme-btn { position: fixed; top: calc(16px + env(safe-area-inset-top)); right: 16px; z-index: 5; background: var(--card); border: 1px solid var(--line); }
html[data-theme="dark"] .seg button.is-on { background: var(--gold-soft); color: var(--gold-hover); }
html[data-theme="dark"] .tabs button.is-on { color: var(--text); }
.login__card { grid-template-columns: minmax(0, 1fr); }
.login__card .fld { grid-column: auto; }
