/* Bergstreme snag portal — the internal grid at /manage.
 *
 * styles.css comes first and supplies the tokens, the header, the buttons and the form controls.
 * This file only does what a wide, editable table needs and the 560 px client form never did. */

/* The client form is a phone-width column. A grid is not. */
body.mg .wrap { max-width: 1600px; }
body.mg { padding-bottom: 96px; }
body.mg main { padding-top: 24px; padding-bottom: 24px; }
/* The account menu hugs the right edge of the wrap; the grid wrap is wider than the form. */
body.mg .menu { right: max(20px, calc((100% - 1600px) / 2 + 20px)); }


/* ---------- project picker ---------- */
.pcard {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--white);
  border: 1.5px solid var(--grey);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.pcard:hover { border-color: var(--navy); background: var(--pale); }
.ccard { justify-content: center; padding: 26px 20px; min-height: 120px; }
.ccard img { width: min(100%, 260px); height: auto; display: block; }
.pcard__name { font-weight: 600; color: var(--ink); }
.pcard__meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pcard__count {
  float: right;
  font-size: 12px;
  font-weight: 600;
  color: var(--navy);
  background: var(--pale);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  margin-left: 12px;
}

/* ---------- grid header ---------- */
.mg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.mg-head h1 { margin: 0; }
.mg-head__sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.mg-head__actions { display: flex; align-items: center; gap: 8px; }

.btn--sm { min-height: 36px; padding: 0 16px; font-size: 13px; }

.mg-cols { position: relative; }
.mg-cols > summary { list-style: none; }
.mg-cols > summary::-webkit-details-marker { display: none; }
.mg-cols__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  width: 300px;
  max-height: 420px;
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--grey);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}
/* The way back out of a list of fifty tick boxes stays in view while the list scrolls past it. */
.mg-cols__panel > .linkbtn {
  position: sticky;
  top: -10px;
  display: block;
  width: 100%;
  text-align: left;
  background: var(--white);
  padding: 6px 2px 8px;
  border-bottom: 1px solid var(--grey);
  margin-bottom: 4px;
  font-size: 13px;
}
.mg-cols__panel label {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 5px 2px;
  font-size: 13px;
  cursor: pointer;
}

.alert--warn { background: #FDF3E7; color: #8A4B00; }
.alert--warn .linkbtn { color: #8A4B00; }

/* ---------- the grid ---------- */
.mg-gridwrap {
  overflow: auto;
  max-height: calc(100vh - 300px);
  background: var(--white);
  border: 1px solid var(--grey);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}
.mg-grid {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  width: max-content;
  min-width: 100%;
}
.mg-grid th, .mg-grid td {
  border-bottom: 1px solid var(--grey);
  border-right: 1px solid var(--grey);
  padding: 0;
  vertical-align: top;
  text-align: left;
}
.mg-grid th:last-child, .mg-grid td:last-child { border-right: 0; }
.mg-grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--ink);
  color: var(--white);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 9px 10px;
  white-space: nowrap;
}
.mg-grid thead th .ro { color: #9FB2CB; font-weight: 400; }

/* The row's identity stays put while the rest scrolls sideways. */
.mg-grid th.sticky, .mg-grid td.sticky {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--white);
  border-right: 2px solid var(--grey);
}
.mg-grid thead th.sticky { z-index: 4; background: var(--ink); }

