html, body { max-width: 100%; }
/* Keep keyboard focus visible above the historical module focus resets. */
body :focus-visible { outline: 3px solid var(--kms-focus) !important; outline-offset: 2px; }

/* Existing validation markers share one visible error state, including focus.
   The app/dialog owner outranks historical generic input !important rules. */
body :is(#app, #login, dialog) :is(input, select, textarea):is([aria-invalid="true"], .field-invalid, .is-invalid),
body :is(#app, #login, dialog) .field-error :is(input, select, textarea) {
  border-color: var(--kms-input-error) !important;
  background-color: var(--kms-color-problem-soft) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kms-input-error) 12%, transparent) !important;
}

:is(.sheet-title, .kms-page-header, .section-heading, .device-section-heading) {
  min-width: 0;
  flex-wrap: wrap;
}
:is(.sheet-title, .kms-page-header, .section-heading, .device-section-heading) > div {
  min-width: 0;
  max-width: 100%;
}
:is(.sheet-title, .kms-page-header, .section-heading, .device-section-heading) :is(h2, h3) {
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  /* Readable mobile/tablet entry text also avoids automatic focus zoom on iOS.
     Keep checkbox, radio, file and graphical controls in their own layouts. */
  body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]):not([type="number"]):not([inputmode="decimal"]):not(.cell):not(.euro-input input), select, textarea) {
    font-size: max(16px, 1rem) !important;
  }

  /* The user editor is its own fixed scroll container on tablet and mobile.
     End it above the shared navigation so its final actions remain clickable. */
  #userEditor.editor-drawer:not(.hidden) {
    bottom: calc(var(--kms-mobile-nav-clearance) + env(safe-area-inset-bottom));
    scroll-padding-bottom: var(--kms-space-4);
  }

  body.g011-package2-cash-active .p2a-cash-area-mobile,
  body.g011-package2-cash-active .p2a-cash-area-mobile > summary,
  body.g011-package2-cash-active .p2a-cash-area-mobile > nav {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
}
.save-status-indicator { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 5px 10px; border: 1px solid var(--kms-color-border); border-radius: var(--kms-radius-lg); background: var(--kms-color-surface-raised); color: var(--kms-color-text-secondary); font-size: .78rem; font-weight: 750; }
.save-status-indicator[data-status="saving"], .save-status-indicator[data-status="queued"] { background: var(--warning); color: var(--ink); }
.save-status-indicator[data-status="saved"] { border-color: color-mix(in srgb, var(--kms-color-success) 34%, var(--kms-color-border)); background: var(--kms-color-success-soft); color: var(--kms-color-text); }
.save-status-indicator[data-status="error"], .save-status-indicator[data-status="conflict"], .save-status-indicator[data-status="offline"] { border-color: color-mix(in srgb, var(--kms-color-problem) 38%, var(--kms-color-border)); background: var(--kms-color-problem-soft); color: var(--kms-color-text); }
.save-status-indicator[data-status="saving"]::before,
.save-status-indicator[data-status="syncing"]::before,
.save-status-indicator[data-status="reconnecting"]::before {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: kms-save-status-spin .7s linear infinite;
}

@media (max-width: 720px) {
  body.location-setup-active #locations {
    position: fixed;
    inset: 0;
    z-index: 240;
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    padding: 12px 12px calc(92px + env(safe-area-inset-bottom));
  }
  body.location-setup-active #locations > .sheet-title,
  body.location-setup-active #locations > .module-overview,
  body.location-setup-active #locations .location-page-head,
  body.location-setup-active #locations .location-central-toolbar { display: none; }
  .location-page-actions,
  .location-setup-summary,
  .location-setup-workspace > header,
  .location-cash-links {
    align-items: stretch;
    flex-direction: column;
  }
  .location-page-actions > *,
  .location-setup-summary > button,
  .location-setup-workspace > header button,
  .location-assistant-actions button,
  .section-heading-actions button { width: 100%; }
  .location-steps-six {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
  }
  .location-steps-six button {
    flex: 0 0 108px;
    min-height: 64px;
    scroll-snap-align: start;
  }
  .location-assignment-grid,
  .location-setup-review article { grid-template-columns: minmax(0, 1fr); }
  .location-assistant-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
