/* Shared button ergonomics, loaded after the legacy desktop/mobile layouts. */
:root {
  --button-target: 44px;
  --button-radius: 12px;
  --button-focus: #bae6fd;
}

button {
  min-height: var(--button-target);
  min-width: var(--button-target);
  font-family: inherit;
  line-height: 1.5;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, border-color .15s, box-shadow .15s, opacity .15s;
}
button > i { flex-shrink: 0; pointer-events: none; }
button > span { min-width: 0; }
button:focus-visible, [role="button"]:focus-visible, [role="radio"]:focus-visible {
  outline: 3px solid var(--button-focus);
  outline-offset: 3px;
}
button:disabled, button[aria-disabled="true"] {
  opacity: .55;
  cursor: not-allowed;
  transform: none !important;
  filter: none !important;
  box-shadow: none !important;
}
button:disabled::before { display: none; }
button:disabled i { transform: none !important; }

.view-action-btn, .tool-btn, .calc-close, .help-drawer-close,
.click-inspect-close, .numpad-toggle-btn {
  width: var(--button-target);
  height: var(--button-target);
  flex: 0 0 var(--button-target);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.numpad-toggle-btn {
  padding: 0;
  border: 1px solid #475569;
  background: #1e293b;
  color: #e2e8f0;
  font-size: .9rem;
}
.calc-close, .help-drawer-close, .click-inspect-close {
  border: 1px solid #475569;
  background: #1e293b;
  color: #f1f5f9;
}
.viewport-actions { gap: 8px; flex-wrap: wrap; }
.action-btn { min-width: 44px; min-height: 44px; }
.dropdown-menu-content, .custom-dropdown-panel { transition: opacity .15s, transform .15s; }
.numeric-input-wrapper { min-width: 0; }
.numeric-input-field { min-width: 0; flex: 1 1 0; }
.input-unit-label { flex-shrink: 0; }
.view-tab, .custom-dropdown-trigger { height: auto; min-height: 44px; padding: 8px 12px; }
.custom-dropdown-trigger .trigger-label { white-space: normal; }
.dropdown-menu-item, .dropdown-option-item { min-height: 48px; transition: background-color .15s, color .15s; }
.view-tab, .view-action-btn { color: #cbd5e1; }
button[aria-pressed="true"], .dropdown-option-item[aria-checked="true"] {
  border-color: #7dd3fc;
  box-shadow: inset 0 0 0 1px #7dd3fc55;
}
.grid-drawing-toolbar .tool-btn { flex-basis: 44px; }
/* Keep the planning label readable instead of squeezing it into an icon cell. */
.grid-drawing-toolbar #tool-guide-btn { position:absolute; left:calc(100% + 12px); top:0; width:148px; height:48px; min-height:48px; flex:0 0 auto; flex-direction:row; gap:8px; padding:10px 14px; border-radius:12px; background:#172033; border-color:#b58127; color:#fcd34d; }
#tool-guide-btn span { font-size:.85rem; font-weight:700; line-height:1.5; white-space:nowrap; text-align:center; }
.grid-drawing-toolbar #tool-guide-btn.active { background:#fbbf24; border-color:#fcd34d; color:#172033; box-shadow:none; outline-color:#fcd34d; }
.grid-drawing-toolbar #tool-guide-divider { display:none; }
@media (max-width:768px) {
 .grid-drawing-toolbar #tool-guide-btn { position:static; order:10; width:100%; flex:1 0 100%; margin-top:4px; }
}
.tool-btn[aria-pressed="true"] { outline: 2px solid #7dd3fc; outline-offset: 1px; }
.click-inspect-pill { width: max-content; max-width: calc(100% - 24px); white-space: normal; }
.click-inspect-pill span { min-width: 0; }
.inspect-name-short { display: none; }
.click-inspect-pill.selected #click-inspect-text { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; }
.click-inspect-pill.selected .inspect-title { flex: none; }
.click-inspect-pill.selected .inspect-description { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Keep navigation labels readable, including long final-stage actions. */
#task-actions-host .task-actions-bar {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
}
#task-actions-host .task-actions-bar > button {
  position: static !important;
  width: 100%;
  height: auto;
  min-height: 48px;
  min-width: 0;
  margin: 0;
  padding: 10px 12px;
  justify-content: center;
  gap: 8px;
  border-radius: var(--button-radius);
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.6;
  white-space: normal;
  text-align: center;
  box-shadow: none;
}
#task-actions-host .task-actions-bar > button > span { display: inline; }
#task-actions-host .btn-check { background: #0369a1; border: 1px solid #38bdf8; color: #fff; }
#task-actions-host .btn-next { background: #047857; border: 1px solid #34d399; color: #fff; }
#task-actions-host .btn-prev { background: #1c2a40; border: 1px solid #4a5d78; color: #e2e8f0; }
#task-actions-host .help-drawer-trigger { background: #342710; border: 1px solid #a87925; color: #fde68a; }
#task-actions-host .btn-ghost-danger { background: #301d29; border: 1px solid #955166; color: #fecdd3; }
#task-actions-host .task-actions-bar > button:only-child { grid-column: 1 / -1; }
#task-actions-host .task-actions-bar:has(.btn-next.show) > .btn-next { grid-column: 1 / -1; }
.btn-check::before, .btn-next::before, .btn-start-track::before { display: none; }
.help-next-level-btn, .btn-start-track { height: auto; min-height: 48px; padding: 10px 16px; white-space: normal; }
.numpad-active-target-badge { gap: 8px; }
.reference-card-trigger { width: 100%; text-align: start; gap: 12px; }
.numpad-btn, .calc-key { min-height: 48px; }
.numpad-btn.action.check-key { background: #065f46; color: #ecfdf5; }
.floating-calculator { max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; animation: none; }
.modal-footer { flex-wrap: wrap; gap: 10px; }
.modal-footer button { flex: 1 1 180px; height: auto; padding: 10px 14px; white-space: normal; justify-content: center; }
.modal-footer .action-btn span { display: inline; }

/* No drifting icons or sticky hover movement after tapping a control. */
button:hover, button:hover i { transform: none !important; }
@media (hover: hover) and (pointer: fine) {
  button:not(:disabled):hover { filter: brightness(1.1); }
  #task-actions-host button:not(:disabled):hover { border-color: #e0f2fe; }
}
button:not(:disabled):active { transform: translateY(1px) !important; filter: brightness(.92); }
@media (hover: none) {
  button:hover { filter: none; }
  button:not(:disabled):active { filter: brightness(.92); }
}
@media (max-width: 768px) {
  .viewport-toolbar { gap: 8px; }
  .viewport-tabs-compact { flex: 1 1 100%; gap: 8px; }
  .viewport-actions { width: 100%; justify-content: flex-end; }
  .lab-main-container .visual-viewport-card { height: 420px !important; min-height: 420px !important; }
  body .lab-main-container.mobile-mode-viewport {
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body:not([data-active-screen="4"]) .lab-main-container.mobile-mode-viewport .visual-viewport-card:not(.expanded) {
    height: max(360px, calc(100dvh - var(--mobile-workspace-top, 160px) - 14px - env(safe-area-inset-bottom, 0px))) !important;
    min-height: 360px !important;
  }
  .mobile-mode-viewport .mobile-viewport-switch-pill {
    align-self: stretch;
    width: auto;
    max-width: none;
    margin: 0 10px 10px;
    min-height: 48px;
    justify-content: center;
  }
  .click-inspect-pill {
    position: static;
    inset: auto;
    transform: none;
    flex: 0 0 auto;
    align-self: stretch;
    width: auto;
    max-width: none;
    min-height: 72px;
    margin: 0 10px 10px;
    padding: 10px 12px;
    gap: 10px;
    border-radius: 14px;
    background: #101e32;
    border-color: #315673;
    box-shadow: none;
    text-align: start;
    transition: background-color .15s, border-color .15s;
  }
  .click-inspect-pill > i {
    display: grid;
    place-items: center;
    flex: 0 0 32px;
    width: 32px;
    height: 36px;
    font-size: 1.2rem;
  }
  #click-inspect-text { flex: 1; min-width: 0; line-height: 1.65; }
  .inspect-title { display: block; color: #f1f5f9; font-size: .875rem; font-weight: 700; }
  .inspect-description { display: block; color: #cbd5e1; font-size: .8125rem; }
  .click-inspect-pill.selected { min-height: 64px; padding: 8px 10px; gap: 8px; background: #102c40; box-shadow: none; }
  .click-inspect-pill.selected .inspect-title, .inspect-name-full { display: none; }
  .inspect-name-short { display: inline; }
  .click-inspect-close { margin: 0; font-size: 1rem; }
  #task-actions-host .task-actions-bar > button { font-size: .84rem; padding: 10px 8px; }
  .mobile-segment-btn { height: auto; min-height: 48px; white-space: normal; line-height: 1.5; }
  .track-modal-actions { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .floating-calculator { max-height: calc(100dvh - 12px); }
  button, [role="button"], [role="radio"] { scroll-margin-block: 16px calc(var(--task-actions-height, 120px) + 24px); }
}
@media (min-width: 769px) {
  #task-actions-host .task-actions-bar > #btn-start-task {
    grid-column: 1 / -1;
    justify-self: center;
    width: min(100%, 320px);
  }
  .floating-calculator { bottom: 16px; max-height: calc(100dvh - 32px); }
}
@media (prefers-reduced-motion: reduce) {
  button, button i, [role="button"] { transition: none !important; animation: none !important; }
  button:not(:disabled):active { transform: none !important; }
}