.mg-grid tbody tr:hover td { background: #FAFCFE; }
.mg-grid tbody tr:hover td.sticky { background: #FAFCFE; }
.mg-grid tbody tr.is-new td { background: #F3F9F4; }
.mg-grid tbody tr.is-new td.sticky { background: #F3F9F4; }
.mg-grid tbody tr.is-conflict td { background: #FDF3E7; }
.mg-grid tbody tr.is-conflict td.sticky { background: #FDF3E7; }

/* The client has looked at this repair and said no. Red rather than the conflict amber, because
 * it is not a race between two editors — it is work to redo, and it is the one thing on this grid
 * that came from outside Bergstreme. The bar on the left survives the horizontal scroll that
 * takes `Client Approval` itself off the screen, which is the point: a dispute has to be
 * noticeable without reading across sixty columns to find it. Conflict wins the background when a
 * row is both, since that one is about what is happening to your typing right now. */
.mg-grid tbody tr.is-disputed td { background: #FDF1F1; }
.mg-grid tbody tr.is-disputed td.sticky { background: #FDF1F1; box-shadow: inset 4px 0 0 #C0392B; }
.mg-grid tbody tr.is-disputed.is-conflict td { background: #FDF3E7; }
.mg-grid tbody tr.is-disputed.is-conflict td.sticky { background: #FDF3E7; box-shadow: inset 4px 0 0 #C0392B; }

.mg-grid td.ro { color: var(--muted); padding: 8px 10px; background: #FBFBFA; }
.mg-grid td.ro.sticky { background: #FBFBFA; }
.mg-grid td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* An edited cell is obvious at a glance and stays obvious until it is saved. */
.mg-grid td.is-dirty { box-shadow: inset 3px 0 0 var(--sky); background: #EFF7FC !important; }

/* ---------- editors ---------- */
.mg-grid .cell {
  width: 100%;
  min-width: 120px;
  min-height: 34px;
  border: 0;
  background: transparent;
  padding: 7px 10px;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 0;
  outline: none;
}
.mg-grid .cell:focus { box-shadow: inset 0 0 0 2px var(--navy); background: var(--white); }
.mg-grid textarea.cell { resize: vertical; min-width: 260px; min-height: 34px; }
.mg-grid select.cell { min-width: 150px; -webkit-appearance: none; appearance: none; cursor: pointer; }
.mg-grid .cell--check { display: flex; align-items: center; justify-content: center; min-height: 34px; }
.mg-grid .cell--check input { width: 17px; height: 17px; cursor: pointer; }
.mg-grid .cell--date { min-width: 130px; }

/* multi-picklist: a summary you can read, a panel you can tick.
 * A snag tagged with fifteen zones would otherwise make its column a screen wide, so the summary
 * is capped and clipped — the panel is where the full list lives. */
.ms { position: relative; min-width: 170px; max-width: 300px; }
.ms > summary {
  list-style: none;
  padding: 7px 10px;
  min-height: 34px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ms > summary::-webkit-details-marker { display: none; }
.ms > summary:hover { background: var(--pale); }
.ms__empty { color: #9A9A9A; }
.ms__panel {
  position: absolute;
  left: 0;
  top: calc(100% + 2px);
  z-index: 20;
  width: 240px;
  max-height: 260px;
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--grey);
  border-radius: var(--radius-input);
  box-shadow: var(--shadow);
  padding: 8px 10px;
}
.ms__panel label { display: flex; gap: 8px; align-items: center; padding: 4px 2px; cursor: pointer; }

/* big-picklist editor (Subbie, ~455 options): a filter-as-you-type box with a hand-rolled
 * suggestion panel — not `<input list>`, which mobile browsers largely decline to render at all.
 * See bigPicklistEditor() in manage.js. */
.ac { position: relative; min-width: 170px; }
.ac__panel {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 2px);
  z-index: 20;
  width: max(240px, 100%);
  max-height: 220px;
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--grey);
  border-radius: var(--radius-input);
  box-shadow: var(--shadow);
  padding: 4px;
}
.ac__panel.is-open { display: block; }
/* Flipped up when there is no room below — the normal case on a phone with the keyboard open. */
.ac--up .ac__panel { top: auto; bottom: calc(100% + 2px); }
.ac__opt { padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.ac__opt:hover { background: var(--pale); }
.ac__empty, .ac__more { padding: 7px 8px; font-size: 12px; color: var(--muted); }

/* Read-only text: shown in full on hover, clipped in the grid so one long formula result cannot
 * push every other column off the screen. */
.mg-img {
  display: block;
  padding: 8px 10px;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mg-link { color: var(--navy); font-size: 12px; padding: 8px 10px; display: inline-block; }
.mg-rowbtn {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 10px;
}

/* ---------- save bar ---------- */
.mg-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--grey);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 25;
}
.mg-bar__inner {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mg-bar__count { margin-left: auto; font-size: 13px; color: var(--muted); }
.mg-bar__count.is-dirty { color: var(--navy); font-weight: 600; }

@media (max-width: 720px) {
  .mg-head { align-items: flex-start; }
  .mg-gridwrap { max-height: calc(100vh - 340px); }
  .mg-bar__inner { padding: 0 14px; gap: 8px; }
  .mg-bar__count { font-size: 12px; }
}

/* A landscape phone is wide enough to dodge the 720px rule above (its short side moved to width)
 * but only ~340-420px tall — the fixed chrome around the grid (64px topbar, heading, save bar)
 * was sized against a portrait phone's headroom and eats most of that, leaving one row barely
 * visible (reported 2026-09-15). Keyed on height, not width, since height is what actually runs
 * out; a short *portrait* phone gets the same relief, which is never a loss. */
@media (max-height: 480px) {
  body.mg main { padding-top: 10px; padding-bottom: 10px; }
  .mg-head { margin-bottom: 8px; }
  .mg-head__sub { display: none; }
  .btn--sm { min-height: 32px; }
  .mg-gridwrap { max-height: calc(100vh - 190px); }
  .mg-bar { padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px)); }
}

/* ------------------------------------------------------------------ photos */
/* An image column is a picture, not a filename. The cell is a drop target, a viewer trigger and an
   upload indicator all at once, so it is sized to a thumbnail rather than to clipped text. */

.mg-grid td.mg-td-img { padding: 0; }

.mg-imgcell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 130px;
  min-height: 44px;
  padding: 5px 10px;
  cursor: pointer;
  outline: none;
}
.mg-imgcell:focus-visible { box-shadow: inset 0 0 0 2px var(--navy); }
.mg-imgcell.is-over { background: var(--pale); box-shadow: inset 0 0 0 2px var(--sky); }

.mg-thumb {
  flex: none;
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--light);
  border: 1px solid var(--grey);
  display: block;
}
.mg-imgcell__note {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mg-imgcell__replace {
  margin-left: auto;
  background: none;
  border: 0;
  padding: 2px 4px;
  font: inherit;
  font-size: 12px;
  color: var(--navy);
  text-decoration: underline;
  opacity: 0;
  cursor: pointer;
}
.mg-imgcell:hover .mg-imgcell__replace,
.mg-imgcell:focus-within .mg-imgcell__replace { opacity: 1; }

/* Empty: something that reads as "put one here" rather than as an empty cell. */
.mg-drop .mg-imgcell__note {
  border: 1px dashed var(--grey);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--muted);
}
.mg-drop:hover .mg-imgcell__note { border-color: var(--sky); color: var(--navy); background: var(--pale); }

.mg-imgcell.is-busy .mg-thumb { opacity: 0.55; }
.mg-imgcell.is-error .mg-imgcell__note { color: var(--danger); }

/* A save that is away but not yet confirmed. Deliberately quieter than .is-dirty — the point is
   "this is handled", not "this needs you". */
.mg-grid td.is-sending { box-shadow: inset 3px 0 0 var(--grey); background: #FAFAF9 !important; }
.mg-grid tr.is-new.is-sending td { opacity: 0.75; }
.mg-bar__count.is-sending { color: var(--muted); font-weight: 500; }

/* ---------------------------------------------------------------- the viewer */

.mg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40; /* above the toast (30) and the save bar (25) */
  background: rgba(18, 18, 18, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.mg-lightbox__body {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 12px;
  max-width: min(1100px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}
.mg-lightbox__img {
  max-width: 100%;
  max-height: calc(100vh - 160px);
  object-fit: contain;
  border-radius: 8px;
  background: var(--light);
}
.mg-lightbox__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.mg-lightbox__cap { font-size: 14px; color: var(--text); margin-right: auto; }