@keyframes kms-save-status-spin { to { transform: rotate(360deg); } }
.operation-progress {
  display: grid;
  gap: 3px;
  min-width: 180px;
  padding: 6px 10px;
  border: 1px solid var(--grid);
  border-radius: var(--kms-radius-sm);
  background: var(--kms-color-surface);
  color: var(--ink);
  font-size: .76rem;
  font-weight: 700;
  pointer-events: none;
}
.operation-progress progress { width: 100%; height: 5px; accent-color: var(--kms-primary); }
.operation-progress.is-success progress { accent-color: var(--kms-color-success); }
.operation-progress.is-error { border-color: var(--bad); color: var(--bad); }
@media (max-width: 430px) {
  .operation-progress {
    position: relative;
    order: 10;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    place-content: center;
    padding: 5px 6px;
  }
  .operation-progress::before { content: "↻"; text-align: center; line-height: 1; }
  .operation-progress.is-success::before { content: "✓"; }
  .operation-progress.is-error::before { content: "!"; }
  .operation-progress > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  button, .btn-link, input, select { min-height: var(--kms-touch-target); }
  dialog { max-width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  dialog.kms-detail-surface {
    inset: 0;
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }
  form:not(.inline-form) { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 431px) and (max-width: 1024px) {
  dialog { max-width: calc(100vw - 40px); }
}

/* Eine Mobile-Logik für alle bestehenden Seiten. */
@media (max-width: 640px) {
  .view {
    padding: var(--kms-space-4);
    border-radius: var(--kms-radius-md);
  }

  .view.active {
    gap: var(--kms-space-4);
  }

  :where(.sheet-title, .kms-page-header, .section-heading, .device-section-heading) {
    align-items: stretch;
    flex-direction: column;
  }

  :where(.title-actions, .confirm-dialog-actions, .settings-inline-actions, .cash-primary-actions, .task-ai-actions) {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  :where(.title-actions, .confirm-dialog-actions, .settings-inline-actions, .cash-primary-actions, .task-ai-actions) > :where(button, .btn-link) {
    width: 100%;
    min-height: var(--kms-control-height-mobile);
  }

  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select,
  textarea,
  button,
  .btn-link {
    min-height: var(--kms-control-height-mobile);
  }

  :where(
    .settings-grid,
    .settings-form-grid,
    .settings-account-grid,
    .settings-management-grid,
    .cash-area-summary,
    .cash-area-actions,
    .safebag-cards,
    .user-card-grid,
    .role-card-grid,
    .location-card-grid,
    .kms-category-grid,
    .kms-metric-grid
  ) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  :where(.tabs, .settings-area-tabs, .user-detail-tabs, .shopflow-tabs, .location-route-nav, .vault-tabs, .management-module-tabs) {
    width: 100%;
    margin-inline: 0;
  }

  #devices {
    min-width: 0;
    max-width: 100%;
  }

  #devices #deviceInventoryCategories button {
    flex: 0 0 max-content;
    min-width: max-content;
  }

  #devices #deviceInventoryCategories .device-category-label {
    white-space: nowrap;
  }

  .vault-category-row { grid-template-columns: 1fr; }
  .category-primary-actions, .category-row-actions { display: grid; grid-template-columns: 1fr; width: 100%; }
  .category-row-actions { grid-column: 1; }
  .category-row-actions small { margin-left: 0; }
  .category-primary-actions button, .category-row-actions button { width: 100%; min-height: var(--kms-control-height-mobile); }
  .category-history-list article > div { display: grid; }

  :where(.tabs, .settings-area-tabs, .user-detail-tabs, .shopflow-tabs, .location-route-nav, .vault-tabs, .management-module-tabs) button {
    min-height: var(--kms-control-height-mobile);
  }

  /* The central create action remains a full touch target even when role
     navigation rewrites its data attributes after hydration. */
  .mobile-bottom-nav .mobile-nav-action.mobile-nav-create {
    min-height: 64px !important;
  }

  /* "Neu" is dismissible and therefore an interactive control.  Keep its
     compact badge appearance on desktop, but expose a full touch target in
     the currently active mobile surface. */
  #app .view.active .feature-new-marker {
    min-width: var(--kms-control-height-mobile) !important;
    min-height: var(--kms-control-height-mobile) !important;
  }

  .table-box {
    border: 0;
    overflow: visible;
    background: transparent;
    box-shadow: none;
  }
}

@media (max-width: 900px) {
  /* Tablet is part of the touch navigation mode as well. */
  #app .view.active .feature-new-marker {
    min-width: var(--kms-control-height-mobile) !important;
    min-height: var(--kms-control-height-mobile) !important;
  }
  #locations.active button {
    min-height: var(--kms-control-height-mobile);
  }
  #permissions.active button {
    min-height: var(--kms-control-height-mobile);
  }
}
@media (max-width: 600px){.completion-confirmation-actions{display:grid;grid-template-columns:1fr}.completion-confirmation-actions button{min-height:48px;width:100%}}
