/*
Stanza Law law office management software
Copyright 2024 CanCan Systems, Inc.
*/

/*
Narrow widths: the CRM in Chrome's side panel, at whatever width it is dragged to.
Loaded after every other stylesheet. Screens set widths, floats and heights inline,
so the rules here use !important to override them.
At 1024px and wider only the targeted fixes in the first section apply, and each one acts
only where something overflows; everything else there stays as it was.
*/

/* ---------- Every width: targeted fixes for spots that overflow at desktop widths ---------- */

/* The case title box is width:100% plus a 1px margin each side: 2px past the work area, which
   then scrolled sideways on every case screen */
#case_header {
  margin-left: 0;
  margin-right: 0;
}
/* Pop-ups: content, fields and inline flex columns never outgrow the pop-up
   (case-search results at 110em, the contact pop-up's 23rem e-mail in a 30% column).
   Option lists keep their own width. */
:is(#pop-content, #pop-message-content, #pop-search-content, #pop-print-content) div[style*="width"]:not(.dropdown-select-content):not(.autocomplete-select-content),
:is(#pop-content, #pop-message-content, #pop-search-content, #pop-print-content) :is(input, select, textarea, .dropdown-select, .autocomplete-select) {
  max-width: 100%;
}
:is(#pop-content, #pop-message-content, #pop-search-content, #pop-print-content) [style*="display:flex"] > * {
  min-width: 0;
}
/* Header client search results (#pop-message-content only): header and rows are two tables with
   fixed em columns that sum to ~110em; share the width evenly so both fit and line up */
#pop-message-content [id="case-selection-menu-display"] :is(th, td) {
  width: auto !important;
}
/* The note's checklist block sits 20rem in; keep it inside the pop-up */
#note_checklist {
  max-width: calc(100% - 20rem);
}
/* Plaintiff address columns (an inline flex row): the mailing column ran past the window at
   1024px. Columns may shrink below their fields' width; fields shrink with them. */
#plaintiff-content [style*="display:flex"] > * {
  min-width: 0;
}
#plaintiff-content [style*="display:flex"] :is(input, select, .dropdown-select) {
  max-width: 100%;
}
/* a list's field also keeps room for its own side margins, so it ends with its wrapper and its
   chevron (common.css); at 640px and narrower those margins are zeroed */
@media (min-width: 640.02px) {
  #plaintiff-content [style*="display:flex"] .dropdown-select > input,
  :is(#pop-content, #pop-message-content, #pop-search-content, #pop-print-content) :is(.dropdown-select, .autocomplete-select) > input {
    max-width: calc(100% - .35rem);
  }
}
/* Plaintiff > Insurance: the panel's fixed height is shorter than its fields, which spilled
   under the row below; the height becomes a minimum */
#stanzalaw-workarea .content5[style*="height:35rem"] {
  min-height: fit-content;
}

/* ---------- Up to 1023px ---------- */

@media (max-width: 1023.98px) {

  /* Grid columns take the full width */
  #stanzalaw-workarea [class*="col-"] {
    width: 100% !important;
  }

  /* Fields and option-list wrappers shrink with their box instead of running past it */
  input, select, textarea, .dropdown-select, .autocomplete-select {
    max-width: 100%;
  }

  /* Rows of boxes laid out inline with display:flex wrap when they do not fit */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) [style*="display:flex"] {
    flex-wrap: wrap;
  }

  /* A box with an inline height grows when its content is taller (it used to spill under the
     next row, e.g. the desktop mail header). Scroll boxes keep their height. */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content)
    div:is([style^="height"], [style*=";height"], [style*="; height"]):not(.content3):not(.content4):not(.content7):not([style*="overflow"]) {
    min-height: fit-content;
  }

  /* Wide tables scroll inside their box, never the page */
  .content3, .content4, .content6, .content7 {
    overflow-x: auto !important;
  }

  /* Boxes with a fixed width in rem shrink to their container instead of running past it
     (Defendants: a 76rem row holding 35rem and 40rem columns, which then wrap). Option lists keep
     their own width, as everywhere else in this file. */
  #stanzalaw-workarea div[style*="width:"][style*="rem"]:not(.dropdown-select-content):not(.autocomplete-select-content) {
    max-width: 100%;
  }

  /* Row captions given a tiny fixed width (e.g. "General:" at 5%) */
  #stanzalaw-workarea div[style*="width:5%"] {
    width: auto !important;
    margin-right: .5rem;
  }
}

/* ---------- Header: two rows up to 767px ---------- */

