/* Bakhaar Lite — modern, clean, mobile-first. */
:root {
  --brand: #0d9488;
  --brand-dark: #0f766e;
  --brand-soft: rgba(13, 148, 136, .1);
  --bg: #f2f6f5;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e4eae8;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .1);
  --ok: #047857;
  --ok-soft: rgba(4, 120, 87, .1);
  --th-bg: #e3f1ef;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .05), 0 6px 20px rgba(15, 23, 42, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1312;
    --card: #12201f;
    --ink: #e7f0ee;
    --muted: #8aa4a0;
    --line: #223c38;
    --brand-soft: rgba(13, 148, 136, .2);
    --danger-soft: rgba(248, 113, 113, .15);
    --ok: #34d399;
    --ok-soft: rgba(52, 211, 153, .12);
    --th-bg: #17302d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.45;
}

/* ---------- Brand ---------- */
.logo {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  font-size: 1.1rem;
  border-radius: 10px;
  background: linear-gradient(150deg, #14b8a6, var(--brand-dark));
  box-shadow: 0 2px 8px rgba(13, 148, 136, .4);
}
.logo.big { width: 64px; height: 64px; font-size: 2rem; border-radius: 18px; margin-bottom: .5rem; }
.brand { display: flex; align-items: center; gap: .55rem; }
.brand strong { font-size: 1.05rem; font-weight: 800; letter-spacing: -.01em; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(255,255,255,.18), transparent 60%),
    linear-gradient(160deg, #115e59, var(--brand) 55%, #2dd4bf);
}
.login-card {
  width: min(400px, 100%);
  text-align: center;
  padding: 2.25rem 1.6rem;
  border: none;
}
.login-card h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; }
.login-card p { color: var(--muted); margin-top: .15rem; }
.login-card input { text-align: center; font-size: 1.3rem; letter-spacing: .25em; }
.login-card button { width: 100%; font-size: 1.05rem; margin-top: .25rem; }

