.modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  transition: opacity 0.3s ease;
}

.modal-content {
  background-color: var(--body-bg);
  color: var(--body-fg);
  margin: 10% auto;
  width: 90%;
  max-width: 500px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  animation: modal-appear 0.3s ease-out;
}

@keyframes modal-appear {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  background-color: var(--primary);
  color: var(--header-link-color);
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 500;
}

.modal-close {
  color: var(--header-link-color);
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  opacity: 0.7;
  transition:
    opacity 0.15s,
    transform 0.15s;
}

.modal-close:hover,
.modal-close:focus {
  opacity: 1;
  transform: scale(1.1);
}

.modal-body {
  padding: 20px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.modal-footer {
  background-color: var(--darkened-bg);
  padding: 15px 20px;
  text-align: right;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

.button,
.modal-action-button,
.modal-footer .button {
  background-color: var(--button-bg);
  color: var(--button-fg);
  border: 1px solid var(--button-border);
  border-radius: 4px;
  padding: 10px 15px;
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.button:hover,
.modal-action-button:hover,
.modal-footer .button:hover {
  background-color: var(--button-hover-bg);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.button:active,
.modal-action-button:active,
.modal-footer .button:active {
  transform: translateY(0);
  box-shadow: none;
}

.button.default,
.modal-action-button.default,
.modal-footer .button.default {
  background-color: var(--default-button-bg);
  border-color: var(--default-button-border);
}

.button.default:hover,
.modal-action-button.default:hover,
.modal-footer .button.default:hover {
  background-color: var(--default-button-hover-bg);
}

.modal-footer .button + .button {
  margin-left: 10px;
}

.modal-action-button.historylink {
  background-image: none;
  padding-left: 15px;
}

#modal-action form p {
  margin-bottom: 20px;
}

#modal-action form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--body-quiet-color);
}

#modal-action form input[type="text"],
#modal-action form input[type="email"],
#modal-action form select,
#modal-action form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 0.9rem;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

#modal-action form input[type="text"]:focus,
#modal-action form input[type="email"]:focus,
#modal-action form select:focus,
#modal-action form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
}

.errorlist {
  color: var(--error-fg);
  background: var(--error-bg);
  border: 1px solid var(--error-fg);
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 4px;
  list-style-type: none;
}

.errorlist li {
  font-size: 0.85rem;
  margin-bottom: 5px;
}

.errorlist li:last-child {
  margin-bottom: 0;
}

.alert {
  padding: 15px;
  margin-bottom: 20px;
  border: 1px solid transparent;
  border-radius: 4px;
}

.alert-danger {
  color: var(--error-fg);
  background-color: var(--error-bg);
  border-color: var(--error-fg);
}

.modal-close:focus-visible,
.button:focus-visible,
.modal-action-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (prefers-color-scheme: dark) {
  .modal-content {
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.1);
  }

  #modal-action form input[type="text"],
  #modal-action form input[type="email"],
  #modal-action form select,
  #modal-action form textarea {
    background-color: var(--body-bg);
    color: var(--body-fg);
  }
}

@media (max-width: 767px) {
  .modal-content {
    width: 95%;
    margin: 5% auto;
  }

  .modal-header h2 {
    font-size: 1.1rem;
  }

  .modal-body {
    padding: 15px;
  }

  .modal-footer {
    padding: 12px 15px;
  }

  .button,
  .modal-action-button,
  .modal-footer .button {
    padding: 8px 12px;
    font-size: 0.8rem;
  }
}