@media (max-width: 767.98px) {

  :root {
    --header-height: 5.75rem;
  }

  #application-header {
    flex-wrap: wrap;
    align-content: center;
    row-gap: .375rem;
    padding: .375rem .5rem;
  }
  #header-company-logo, #header-company-name, #header-user {
    display: none;
  }
  #header-menu-content {
    flex: 1 1 100%;
    flex-wrap: wrap;
    row-gap: .375rem;
  }
  #header-search-case {
    flex: 1 1 100%;
    margin-right: 0;
  }
  #header-nav {
    flex: 1 1 100%;
    justify-content: space-between;
    gap: 0;
  }
  .header-nav-item {
    width: 1.875rem;
    height: 1.875rem;
  }
  #header-user-unread-messages {
    min-width: 0;
    font-size: .75rem;
  }
}

/* ---------- Side panel: 640px and narrower ---------- */

@media (max-width: 640px) {

  #stanzalaw-workarea {
    padding: .25rem;
  }

  /* Nothing floats beside anything (e.g. the mail body textarea is floated inline) */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) [style*="float"] {
    float: none !important;
  }
  /* Every box stacks at full width. Option lists and menus keep their own sizing. */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content)
    div:not(.dropdown-select-content):not(.autocomplete-select-content):not(.dropdown-menu-content):not(.dropdown-menu):not(.dropdown-select):not(.autocomplete-select):not([id$="-select_options"]) {
    float: none !important;
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) [class*="col-"] {
    width: 100% !important;
    padding: .25rem !important;
  }
  /* Fixed heights were sized for the wide layout; scroll boxes keep theirs */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content)
    div:not(.content3):not(.content4):not(.content7)[style*="height"] {
    height: auto !important;
  }
  /* Rows of boxes side by side (display:flex inline) wrap into a column */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) [style*="display:flex"] {
    flex-wrap: wrap !important;
  }
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) [style*="display:flex"] > * {
    flex: 1 1 100% !important;
    margin-left: 0 !important;
  }
  /* Left offsets from the wide layout (e.g. the note checklist block) */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content)
    :is(div, span)[style*="margin-left"] {
    margin-left: 0 !important;
  }
  #stanzalaw-workarea img, [id^="pop"] img {
    max-width: 100%;
    height: auto;
  }
  /* Contact form (the contact pop-up, and the Add form of a contact search): Prefix/Name/Last
     name/Suffix and Company sit in inline-block wrappers (shown and hidden by contacts.js) that
     would shrink to their content */
  :is(#pop-content, #pop-search-content) :is(#contact-person, #contact-non-person) {
    width: 100% !important;
  }
  #note_checklist {
    max-width: 100%;
    margin-top: .5rem !important; /* inline -2rem/-5rem pulled it over "Set checklist?" */
  }

  /* Desktop: checklist, then mail and recent cases */
  #desktop-content {
    flex-direction: column;
    height: auto;
  }
  #desktop-checklist-content, #desktop-todo-list-content {
    width: 100%;
  }

  /* Record lists beside a form move above it */
  .side-menu {
    float: none !important;
    width: 100% !important;
    height: auto !important;
    margin-right: 0;
  }

  /* Labels above their fields; fields fill the width */
  label {
    display: block !important;
    width: auto !important;
    min-width: 0;
    text-align: left !important;
    margin: .5rem .25rem .125rem !important;
  }
  /* A checkbox keeps its label on the same line */
  label:has(+ input[type="checkbox"], + input[type="radio"]),
  input[type="checkbox"] + label, input[type="radio"] + label {
    display: inline-block !important;
    margin-right: .375rem !important;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="image"]),
  select, textarea {
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .dropdown-select, .autocomplete-select {
    display: flex !important;
    align-items: center;
    width: 100%;
  }
  .dropdown-select > .select-input, .autocomplete-select > .autocomplete_input {
    flex: 1 1 auto;
    min-width: 0;
  }
  .dropdown-select-content, .autocomplete-select-content {
    max-width: calc(100vw - 1.5rem);
  }

  /* Tabs: one row that scrolls sideways. Sub-menus are fixed so the row's scroll box
     does not clip them. */
  #top-menu {
    display: flex !important;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin; /* visible, so the row can be dragged sideways with the mouse */
  }
  #top-menu > * {
    flex: none;
  }
  #top-menu .dropdown-menu-content {
    position: fixed;
    left: .5rem !important;
    right: .5rem;
    margin-left: 0;
  }

  /* Tables: each row wraps into a line of values; the header row stays (it holds the sort
     links). Cells keep their own display:none. */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) table,
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) tbody {
    display: block;
    width: 100% !important;
  }
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) tr {
    display: block;
    height: auto !important;
    padding: .375rem .25rem;
    white-space: normal !important; /* result rows carry .menu-option, which is nowrap */
    text-align: left;
  }
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) :is(td, th):not([style*="display:none"]) {
    display: inline-block;
    width: auto !important;
    max-width: 100%;
    height: auto !important;
    padding: 0 .5rem 0 0;
    text-align: left !important;
    white-space: normal;
  }
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) th {
    box-shadow: none;
  }
  /* A row with a Setup colour wraps into lines here: its bar runs down the whole row, and its text
     clears the bar (common.css draws the bar on the first cell at wider widths) */
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) tr[style*="--data-color"] {
    box-shadow: inset 4px 0 0 var(--data-color);
    padding-left: calc(4px + .375rem);
  }
  :is(#stanzalaw-workarea, #pop-content, #pop-message-content, #pop-search-content, #pop-print-content) tr[style*="--data-color"] > :first-child {
    box-shadow: none;
  }

  /* Pop-ups: a sheet across the window */
  #pop-content, #pop-message-content, #pop-search-content, #pop-print-content {
    left: .5rem !important;
    right: .5rem !important;
    top: .5rem !important;
    margin-left: 0 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: calc(100vh - 1rem);
    padding: .5rem;
  }
  .pop-selection-workarea, #pop-selection-workarea {
    width: auto !important;
    padding: 0 !important;
  }

  /* Case header summary (cases_case_top_menu_title.php): each label beside its value, two pairs
     per row, then the settlement amount and Stage on rows of their own. Only this
     read-only block keeps labels beside values (the sidebar-polish card's decision); stacked it was
     ~460px of fields above the tabs on every case screen. */
  #case_header {
    display: grid !important;
    grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
    align-items: center;
    gap: .125rem .375rem;
  }
  #case_header > #case_title {
    grid-column: 1 / -1;
    margin: .125rem 0 .25rem !important;
    font-size: .9375rem;
    line-height: 1.25;
  }
  /* the title's "Assigned to" / "** Read Only **" keep a 5rem right margin from their float, and
     the liability mark is 1.5rem: both made the title wrap or grow */
  #case_title > span {
    margin-right: 0 !important;
    margin-left: .5rem !important;
  }
  #case_header > #case_title > #case_liability_type_color {
    font-size: 1rem !important;
    margin-left: .375rem !important; /* outranks the 640px rule that zeroes inline left margins */
  }
  #case_header > span, #case_header > span > label {
    margin: 0 !important;
    white-space: nowrap;
    font-size: .8125rem;
    font-weight: var(--label-font-weight);
    color: var(--label-font-color);
  }
  #case_header input[type="text"] {
    font-size: .875rem;
    padding-left: .25rem !important;
    padding-right: .25rem !important;
    text-overflow: ellipsis; /* a long value at 320px ends in … instead of being cut */
  }
  /* the read-only values read as text, as in the chosen sketch: no field box, so each row is the
     height of a line. Stage (an editable list) keeps its box. */
  #case_header > input[readonly], #case_header > .dropdown-select > input[readonly], #case_header #settlement_amount_value {
    height: 1.25rem;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    text-align: left !important;
  }
  #case_header > :is(input, .dropdown-select) {
    width: 100% !important;
    min-width: 0;
    margin: 0 !important;
  }
  #case_header > input[type="checkbox"] {
    width: auto !important;
    justify-self: start;
  }
  #case_header > span:has(> label) {
    display: flex;
    align-items: center;
    gap: .375rem;
    min-width: 0;
    grid-column: span 2;
  }
  #case_header > span:has(> #case_stage_status_label) {
    grid-column: 1 / -1;
    order: 1;
  }
  /* the amount never shows cut short: it takes a whole row (label, the field at its own width, which
     holds 1,000,000.00, and the magnifier), so nothing wraps even at 320px */
  #case_header > #settlement_amount_display {
    grid-column: 1 / -1;
  }
  #case_header #settlement_amount_value {
    flex: 0 1 auto;
    width: auto !important;
    field-sizing: content; /* as wide as the amount, so the magnifier sits beside it */
    max-width: 100%;
  }
  #case_header > span > label {
    display: inline-block !important;
    flex: none;
    width: auto !important;
    margin: 0 !important;
  }
  #case_header > span > :is(input, .dropdown-select) {
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
  }
}