/* ---------- Base elements ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.pad { padding: 1.1rem; }
h1 { margin: 0 0 .25rem; color: var(--brand-dark); }
h3 { margin: 0 0 .5rem; font-weight: 700; }
@media (prefers-color-scheme: dark) { h1 { color: #2dd4bf; } }
label { display: flex; flex-direction: column; gap: .4rem; margin: 1rem 0; font-weight: 600; text-align: start; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  padding: .6rem .75rem;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input::placeholder { color: var(--muted); opacity: .8; }

button {
  font: inherit;
  font-weight: 600;
  padding: .6rem 1.05rem;
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #14b8a6, var(--brand-dark));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(13, 148, 136, .35);
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .6; cursor: wait; }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
  box-shadow: none;
}
button.ghost:hover { border-color: var(--brand); color: var(--brand); filter: none; }
button.small { padding: .2rem .55rem; min-height: 32px; font-size: .85rem; border-radius: 8px; }

.error { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); font-size: .9rem; }
.push-end { margin-left: auto; }
.empty { display: grid; place-items: center; min-height: 140px; color: var(--muted); }
.empty-row { text-align: center; padding: 1.25rem !important; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: .15rem .6rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.good { background: var(--ok-soft); color: var(--ok); }

/* ---------- Page link between the two pages ---------- */
.pagetitle { font-weight: 700; color: var(--brand-dark); }
@media (prefers-color-scheme: dark) { .pagetitle { color: #2dd4bf; } }
.navlink {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .95rem;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  transition: border-color .15s;
}
.navlink:hover { border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .navlink { color: #2dd4bf; } }
@media (max-width: 640px) {
  .pagetitle { display: none; }
  .navlink { font-size: .85rem; padding: .4rem .7rem; }
}

/* ---------- Header / navigation ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: .9rem;
  align-items: center;
  padding: .6rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
nav { display: flex; gap: .3rem; }
nav button {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: .45rem .95rem;
  box-shadow: none;
}
nav button .ico { font-size: 1.05rem; }
nav button:hover { color: var(--brand); filter: none; }
nav button.active { background: var(--brand-soft); color: var(--brand-dark); }
@media (prefers-color-scheme: dark) { nav button.active { color: #2dd4bf; } }

/* Mobile: nav becomes a fixed bottom tab bar */
@media (max-width: 640px) {
  .brand strong { display: none; }
  nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
    justify-content: space-around;
    box-shadow: 0 -2px 14px rgba(15, 23, 42, .1);
  }
  nav button { flex-direction: column; gap: .1rem; font-size: .72rem; padding: .3rem .8rem; min-height: auto; }
  nav button .ico { font-size: 1.35rem; }
  body { padding-bottom: 78px; }
}

/* ---------- Layout ---------- */
.panel { padding: 1rem; max-width: 1100px; margin: 0 auto; display: grid; gap: 1rem; animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.row-form input, .row-form select { flex: 1 1 150px; }
.search { width: 100%; margin-bottom: .85rem; }
.split { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .85rem; }

/* ---------- Flash toast ---------- */
.flash {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  margin: 0;
  padding: .55rem 1.15rem;
  background: var(--ok);
  color: #fff;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: var(--shadow);
  animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } }

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
}
.card table { box-shadow: none; border: 1px solid var(--line); }
th, td { padding: .65rem .75rem; text-align: start; border-bottom: 1px solid var(--line); }
th {
  background: var(--th-bg);
  color: var(--brand-dark);
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
@media (prefers-color-scheme: dark) { th { color: #2dd4bf; } }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: end; font-variant-numeric: tabular-nums; }
.actions { white-space: nowrap; width: 1%; }
.click { cursor: pointer; }
.click:hover { background: var(--brand-soft); }
tr.active { background: var(--brand-soft); }
tfoot .totals td {
  background: var(--brand-soft);
  border-top: 2px solid var(--brand);
  font-variant-numeric: tabular-nums;
}

/* Tables scroll sideways on small screens instead of squeezing */
@media (max-width: 640px) {
  .panel table:not(.grid) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .grid { min-width: 560px; } /* the sheet scrolls inside .sheet-scroll instead */
}

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.kpis div {
  background:
    radial-gradient(220px 120px at 100% 0%, rgba(255,255,255,.14), transparent 60%),
    linear-gradient(160deg, #115e59, var(--brand));
  color: #fff;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpis span { display: block; font-size: .8rem; opacity: .9; margin-bottom: .2rem; }
.kpis strong { font-size: 1.55rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ---------- Sheets ---------- */
.sheet-list { list-style: none; margin: 0; padding: 0; }
.sheet-list button {
  width: 100%;
  text-align: start;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  margin-bottom: .45rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.sheet-list button:hover { border-color: var(--brand); filter: none; }
.sheet-list button.active { background: var(--brand-soft); border-color: var(--brand); }
.sheet-list small { color: var(--muted); }

/* ---------- Excel-style grid ---------- */
:root { --cell-bg: #ffffff; --grid-line: #d7e0de; --hl-bg: #cde9e5; }
@media (prefers-color-scheme: dark) {
  :root { --cell-bg: #0f1b1a; --grid-line: #28453f; --hl-bg: #1d4a44; }
}
.sheet-scroll { max-height: 65vh; overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--grid-line); background: var(--cell-bg); }
.sheet-scroll table { border: none; border-radius: 0; background: var(--cell-bg); }
.sheet-scroll th, .sheet-scroll td { border: 1px solid var(--grid-line); }

/* Frozen header rows */
.sheet-scroll thead tr.letters th { position: sticky; top: 0; z-index: 5; }
.sheet-scroll thead tr:not(.letters) th { position: sticky; top: 29px; z-index: 5; }
.sheet-scroll thead th {
  background: var(--th-bg);
  text-transform: none;
  font-size: .8rem;
  letter-spacing: 0;
}
.sheet-scroll thead tr.letters th {
  height: 28px;
  padding: .15rem .5rem;
  text-align: center;
  font-weight: 700;
  font-size: .72rem;
  color: var(--muted);
}

/* Modern slim scrollbars for the grid */
.sheet-scroll { scrollbar-width: thin; scrollbar-color: var(--grid-line) transparent; scroll-behavior: auto; }
.sheet-scroll::-webkit-scrollbar { width: 12px; height: 12px; }
.sheet-scroll::-webkit-scrollbar-track { background: transparent; }
.sheet-scroll::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  border: 3px solid var(--cell-bg);
  border-radius: 8px;
}
.sheet-scroll::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--brand) 70%, transparent); }
.sheet-scroll::-webkit-scrollbar-corner { background: var(--cell-bg); }

/* Freeze-pane depth: the frozen header and first columns float above the cells */
.sheet-scroll thead tr:not(.letters) th { box-shadow: 0 2px 5px -3px rgba(15, 23, 42, .45); }
.grid .datecol { box-shadow: 3px 0 5px -3px rgba(15, 23, 42, .3); }

/* Frozen row-number and Date columns */
.grid .rownum {
  position: sticky; left: 0; z-index: 3;
  width: 44px; min-width: 44px; max-width: 44px;
  background: var(--th-bg);
  color: var(--muted);
  text-align: center;
  font-size: .78rem;
  font-weight: 600;
  padding: .45rem .3rem;
}
.grid .datecol { position: sticky; left: 44px; z-index: 3; background: var(--cell-bg); min-width: 128px; }
.sheet-scroll thead .rownum, .sheet-scroll thead .datecol { z-index: 6; background: var(--th-bg); }
tfoot .totals .rownum, tfoot .totals .datecol { z-index: 4; }

/* Active cell + highlighted headers (like Excel) */
.sheet-scroll:focus { outline: none; }
.grid td.cell { cursor: cell; white-space: nowrap; user-select: none; }
.grid td.sel {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--cell-bg) 88%, var(--brand)) !important;
}
.grid td.editing { padding: 0 !important; outline: 2px solid var(--brand); outline-offset: -2px; }
.cell-input {
  width: 100%;
  min-height: 28px;
  border: none;
  border-radius: 0;
  background: var(--cell-bg);
  padding: .2rem .5rem;
  font-size: .88rem;
}
.cell-input:focus { outline: none; box-shadow: none; }
.grid td.cell-active { outline: 2px solid var(--brand); outline-offset: -2px; }
.grid .hl { background: var(--hl-bg) !important; color: var(--brand-dark); }
@media (prefers-color-scheme: dark) { .grid .hl { color: #2dd4bf; } }

.col-tools { white-space: nowrap; margin-left: .25rem; }
.colbtn {
  background: transparent; border: none; color: var(--muted); box-shadow: none;
  min-height: auto; padding: 0 .15rem; font-size: .85rem; border-radius: 4px;
}
.colbtn:hover { color: var(--brand); filter: none; }
.save-ok { color: var(--ok); font-size: .9rem; font-weight: 600; }

.grid input {
  width: 100%;
  min-height: 38px;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: .4rem .55rem;
  font-size: .92rem;
}
.grid input:focus { box-shadow: none; outline: none; }
.grid td { padding: .4rem .55rem; background: var(--cell-bg); font-size: .92rem; }
.grid td:has(input) { padding: 0; }
.grid tbody tr:hover td { background: color-mix(in srgb, var(--cell-bg) 92%, var(--brand)); }
.grid tbody tr:hover td.rownum { background: var(--hl-bg); }
.grid .delcol { width: 36px; min-width: 36px; background: var(--cell-bg); text-align: center; }
.rowdel {
  background: transparent; border: none; box-shadow: none; color: var(--muted);
  min-height: auto; padding: .1rem .3rem; font-size: .9rem;
}
.rowdel:hover { color: var(--danger); filter: none; }
tfoot .totals td { background: var(--th-bg); border-top: 2px solid var(--brand); }

/* ---------- Sheets view: fits the screen, grid takes the leftover space ---------- */
#tab-raf {
  --botnav: 0px;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  height: calc(100dvh - var(--hdr, 58px) - var(--botnav));
  max-width: 1500px;
  padding: .6rem .8rem .5rem;
  overflow: hidden;
}
@media (max-width: 640px) { #tab-raf { --botnav: 78px; } }
#tab-raf > .gs-card { flex: 0 0 auto; padding: .55rem .7rem; }
#tab-raf .gs-results { max-height: 40vh; overflow: auto; }

/* Must out-specify `.card.pad` so the grid — not the card — takes the leftover height. */
#tab-raf > #sheet-detail.card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: .6rem .7rem;
  margin-bottom: 0;
}
#sheet-detail.empty { display: grid; }
#sheet-table { flex: 1 1 auto; min-height: 0; display: flex; }
#tab-raf .sheet-scroll { flex: 1 1 auto; min-height: 0; max-height: none; }

/* Compact one-line toolbar above the grid */
.sheet-toolbar {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.sheet-title { font-size: .95rem; white-space: nowrap; }
.tb-sep { flex: 1 1 auto; }
.inline-form { display: flex; gap: .3rem; align-items: center; }
.mini {
  min-height: 32px;
  padding: .25rem .7rem;
  font-size: .84rem;
  border-radius: 8px;
}
.mini-input, .mini-search {
  min-height: 32px;
  padding: .25rem .55rem;
  font-size: .85rem;
  border-radius: 8px;
}
.mini-search { flex: 1 1 180px; max-width: 320px; }
.mini-input { width: 118px; }

/* Denser cells on desktop so more rows are visible at once */
@media (min-width: 800px) {
  .grid input { min-height: 30px; padding: .22rem .5rem; font-size: .88rem; }
  .grid td, .grid th { padding: .22rem .5rem; font-size: .88rem; }
  .grid .rownum { padding: .22rem .3rem; }
  .sheet-scroll thead tr.letters th { height: 22px; }
  .sheet-scroll thead tr:not(.letters) th { top: 22px; }
}

/* Excel-style bottom sheet tabs */
.sheet-tabs {
  display: flex;
  align-items: stretch;
  gap: .3rem;
  padding: 0 .4rem .35rem;
  background: var(--th-bg);
  border: 1px solid var(--grid-line);
  border-top: 3px solid var(--brand);
  border-radius: 0 0 10px 10px;
  flex: 0 0 auto;
  margin-top: -.5rem; /* sit flush under the sheet card */
}
.stab {
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: .35rem .9rem;
  min-height: 34px;
  font-size: .85rem;
  font-weight: 600;
  box-shadow: none;
  white-space: nowrap;
}
.stab:hover { color: var(--brand-dark); background: var(--brand-soft); filter: none; }
.stab.active {
  background: var(--cell-bg);
  color: var(--brand-dark);
  border-color: var(--grid-line);
  font-weight: 700;
}
@media (prefers-color-scheme: dark) { .stab.active, .stab:hover { color: #2dd4bf; } }
.stab.add { font-size: 1.1rem; font-weight: 700; padding: .35rem .7rem; color: var(--brand); }
.tab-nav { display: flex; align-items: center; gap: 1px; flex: 0 0 auto; }
.tabarrow {
  background: transparent;
  color: var(--muted);
  border: none;
  box-shadow: none;
  min-height: 30px;
  padding: .2rem .35rem;
  font-size: .7rem;
  border-radius: 6px;
}
.tabarrow:hover { color: var(--brand); background: var(--brand-soft); filter: none; }
.sheet-tabs { position: relative; }
.sheet-menu {
  position: absolute;
  left: .4rem;
  bottom: calc(100% + .3rem);
  z-index: 40;
  min-width: 230px;
  max-height: 60vh;
  overflow: auto;
  padding: .3rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, .22);
}
.sm-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  min-height: 32px;
  padding: .3rem .55rem;
  border-radius: 7px;
  font-weight: 500;
  font-size: .87rem;
  text-align: start;
}
.sm-item:hover { background: var(--brand-soft); filter: none; }
.sm-item.active { background: var(--brand-soft); font-weight: 700; }
.sm-empty { display: block; padding: .4rem .55rem; }

.tab-strip {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  flex: 1 1 auto;
  min-width: 0;
}

/* ---------- Workbook file bar ---------- */
.gs-card { position: relative; }
.filebar {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--line);
}
.wb-pick {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--brand-soft);
  color: var(--brand-dark);
  box-shadow: none;
  min-height: 34px;
  padding: .25rem .7rem;
  border-radius: 9px;
  font-weight: 700;
  max-width: 46vw;
}
.wb-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wb-pick .wb-ico, .wb-pick .caret { overflow: visible; }
.wb-pick:hover { filter: none; background: color-mix(in srgb, var(--brand-soft) 70%, var(--brand)); }
@media (prefers-color-scheme: dark) { .wb-pick { color: #2dd4bf; } }
.caret { font-size: .7rem; opacity: .7; }
.saved-note { font-size: .8rem; color: var(--ok); font-weight: 600; white-space: nowrap; }
.saved-note.busy { color: var(--muted); }
.wb-menu {
  position: absolute;
  left: .8rem;
  top: 3.1rem;
  z-index: 45;
  min-width: 250px;
  max-height: 55vh;
  overflow: auto;
  padding: .3rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
}
.sm-sep { height: 1px; background: var(--line); margin: .25rem .3rem; }

/* ---------- Signed-in user + users manager ---------- */
.who {
  font-size: .85rem;
  font-weight: 600;
  color: var(--brand-dark);
  background: var(--brand-soft);
  padding: .3rem .7rem;
  border-radius: 999px;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .who { color: #2dd4bf; } }
@media (max-width: 640px) { .who { display: none; } }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, .45);
}
.modal-card {
  width: min(640px, 100%);
  max-height: 85vh;
  overflow: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(15, 23, 42, .3);
  padding: 1rem 1.1rem 1.2rem;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .8rem;
}
.hist-who { font-size: .8rem; color: var(--brand-dark); white-space: nowrap; }
@media (prefers-color-scheme: dark) { .hist-who { color: #2dd4bf; } }

/* ---------- History panel ---------- */
.history-panel {
  flex: 0 0 auto;
  max-height: 45vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .5rem .75rem;
  background: var(--th-bg);
  border-bottom: 1px solid var(--line);
}
.hist-list { overflow: auto; padding: .25rem .35rem .4rem; }
.hist-row {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto auto auto;
  gap: .5rem;
  align-items: baseline;
  padding: .28rem .4rem;
  border-radius: 7px;
  font-size: .86rem;
}
.hist-row:nth-child(odd) { background: color-mix(in srgb, var(--th-bg) 45%, transparent); }
.hist-detail { overflow-wrap: anywhere; }
.hist-sheet { font-size: .8rem; white-space: nowrap; }
.hist-time { font-size: .78rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .hist-row { grid-template-columns: 1.2rem 1fr; }
  .hist-who, .hist-sheet, .hist-time { grid-column: 2; }
}

/* Global search results */
.gsbar { margin-bottom: 0; }
.gsbar .search { margin-bottom: 0; flex: 1 1 260px; }
.gs-results { margin-top: .65rem; display: grid; gap: .5rem; }
.gs-group {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.gs-sheet {
  display: block;
  width: 100%;
  text-align: start;
  background: var(--th-bg);
  color: var(--ink);
  border-radius: 0;
  box-shadow: none;
  min-height: 38px;
  padding: .4rem .7rem;
}
.gs-sheet:hover { filter: none; background: var(--brand-soft); }
.gs-row {
  display: block;
  width: 100%;
  text-align: start;
  background: var(--card);
  color: var(--ink);
  font-weight: 400;
  font-size: .88rem;
  border: none;
  border-top: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  min-height: 34px;
  padding: .35rem .7rem;
}
.gs-row:hover { background: var(--brand-soft); filter: none; }
.gs-more { display: block; padding: .25rem .7rem .4rem; }

/* Status bar under the grid, like Excel's */
.sheet-status {
  flex: 0 0 auto;
  padding: .28rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--th-bg);
  color: var(--muted);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.sheet-status { display: flex; align-items: center; gap: .5rem; }
.namebox {
  flex: 0 0 auto;
  min-width: 52px;
  text-align: center;
  padding: .05rem .4rem;
  border: 1px solid var(--grid-line);
  border-radius: 5px;
  background: var(--cell-bg);
  color: var(--brand-dark);
  font-weight: 700;
}
@media (prefers-color-scheme: dark) { .namebox { color: #2dd4bf; } }
.sheet-status strong { color: var(--brand-dark); }
@media (prefers-color-scheme: dark) { .sheet-status strong { color: #2dd4bf; } }
