/* RC3 Recovery 1: intentionally narrow, screen-only refinements.
   Main Dock and View/Zoom are inherited unchanged from RC2 Startup 1. */
@media screen {
  /* Horizontal and vertical/tiny dock branches previously inherited different
     layout shorthands (24px versus 16px at the top). Keep one screen-space
     document origin so breakpoint changes cannot move the invoice vertically. */
  .layout {
    padding-block-start: 24px;
  }

  html,
  body,
  .layout,
  .paper {
    overflow-anchor: none;
  }

  /* Status color is confined to the small review glyph and counter. The
     established navy review bar remains unchanged in every state. */
  .invoice-review-hud[data-severity="quiet"] .review-hud-mark,
  .invoice-review-hud[data-severity="quiet"] .review-hud-count {
    color: #9ee3bb;
    background: rgba(74, 169, 113, .14);
    border-color: rgba(114, 206, 151, .34);
  }

  .invoice-review-hud[data-severity="caution"] .review-hud-mark,
  .invoice-review-hud[data-severity="caution"] .review-hud-count {
    background: rgba(203, 131, 35, .13);
    border-color: rgba(242, 179, 91, .34);
  }

  .invoice-review-hud[data-severity="action"] .review-hud-mark,
  .invoice-review-hud[data-severity="action"] .review-hud-count {
    background: rgba(199, 40, 56, .14);
    border-color: rgba(237, 105, 118, .36);
  }

  /* Keep the nautical workspace visible through the same restrained blur and
     dimming language used by My Defaults. */
  /* Use the secondary veil so the primary scenic workspace layer remains
     intact. This avoids replacing body::before (the actual lake artwork). */
  body.rate-management-active::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 69;
    background: rgba(0, 9, 22, .42);
    backdrop-filter: blur(5px) saturate(.86);
    -webkit-backdrop-filter: blur(5px) saturate(.86);
    pointer-events: none;
  }

  .rate-panel {
    inset: 50vh auto auto 50vw !important;
    z-index: 70;
    width: min(620px, calc(100vw - 44px));
    max-height: calc(100vh - 44px) !important;
    margin: 0 !important;
    padding: 18px;
    background:
      linear-gradient(150deg, rgba(9, 47, 79, .94), rgba(2, 18, 38, .97)),
      url("assets/moonlit-tow-rope-lake-chart.png") center / cover no-repeat;
    transform: translate(-50%, calc(-50% - 10px));
  }

  .rate-panel.open {
    transform: translate(-50%, -50%);
  }

  /* The launcher is inert at established desktop sizes. In a constrained
     viewport it reuses the recovered dock surface, logo, and vertical dock
     without introducing a second visual variant. */
  .dock-compact-toggle {
    display: none;
  }

  html.dock-constrained,
  body.dock-constrained {
    min-width: 0 !important;
  }

  body.dock-constrained .layout {
    width: 100%;
    min-width: 0 !important;
    padding-inline: 16px;
    overflow-x: hidden;
  }

  body.dock-constrained:not(.dock-compact-expanded) .command-dock {
    width: 72px;
    height: 82px;
    min-height: 0;
    padding: 7px;
    overflow: visible;
  }

  body.dock-constrained:not(.dock-compact-expanded) .command-dock > :not(.dock-compact-toggle) {
    display: none !important;
  }

  body.dock-constrained:not(.dock-compact-expanded) .dock-compact-toggle {
    display: flex;
    width: 56px;
    height: 66px;
    box-sizing: border-box;
    padding: 4px 6px 3px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1px;
    color: #edf6ff;
    background: rgba(238, 247, 255, .055);
    border: 1px solid rgba(174, 207, 234, .22);
    border-radius: 9px;
    cursor: pointer;
  }

  body.dock-constrained:not(.dock-compact-expanded) .dock-compact-toggle:hover,
  body.dock-constrained:not(.dock-compact-expanded) .dock-compact-toggle:focus-visible {
    color: #fff;
    background: rgba(135, 186, 226, .18);
    border-color: rgba(187, 220, 245, .58);
    outline: 2px solid #a6d8f8;
    outline-offset: 2px;
  }

  .dock-compact-toggle img {
    display: block;
    width: 42px;
    height: 42px;
    object-fit: contain;
  }

  .dock-compact-toggle svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  body.dock-constrained.dock-compact-expanded .command-dock {
    top: 8px;
    /* Reserve the approved compact Review strip immediately below the
       temporary vertical dock instead of moving it beside the dock. */
    max-height: calc(100vh - 66px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.dock-constrained.dock-compact-expanded .invoice-review-hud {
    left: 16px;
  }

  body.dock-constrained:not(.dock-compact-expanded) .invoice-review-hud {
    visibility: visible;
  }

  /* The legacy compact Review button carries a fixed 96 px width. In tiny
     mode the HUD itself follows the 72 px launcher, so make the visible
     button inherit that measured width; temporary vertical expansion then
     naturally returns both to 96 px. */
  body.dock-constrained .invoice-review-hud .review-hud-toggle {
    width: 100%;
    max-width: 100%;
  }

  /* The existing native link is normally hidden until a PDF association is
     available. Once available, retain it in the vertical dock instead of
     suppressing it at the compact breakpoint. */
  @media (max-width: 1800px) {
    /* Vertical-only organization. display:contents lets the two established
       text links take their requested positions without changing the
       horizontal dock DOM or introducing another dock variant. */
    .command-dock {
      display: flex;
      align-items: stretch;
      flex-direction: column;
    }

    .dock-brand { order: 1; }
    .dock-brand .app-version { display: none !important; }
    .dock-file-links { display: contents; }
    .dock-file-links .native-show-in-folder {
      order: 2;
      width: 100%;
      min-height: 22px;
      box-sizing: border-box;
      padding: 3px 0;
      align-items: center;
      justify-content: center;
      font-size: 8px;
      line-height: 1;
      text-align: center;
      white-space: nowrap;
    }
    .dock-rule { order: 3; width: 100%; }
    .dock-actions { order: 4; width: 100%; }
    .dock-defaults-link {
      order: 5;
      width: 100%;
      min-height: 22px;
      box-sizing: border-box;
      padding: 4px 0;
      text-align: center;
    }
    .dock-footer { order: 6; }
    .dock-offline { order: 7; }

    .dock-file-links .native-show-in-folder:not([hidden]) {
      display: flex !important;
    }
  }

  /* A quiet divider reinforces the existing file / status hierarchy without
     changing the restored dock composition. */
  .dock-footer {
    border-top-color: rgba(169, 201, 227, .38);
  }

  @media (max-width: 1100px), (max-height: 760px) {
    .rate-panel {
      width: min(590px, calc(100vw - 32px));
      max-height: calc(100vh - 32px) !important;
      padding: 14px;
    }
  }

  @media (max-height: 639px) {
    body.dock-constrained.dock-compact-expanded .review-hud-cards {
      top: calc(100% + 6px);
      bottom: auto;
      max-height: calc(100vh - 84px);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .rate-panel { transition: none !important; }
  }

  /* Geometry-selected dock modes. These selectors intentionally come after
     the legacy viewport media queries: JavaScript chooses a mode from the
     rendered paper edge, candidate dock bounds, zoom and a hysteresis margin.
     The declarations only reapply the already-approved horizontal/vertical
     artwork; they do not introduce another visual treatment. */
  body.dock-mode-horizontal .command-dock {
    display: block;
    inset: 24px auto auto 22px;
    width: 310px;
    max-height: none;
    padding: 12px 12px 10px;
    overflow: visible;
  }

  body.dock-mode-horizontal .dock-compact-toggle { display: none !important; }
  body.dock-mode-horizontal .dock-brand {
    height: 68px;
    padding: 0 2px;
    align-items: center;
    justify-content: flex-start;
    flex-direction: row;
    gap: 8px;
  }
  body.dock-mode-horizontal .dock-brand-full {
    display: block !important;
    flex: 0 0 170px !important;
    width: 170px !important;
    height: auto !important;
  }
  body.dock-mode-horizontal .dock-brand-compact { display: none !important; }
  body.dock-mode-horizontal .dock-brand .app-version { display: inline-block !important; margin-left: auto; }
  body.dock-mode-horizontal .dock-current-filename { display: block; }
  body.dock-mode-horizontal .dock-file-links {
    display: grid !important;
    min-height: 24px;
    margin: 1px 3px 3px;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  body.dock-mode-horizontal .dock-file-links .native-show-in-folder:not([hidden]) {
    display: block !important;
    order: initial;
    width: auto;
    min-height: 24px;
    padding: 4px 3px 3px;
    justify-self: start;
    font-size: 10px;
    line-height: 1.25;
  }
  body.dock-mode-horizontal .dock-defaults-link {
    order: initial;
    width: auto;
    min-height: 24px;
    padding: 4px 3px 3px;
    justify-self: end;
    color: #c3d7e7;
    font-size: 10px;
    text-align: initial;
    background: transparent;
    border: 0;
    border-bottom: 1px solid transparent;
    border-radius: 0;
  }
  body.dock-mode-horizontal .dock-rule { width: auto; margin: 2px 0; }
  body.dock-mode-horizontal .dock-rule-secondary { display: none; }
  body.dock-mode-horizontal .dock-actions {
    width: auto;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }
  body.dock-mode-horizontal .dock-command {
    height: 48px;
    padding: 5px 2px;
    gap: 2px;
    background: rgba(238, 247, 255, .055);
    border-color: rgba(174, 207, 234, .18);
    border-radius: 7px;
  }
  body.dock-mode-horizontal .dock-command svg { width: 19px; height: 19px; }
  body.dock-mode-horizontal .dock-command span { font-size: 10.5px; line-height: 1; white-space: nowrap; }
  body.dock-mode-horizontal .dock-footer {
    width: auto;
    min-height: 28px;
    margin-top: 7px;
    padding-top: 0;
    align-items: center;
    justify-content: space-between;
    flex-direction: row;
    gap: 6px;
    border-top: 0;
  }
  body.dock-mode-horizontal .dock-save-state {
    width: auto;
    min-height: 0;
    max-width: 112px;
    padding: 0;
    justify-content: flex-start;
    color: #bfd1e2;
    font-size: 10.5px;
    text-align: left;
    white-space: normal;
    background: transparent;
    border: 0;
  }
  body.dock-mode-horizontal .dock-rate-control {
    display: inline-flex;
    width: auto;
    min-height: 0;
    padding: 4px 6px;
    align-items: center;
    justify-content: flex-start;
    flex-direction: row;
    gap: 5px;
    color: #dceaf7;
    white-space: nowrap;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
  }
  body.dock-mode-horizontal .dock-rate-control svg { width: 16px; height: 16px; }
  body.dock-mode-horizontal .dock-rate-control span { max-width: none; font-size: 10.5px; line-height: 1; white-space: nowrap; }

  body.dock-mode-vertical .command-dock,
  body.dock-mode-tiny.dock-compact-expanded .command-dock {
    display: flex;
    inset: 16px auto auto 16px;
    width: 96px;
    box-sizing: border-box;
    margin: 0;
    padding: 10px 8px;
    align-items: stretch;
    flex-direction: column;
    overflow: visible;
  }
  body.dock-mode-vertical .dock-compact-toggle,
  body.dock-mode-tiny.dock-compact-expanded .dock-compact-toggle { display: none !important; }
  body.dock-mode-vertical .dock-brand,
  body.dock-mode-tiny.dock-compact-expanded .dock-brand {
    order: 1;
    height: 66px;
    padding: 2px 0;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
  }
  body.dock-mode-vertical .dock-brand-full,
  body.dock-mode-tiny.dock-compact-expanded .dock-brand-full { display: none !important; }
  body.dock-mode-vertical .dock-brand-compact,
  body.dock-mode-tiny.dock-compact-expanded .dock-brand-compact {
    display: block !important;
    flex: 0 0 44px !important;
    width: 44px !important;
    height: 44px !important;
    object-fit: contain;
  }
  body.dock-mode-vertical .dock-brand .app-version,
  body.dock-mode-tiny.dock-compact-expanded .dock-brand .app-version { display: none !important; }
  body.dock-mode-vertical .dock-current-filename,
  body.dock-mode-tiny.dock-compact-expanded .dock-current-filename { display: none; }
  body.dock-mode-vertical .dock-file-links,
  body.dock-mode-tiny.dock-compact-expanded .dock-file-links { display: contents !important; }
  body.dock-mode-vertical .dock-file-links .native-show-in-folder,
  body.dock-mode-tiny.dock-compact-expanded .dock-file-links .native-show-in-folder {
    order: 2;
    width: 100%;
    min-height: 22px;
    box-sizing: border-box;
    padding: 3px 0;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
  }
  body.dock-mode-vertical .dock-file-links .native-show-in-folder:not([hidden]),
  body.dock-mode-tiny.dock-compact-expanded .dock-file-links .native-show-in-folder:not([hidden]) { display: flex !important; }
  body.dock-mode-vertical .dock-rule:not(.dock-rule-secondary),
  body.dock-mode-tiny.dock-compact-expanded .dock-rule:not(.dock-rule-secondary) {
    order: 3;
    width: 100%;
    margin: 6px 0 8px;
  }
  body.dock-mode-vertical .dock-actions,
  body.dock-mode-tiny.dock-compact-expanded .dock-actions {
    order: 4;
    width: 100%;
    grid-template-columns: 1fr;
    gap: 6px;
  }
  body.dock-mode-vertical .dock-command,
  body.dock-mode-tiny.dock-compact-expanded .dock-command {
    height: 52px;
    padding: 6px 4px;
    gap: 4px;
    background: rgba(238, 247, 255, .065);
    border-color: rgba(174, 207, 234, .24);
    border-radius: 8px;
  }
  body.dock-mode-vertical .dock-command svg,
  body.dock-mode-tiny.dock-compact-expanded .dock-command svg { width: 20px; height: 20px; }
  body.dock-mode-vertical .dock-command span,
  body.dock-mode-tiny.dock-compact-expanded .dock-command span {
    font-size: 10px;
    line-height: 1.05;
    text-align: center;
  }
  body.dock-mode-vertical .dock-rule-secondary,
  body.dock-mode-tiny.dock-compact-expanded .dock-rule-secondary {
    display: block;
    order: 5;
    width: 82%;
    height: 1px;
    margin: 9px auto 7px;
    opacity: .62;
    background: linear-gradient(90deg, rgba(169, 201, 227, .08), rgba(169, 201, 227, .48), rgba(237, 28, 46, .42));
  }
  body.dock-mode-vertical .dock-defaults-link,
  body.dock-mode-tiny.dock-compact-expanded .dock-defaults-link {
    order: 6;
    width: 100%;
    min-height: 22px;
    box-sizing: border-box;
    padding: 4px 0;
    text-align: center;
  }
  body.dock-mode-vertical .dock-footer,
  body.dock-mode-tiny.dock-compact-expanded .dock-footer {
    order: 7;
    width: 100%;
    box-sizing: border-box;
    margin-top: 9px;
    padding-top: 9px;
    align-items: center;
    flex-direction: column;
    gap: 7px;
    border-top: 1px solid rgba(169, 201, 227, .38);
  }
  body.dock-mode-vertical .dock-save-state,
  body.dock-mode-tiny.dock-compact-expanded .dock-save-state {
    width: 100%;
    min-height: 34px;
    box-sizing: border-box;
    padding: 5px 4px;
    justify-content: center;
    color: #d6e4f1;
    font-size: 9.5px;
    line-height: 1;
    text-align: center;
    background: rgba(0, 12, 28, .24);
    border: 1px solid rgba(174, 207, 234, .14);
    border-radius: 6px;
  }
  body.dock-mode-vertical .dock-rate-control,
  body.dock-mode-tiny.dock-compact-expanded .dock-rate-control {
    width: 100%;
    min-height: 58px;
    box-sizing: border-box;
    padding: 6px 4px;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    color: #edf6ff;
    white-space: normal;
    text-align: center;
    background: rgba(238, 247, 255, .065);
    border: 1px solid rgba(174, 207, 234, .24);
    border-radius: 8px;
  }
  body.dock-mode-vertical .dock-rate-control svg,
  body.dock-mode-tiny.dock-compact-expanded .dock-rate-control svg { width: 20px; height: 20px; }
  body.dock-mode-vertical .dock-rate-control span,
  body.dock-mode-tiny.dock-compact-expanded .dock-rate-control span {
    max-width: 70px;
    font-size: 9.8px;
    line-height: 1.12;
    white-space: normal;
  }
  body.dock-mode-vertical .dock-offline,
  body.dock-mode-tiny.dock-compact-expanded .dock-offline { order: 8; }

  body.dock-mode-tiny:not(.dock-compact-expanded) .command-dock {
    inset: 16px auto auto 16px;
  }
  body.dock-mode-tiny .layout {
    width: 100%;
    min-width: max(680px, var(--workspace-paper-width, 680px)) !important;
    overflow-x: visible;
  }
  body.dock-mode-tiny.dock-compact-expanded .command-dock {
    top: 8px;
    max-height: calc(100vh - 66px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.dock-mode-horizontal .invoice-review-hud,
  body.dock-mode-vertical .invoice-review-hud,
  body.dock-mode-tiny .invoice-review-hud {
    inset: var(--dock-review-top, 280px) auto auto var(--dock-review-left, 16px);
    width: var(--dock-review-width, 96px);
  }
  body.dock-mode-horizontal .review-hud-toggle {
    width: 100%;
    min-height: 40px;
    padding: 7px 10px;
    justify-content: flex-start;
  }
  body.dock-mode-horizontal .review-hud-label {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
  body.dock-mode-horizontal .review-hud-cards { width: 310px; }
  body.dock-mode-vertical .review-hud-toggle,
  body.dock-mode-tiny .review-hud-toggle {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    min-height: 42px;
    padding: 7px;
    justify-content: center;
  }
  body.dock-mode-vertical .review-hud-label,
  body.dock-mode-tiny .review-hud-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  body.dock-mode-vertical .review-hud-cards,
  body.dock-mode-tiny .review-hud-cards {
    position: absolute;
    top: 100%;
    left: 0;
    width: 286px;
    max-height: calc(100vh - var(--dock-review-top, 585px) - 52px);
    min-height: 0;
  }
}

@media print {
  body.rate-management-active::after { display: none !important; }
  .dock-compact-toggle { display: none !important; }
}
