/* Minimal app styles - branding handled via DaisyUI + brand_config */

/*
 * Modal robustness. The board renders ~70 <dialog class="modal"> elements (one
 * per card/column). Those rely on DaisyUI's CDN CSS to (a) stay hidden when
 * closed and (b) give the panel a solid background. When that CDN styling loads
 * incompletely, every closed dialog leaks into the page as a transparent,
 * unreadable pile-up. These same-origin rules (always loaded, higher
 * specificity) restore the native-dialog behavior no matter what the CDN does.
 */
dialog.modal:not([open]) { display: none; }
dialog.modal[open] { display: grid; }
.modal-box { background-color: #ffffff; }

/*
 * Checkbox robustness — same story as the modal rules above. DaisyUI's .checkbox
 * sets `appearance: none` (which hides the browser's own checkmark) and then
 * paints its own tick from the CDN stylesheet. When that CDN styling doesn't
 * fully apply, a *checked* box looks identical to an unchecked one — so people
 * couldn't tell a selection had registered (reported on the Timesheets "Add
 * time" people picker: "it won't let me select the cleaner"). These same-origin,
 * higher-specificity rules draw the checked state ourselves, so a tick is always
 * visible no matter what the CDN does.
 */
input[type="checkbox"].checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  min-width: 1.25rem;
  flex-shrink: 0;
  border: 2px solid var(--brand-primary, #2563EB);
  border-radius: 0.35rem;
  background-color: #ffffff;
  cursor: pointer;
  position: relative;
  display: inline-block;
  vertical-align: middle;
  margin: 0;
}
input[type="checkbox"].checkbox.checkbox-sm {
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
}
input[type="checkbox"].checkbox:checked {
  background-color: var(--brand-primary, #2563EB);
  border-color: var(--brand-primary, #2563EB);
}
input[type="checkbox"].checkbox:checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.3rem;
  height: 0.6rem;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -60%) rotate(45deg);
}

/*
 * Sidebar nav colors. DaisyUI's bg-primary/text-primary *utility* classes are
 * not generated in this CDN setup (they compute to transparent), so the active
 * "you are here" pill is drawn here with the reliable --brand-primary variable.
 */
.sidebar-link { color: rgba(20, 35, 51, 0.72); }
.sidebar-link:hover { background-color: rgba(0, 113, 175, 0.10); color: #0071af; }
.sidebar-link.is-active,
.sidebar-link.is-active:hover { background-color: var(--brand-primary); color: #ffffff; font-weight: 600; }
.sidebar-link.is-active i { color: #ffffff; }

/*
 * Project Board — a persistent, grabbable horizontal scrollbar. The board is a
 * wide row of columns you scroll laterally. On macOS the native overflow
 * scrollbar stays hidden until you're already scrolling, so it felt like there
 * was "no bar to move along." Force it always-visible with a chunky, easy-to-
 * drag thumb. Higher-specificity `div.board-scroll` so it beats utility classes.
 */
div.board-scroll {
  overflow-x: scroll;
  overflow-y: hidden;
  scrollbar-width: auto;                       /* Firefox: normal-width bar */
  scrollbar-color: #94a3b8 rgba(100, 116, 139, 0.15);
}
div.board-scroll::-webkit-scrollbar {
  height: 14px;
}
div.board-scroll::-webkit-scrollbar-track {
  background: rgba(100, 116, 139, 0.15);
  border-radius: 999px;
  margin: 0 4px;
}
div.board-scroll::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
div.board-scroll::-webkit-scrollbar-thumb:hover {
  background: #64748b;
  background-clip: padding-box;
}

/*
 * Floating overlays must be opaque. Search dropdowns and menu pop-overs render
 * on top of other content, so a see-through background makes the text collide
 * with the fields behind it (reported: the client search list on the Schedule
 * Job form). They rely on daisyUI's `bg-base-100`, which resolves to
 * transparent whenever the CDN theme variables don't load — the same CDN
 * fragility handled for modals/checkboxes above. Force a solid background (and
 * dark text) so they always cover what's behind them, wherever they appear:
 *   - the client search lists (new + inline job forms)
 *   - the board card menu, the board column menu
 *   - the schedule "Assign" open-shift dropdown
 */
[data-client-search-target="list"],
.dropdown-content {
  background-color: #ffffff;
  color: #10222f;
}

/*
 * Messages screen — conversation list overflow (ROOT CAUSE).
 *
 * The two-pane layout (conversation list | thread + compose) looked like it was
 * collapsing, but the grid was never the problem. The conversation list is a
 * DaisyUI `.menu`, and DaisyUI v4 sets `.menu { display:flex; flex-flow: column
 * wrap }`. In a WRAPPING column flex container, items are NOT stretched to the
 * container's width — each <li> sizes to its own content (max-content). So a
 * conversation whose last message is long stretches its row to the full width
 * of that text (~900px), bursting out of the ~290px list column and sprawling
 * across the thread pane, on top of the "Pick a conversation…" text. Rows with
 * short messages don't trigger it — which is why it looked fine when there were
 * few/short conversations and broke once a long message arrived.
 *
 * Fix (same-origin, independent of whether the Tailwind CDN utilities load):
 *   - stop the menu wrapping, so rows stretch to the column width instead of
 *     growing to their content;
 *   - let each row and its content shrink (min-width:0) and clip the number +
 *     preview lines with an ellipsis, so long text can never widen the row.
 *
 * The grid + stretched-link rules below are kept as belt-and-suspenders for the
 * separate case where the CDN utilities are slow to generate on a Turbo nav.
 */
.messages-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 768px) {
  .messages-layout { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .messages-col-list { grid-column: span 1 / span 1; }
  .messages-col-thread { grid-column: span 2 / span 2; }
}

/* THE fix: a non-wrapping menu whose rows fill the column and clip long text. */
.messages-col-list .menu { flex-wrap: nowrap; width: 100%; align-items: stretch; }
.messages-row {
  position: relative;      /* positioning context for the stretched link below */
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  text-align: left;
}
.messages-row-content {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  /* Let clicks fall through to the stretched row link below, so tapping
     anywhere on the row opens the thread… */
  pointer-events: none;
}
.messages-row-content > * { min-width: 0; max-width: 100%; }
/* The number + message-preview lines truncate instead of forcing the row wide. */
.messages-row-content > span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* …except the client-name link, which stays clickable to reach their page. */
.messages-row-content a { pointer-events: auto; }
.messages-row-link { position: absolute; inset: 0; z-index: 0; }

/* ---- Messages: iMessage-style drill-in + new-message picker ---- */

/* Conversation-list column header (holds the "New message" button). */
.messages-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid hsl(var(--b3));
}

/* Selected / pressed / hovered conversation row: a light brand tint — never the
   dark navy block DaisyUI paints for `.active` / `:active` on a menu item. */
.messages-row-link:hover,
.messages-row-link:focus,
.messages-row-link:active,
.messages-row-link.active {
  background-color: #eaf3fb !important;
  color: inherit !important;
  box-shadow: none !important;
  border-radius: 10px;
}

/* Thread / new-message header: (mobile-only) back button + the title. */
.messages-thread-head { display: flex; align-items: center; gap: 10px; }
.messages-back {
  display: none;
  align-items: center;
  gap: 4px;
  color: var(--brand-primary, #0071af);
  font-weight: 600;
  white-space: nowrap;
}

/* New-message recipient typeahead dropdown. A plain list (deliberately NOT a
   DaisyUI .menu — that wraps and overflows, see the rules above) anchored under
   the To box, with a solid background so it covers the form behind it. */
.messages-recipient-list {
  position: absolute;
  left: 0; right: 0;
  z-index: 30;
  margin-top: 4px;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  color: #10222f;
  border: 1px solid hsl(var(--b3));
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(16, 40, 58, .12);
  padding: 4px;
  list-style: none;
}
.messages-recipient-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 0;
}
.messages-recipient-item:hover { background: #eaf3fb; }
.messages-recipient-item > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages-recipient-empty { padding: 10px 12px; font-size: 13px; opacity: .6; }

/* Fixed-height thread pane (iMessage-style). The card is sized to the screen,
   the message list scrolls INSIDE it (opening on the newest message), and the
   reply box sits pinned underneath — so you never scroll the whole page up to
   read and back down to reply. `vh` first as a fallback for older browsers;
   `dvh` tracks the phone's real visible height as its toolbars show/hide. */
.messages-thread-card {
  height: clamp(22rem, calc(100vh - 13rem), 56rem);
  height: clamp(22rem, calc(100dvh - 13rem), 56rem);
}
.messages-thread-card > .card-body { height: 100%; min-height: 0; }
.messages-thread-scroll {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Computer: the conversation list matches the thread's height and scrolls on
   its own, so a long list doesn't push the page (and reply box) down. */
@media (min-width: 768px) {
  .messages-col-list {
    height: clamp(22rem, calc(100vh - 13rem), 56rem);
    height: clamp(22rem, calc(100dvh - 13rem), 56rem);
  }
  .messages-list-body { height: 100%; min-height: 0; display: flex; flex-direction: column; }
  .messages-list-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; flex-wrap: nowrap; }
}

/* Responsive drill-in: on phones show ONE pane at a time — the conversation
   list, OR the open thread / new-message screen (with a back button). On
   tablets and up, keep the two-pane split visible at all times. */
@media (max-width: 767px) {
  .messages-layout[data-detail="closed"] .messages-col-thread { display: none; }
  .messages-layout[data-detail="open"]  .messages-col-list   { display: none; }
  .messages-layout[data-detail="open"]  .messages-col-thread { grid-column: 1 / -1; }
  .messages-back { display: inline-flex; }
  /* Open conversation on a phone: hide the tabs/title so the thread + reply box
     fill the screen (the back button is in the thread header). */
  .messages-page[data-detail="open"] .messages-page-head { display: none; }
  /* …and shrink the undelivered-text warning to its one-line heading + "Got it"
     (the failed text itself is flagged in red inside its own conversation). */
  .messages-page[data-detail="open"] .messages-failures-detail { display: none; }
  .messages-thread-card {
    height: max(20rem, calc(100vh - 9rem));
    height: max(20rem, calc(100dvh - 9rem));
  }
  /* Open conversation on a phone: use the whole screen under the app bar. The
     page's normal side padding (24px + 16px each side) squeezed a 390px-wide
     phone down to ~310px of conversation; drop it to a thin 8px edge and give
     the card the height that frees up (app bar 4rem + 2 x 8px). */
  main:has(.messages-page[data-detail="open"]) { padding: 8px; }
  .messages-page[data-detail="open"] { padding: 0; }
  .messages-page[data-detail="open"] .messages-thread-card {
    height: max(20rem, calc(100vh - 5rem));
    height: max(20rem, calc(100dvh - 5rem));
  }
  .messages-page[data-detail="open"] .messages-thread-card > .card-body {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }
  /* The Punch List's round orange button floats over the bottom-right corner
     of every page. Keep the reply row and quick replies clear of it so it never
     sits on top of Send. Only when the Punch List is actually on the page. */
  body:has(build-kit-root:not([hidden])) .messages-page[data-detail="open"] .messages-compose {
    padding-right: 64px;
  }
}

/* Keep the line breaks in a text (typed with Enter on a phone, or Shift+Enter
   on a computer) instead of running the lines together in the bubble. */
.messages-thread-scroll .chat-bubble { white-space: pre-line; overflow-wrap: anywhere; }

/* Pictures in a text: thumbnails above the words in the bubble, tap to enlarge.
   Fixed max size so a tall phone photo can't take over the conversation. */
.messages-media { display: flex; flex-wrap: wrap; gap: 4px; white-space: normal; margin: 2px 0; }
.messages-media-link { display: block; line-height: 0; }
.messages-media-thumb {
  display: block;
  max-width: min(14rem, 60vw);
  max-height: 14rem;
  border-radius: 0.5rem;
  object-fit: cover;
  background: hsl(var(--b2));
}
.messages-media-placeholder {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  opacity: 0.75;
  font-style: italic;
}
.messages-lightbox-img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  margin: 0 auto;
  border-radius: 0.5rem;
}
/* Pictures picked for the next text, shown above the reply box. */
.messages-attach-preview { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.messages-attach-preview.hidden { display: none; }
.messages-attach-thumb { width: 3rem; height: 3rem; object-fit: cover; border-radius: 0.375rem; }

/* Reply box: no drag handle (it grows by itself as you type, up to ~6 lines,
   then scrolls). */
.messages-reply-input {
  resize: none;
  max-height: 9.5rem;
  overflow-y: auto;
  line-height: 1.4;
}
