/* Demo-only inventory and marketing layout refinement.
   Keep all original actions, values, labels and event targets intact. */
@media screen {
  /* The title and its tools form two deliberate rows instead of competing
     for a shrinking strip at desktop zoom and tablet widths. */
  body.app-shell .inv-head .inv-tools,
  body.app-shell[data-nav="ads"] .page-head > .page-actions {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    margin-left: 0;
    justify-content: flex-start;
    align-items: stretch;
    gap: 8px;
  }
  body.app-shell .inv-tools > .btn,
  body.app-shell[data-nav="ads"] .page-head > .page-actions > .btn {
    flex: 0 1 auto;
    max-width: 100%;
    min-width: 0;
    min-height: 44px;
    height: auto;
    padding: 10px 14px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.4;
    text-align: center;
  }
  body.app-shell :is(.inv-tools,.page-actions,.mn-head .act) .btn > .ico {
    flex: 0 0 17px;
  }
  body.app-shell .inv-head > h1,
  body.app-shell[data-nav="inventory"] .page-head > h1 {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  body.app-shell[data-nav="inventory"] .page-head:has(.head-thumb) > h1 {
    flex: 1 1 240px;
  }
  body.app-shell[data-nav="inventory"] .page-head:has(.head-thumb) > .page-actions {
    flex: 1 1 100%;
    min-width: 0;
    margin-left: 0;
    justify-content: flex-start;
  }
  body.app-shell[data-nav="inventory"] .page-head:has(.head-thumb) .btn {
    max-width: 100%;
    white-space: normal;
    height: auto;
    min-height: 44px;
    text-align: center;
  }

  /* A real minimum card width protects complete money values. The tax
     qualifier may use its own line; no amount is clipped or abbreviated. */
  body.app-shell[data-nav="inventory"] .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 14px;
    align-items: stretch;
  }
  body.app-shell[data-nav="inventory"] .kpi {
    min-width: 0;
    max-width: 100%;
    padding: 17px;
  }
  body.app-shell[data-nav="inventory"] .kpi .l {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.4;
    margin-bottom: 7px;
  }
  body.app-shell[data-nav="inventory"] .kpi .v {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 5px;
    row-gap: 4px;
    max-width: 100%;
    white-space: nowrap;
    line-height: 1.25;
  }
  body.app-shell[data-nav="inventory"] .kpi.lead .v {
    font-size: clamp(28px, 2.7vw, 36px);
  }
  body.app-shell[data-nav="inventory"] .kpi .v .tax {
    margin-left: 0;
    font-size: 13px;
    line-height: 1.4;
  }
  body.app-shell[data-nav="inventory"] .kpi > .caption,
  body.app-shell[data-nav="inventory"] .kpi > .caption.kpi-fee {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
    margin-top: 6px;
  }

  /* Notes actions wrap as a group, so a full label stays inside the card. */
  body.app-shell .mgr-notes .mn-head {
    align-items: center;
    min-width: 0;
    gap: 10px 16px;
  }
  body.app-shell .mgr-notes .mn-head > h2 {
    flex: 1 1 180px;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  body.app-shell .mgr-notes .mn-head > .act {
    display: flex;
    flex: 0 1 auto;
    flex-wrap: wrap;
    min-width: 0;
    max-width: 100%;
    gap: 8px;
  }
  body.app-shell .mgr-notes .mn-head .act :is(.btn,form) {
    min-width: 0;
    max-width: 100%;
  }
  body.app-shell .mgr-notes .mn-head .act .btn {
    white-space: normal;
    height: auto;
    min-height: 44px;
    text-align: center;
    overflow-wrap: anywhere;
  }
  body.app-shell .quote-row {
    gap: 8px 12px;
    align-items: center;
  }
  body.app-shell .quote-row > :not(button) {
    min-width: 0;
    flex: 1 1 230px;
    overflow-wrap: anywhere;
  }

  /* Status labels remain readable at their actual content width; two
     columns are used before four cramped controls would truncate text. */
  body.app-shell[data-nav="ads"] .mseg {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    gap: 4px;
  }
  body.app-shell[data-nav="ads"] .mseg a {
    min-width: 0;
    min-height: 44px;
    height: auto;
    padding: 10px 12px;
    gap: 7px;
    line-height: 1.35;
  }
  body.app-shell[data-nav="ads"] .mseg .lbl {
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
    overflow-wrap: anywhere;
    margin: 0;
  }
  body.app-shell[data-nav="ads"] .mseg .cnt {
    flex: 0 0 auto;
  }
  body.app-shell[data-nav="ads"] .whopost .whosum {
    min-width: 0;
    flex: 1 1 250px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  body.app-shell[data-nav="ads"] .whogrid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  }
  body.app-shell :is(.inv-search,.qsearch) {
    min-width: 0;
    max-width: 100%;
    align-items: stretch;
  }
  body.app-shell :is(.inv-search,.qsearch) > input:not([type="hidden"]) {
    min-width: 0;
    width: 0;
    flex: 1 1 120px;
  }
  body.app-shell :is(.inv-search,.qsearch) > .btn {
    min-height: 44px;
    height: auto;
    line-height: 1.4;
  }
  body.app-shell[data-nav="inventory"] :is(.inv-act,.veh-sub-line) {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
  }
  body.app-shell[data-nav="inventory"] .inv-sort {
    min-width: 0;
    max-width: 100%;
  }
  body.app-shell[data-nav="inventory"] .inv-sort select {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
  }
}

@media screen and (max-width: 1100px) {
  body.app-shell[data-nav="ads"] .mseg {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media screen and (max-width: 840px) {
  /* Put the longest, task-oriented search action first, then pair the two
     shorter tools. This preserves all original handlers and DOM order. */
  body.app-shell .inv-head .inv-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body.app-shell .inv-tools > .btn {
    width: 100%;
    padding: 10px 12px;
  }
  body.app-shell .inv-tools > a[href*="/find"] {
    grid-column: 1 / -1;
    order: -1;
  }
  body.app-shell[data-nav="inventory"] .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  body.app-shell[data-nav="inventory"] .kpi-grid > .kpi.lead {
    grid-column: 1 / -1;
  }
  body.app-shell[data-nav="inventory"] .kpi {
    padding: 15px;
  }
  body.app-shell[data-nav="inventory"] .kpi.lead .v {
    font-size: 34px;
  }
  body.app-shell[data-nav="inventory"] .kpi:not(.lead) .v {
    font-size: 22px;
  }
  body.app-shell .mgr-notes .mn-head > .act {
    flex: 1 1 100%;
    margin-left: 0;
  }
  body.app-shell .mgr-notes .mn-head .act .btn {
    justify-content: flex-start;
    text-align: left;
  }
  body.app-shell[data-nav="ads"] .page-head > .page-actions > .btn {
    flex: 1 1 130px;
  }
  body.app-shell[data-nav="ads"] #ads-ext {
    flex-basis: 100%;
  }
  body.app-shell[data-nav="ads"] .mseg a {
    padding: 10px 8px;
  }
}

@media screen and (max-width: 380px) {
  body.app-shell[data-nav="inventory"] .kpi:not(.lead) {
    grid-column: 1 / -1;
  }
  body.app-shell[data-nav="inventory"] .kpi.lead .v {
    font-size: 32px;
  }
  body.app-shell[data-nav="inventory"] .page-head:has(.head-thumb) > h1 {
    flex-basis: 160px;
  }
}

/* Marketing: everyday work stays visible; occasional setup sits in quiet Tools. */
@media screen {
  body.app-shell[data-nav="ads"] .page-actions:has(.df-marketing-tools) {
    align-items: center;
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools {
    position: relative;
    flex: 0 0 auto;
    min-width: 0;
    margin-left: auto;
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--ink-2);
    list-style: none;
    cursor: pointer;
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools-toggle::-webkit-details-marker {
    display: none;
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools-toggle::after {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    flex: 0 0 auto;
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools[open] > summary::after {
    transform: translateY(2px) rotate(225deg);
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools[open] > summary {
    background: var(--surface-3);
    border-color: var(--line);
    color: var(--ink);
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools-panel {
    position: absolute;
    z-index: 40;
    top: calc(100% + 8px);
    right: 0;
    width: max-content;
    max-width: min(320px, calc(100vw - 48px));
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-2);
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools-panel #ads-ext {
    display: flex;
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 10px 12px;
    border-color: transparent;
    box-shadow: none;
    background: transparent;
    white-space: normal;
    line-height: 1.5;
    text-align: left;
    justify-content: flex-start;
    color: var(--ink-2);
  }
}
@media screen and (max-width: 640px) {
  body.app-shell[data-nav="ads"] .page-actions:has(.df-marketing-tools) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    align-items: stretch;
  }
  body.app-shell[data-nav="ads"] .page-actions:has(.df-marketing-tools) > .btn {
    width: 100%;
    height: 100%;
  }
  body.app-shell[data-nav="ads"] .df-marketing-tools {
    align-self: center;
    justify-self: end;
    margin-left: 0;
  }
}
@media (hover: hover) and (pointer: fine) {
  body.app-shell[data-nav="ads"] .df-marketing-tools-toggle:hover,
  body.app-shell[data-nav="ads"] .df-marketing-tools-panel #ads-ext:hover {
    background: var(--surface-3);
    color: var(--ink);
  }
}
