:root {
  --at-modal-gutter: 12px;
  --at-modal-touch-target: 44px;
  --at-modal-max-height: calc(100dvh - (var(--at-modal-gutter) * 2));
}

.at-modal .modal-dialog,
.at-modal-dialog {
  width: calc(100vw - (var(--at-modal-gutter) * 2));
  max-width: calc(100vw - (var(--at-modal-gutter) * 2));
  margin: var(--at-modal-gutter) auto;
  min-width: 0;
}

.at-modal .modal-content,
.at-modal-content {
  width: 100%;
  min-width: 0;
  max-height: var(--at-modal-max-height);
  overflow: hidden;
}

.at-modal .modal-body,
.at-modal-body {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.at-modal-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  max-height: var(--at-modal-max-height);
}

.at-modal-form .modal-content {
  flex: 1 1 auto;
  min-height: 0;
}

.at-modal-title {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.at-modal-footer {
  gap: 0.5rem;
}

.at-modal-footer > * {
  margin: 0;
}

.at-modal-table-scroll {
  margin-bottom: 0;
  -webkit-overflow-scrolling: touch;
}

.at-modal-table th,
.at-modal-table td {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  vertical-align: middle;
}

.at-modal-table input.form-control,
.at-modal-table textarea.form-control {
  min-width: 0;
  font-size: 16px;
}

.at-modal-breakable {
  overflow-wrap: anywhere;
  word-break: break-word;
}

#modal-company-selector .company-selector-item {
  display: flex;
  align-items: flex-start;
  min-width: 0;
}

#modal-company-selector .company-selector-label {
  flex: 1 1 auto;
  min-width: 0;
}

#modal-company-selector .company-selector-checkbox {
  flex-shrink: 0;
}

@media (max-width: 575.98px) {
  .at-modal .modal-header,
  .at-modal .modal-body,
  .at-modal .modal-footer {
    padding: 1rem;
  }

  .at-modal-footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .at-modal-footer .btn,
  .at-modal-footer button,
  .at-modal-footer form {
    width: 100%;
  }

  .at-modal-footer .btn,
  .at-modal-footer button {
    min-height: var(--at-modal-touch-target);
  }

  .at-modal-table-stack thead {
    display: none;
  }

  .at-modal-table-stack tbody tr {
    display: block;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--tblr-border-color, #e6e7e9);
    border-radius: var(--tblr-border-radius, 4px);
    background: var(--tblr-bg-surface-secondary, #f8fafc);
  }

  .at-modal-table-stack tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border: 0;
  }

  .at-modal-table-stack tbody td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    font-weight: 600;
    color: var(--tblr-secondary, #626976);
  }

  .at-modal-table-stack tbody td:last-child {
    padding-bottom: 0;
  }
}

@media (min-width: 576px) {
  .at-modal .modal-dialog,
  .at-modal-dialog {
    width: auto;
    max-width: min(540px, calc(100vw - (var(--at-modal-gutter) * 2)));
  }

  .at-modal .modal-dialog.modal-lg,
  .at-modal-dialog.modal-lg {
    max-width: min(720px, calc(100vw - (var(--at-modal-gutter) * 2)));
  }
}

/* Admin confirmation overlays */
.at-admin-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: var(--at-modal-gutter);
  background: rgba(0, 0, 0, 0.5);
}

.at-admin-modal-overlay:not([hidden]) {
  display: flex;
}

.at-admin-modal-box {
  box-sizing: border-box;
  width: min(420px, calc(100vw - (var(--at-modal-gutter) * 2)));
  max-width: calc(100vw - (var(--at-modal-gutter) * 2));
  max-height: var(--at-modal-max-height);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.at-admin-modal-box h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.at-admin-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.at-admin-modal-box textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 100px;
  margin-top: 0.5rem;
  font-size: 16px;
}

.at-admin-modal-error {
  margin-top: 0.25rem;
  color: #ba2121;
  font-size: 12px;
}

.at-admin-modal-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.at-admin-modal-actions button {
  width: 100%;
  min-height: var(--at-modal-touch-target);
}

@media (min-width: 576px) {
  .at-admin-modal-actions {
    flex-direction: row;
    justify-content: flex-end;
  }

  .at-admin-modal-actions button {
    width: auto;
    margin-left: 0.5rem;
  }
}
